云服务器的入门系列
LAMP环境搭建
个人博客Wordpress搭建
GItlab搭建
Ftp搭建
公网IP
youIP
密码
pwd
域名
javacoldly.xyz
SSL证书申请
- todo..
API 密钥
SecretId: Xxx SecretKey:Xxx
阿里云
账号密码
- 公网IP
120.79.150.12
- 公网IP
密码
pwd
个人建站环境搭建
- 防火墙
- 查看状态
- 关闭防火墙
-
stemctl stop firewalld
- 永久关闭防火墙
systemctl disable firewalld
- 关闭SELInux
- 开启或关闭SELinux
- 禁用 selinux:setenforce 0
-
[root@iZwz9c743j35koyx2hety8Z ~]# getenforce
[root@iZwz9c743j35koyx2hety8Z ~]# systemctl status firewalld
部署LNMP环境
- nginx安装
-yum -y install nginx
- mysql安装
- 更新yum源
rpm - http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
- 安装mysql命令
yum -y install mysql-community-server
- 查看版本号
mysql -V
- nginx安装
启动mysql
systemctl start mysqld
- 其他命令
-
systemctl enable mysqld
systemctl daemon-reload
-
php安装
- 更新yum源
yum install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- 运行以下命令添加Webtatic源。
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
- 命令安装
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
- 查看php版本
php -v
- nginx配置
- nginx备份
-
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
-
- 修改nginx文件支持php
- 配置参考
- nginx备份
- 启动nginx服务
- 设置nginx开机自启动
Mysql配置
- 获取初始密码
grep 'temporary password' /var/log/mysqld.log
2022-04-22T07:12:28.723970Z 1 [Note] A temporary password is generated for root@localhost: tN/TN0rfV+0c
- 配置Mysql安全
- mysql_secure_installation
- 输入初始密码
tN/TN0rfV+0c
- 配置新密码
#输入新密码。长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号包含()` ~!@#$%^&*-+=|{}[]:;‘<>,.?
mysql
新密码:FrsEKF,m9a$dn2N
- 接下来操作一直
yes!
- 删除匿名用户
- 禁止使用
root
用户远程登录mysql
- 删除
test
库以及用户访问test
库的权限 - 重新加载授权表
- 接下来操作一直
PHP配置
- 新建phpinfo.php文件(网站根目录配置)
- root参数
- root参数
-
vim /usr/share/nginx/html/phpinfo.php
- 添加如下内容 保存关闭
<?php echo phpinfo(); ?>
- 新建phpinfo.php文件(网站根目录配置)
启动
php-fpm
systemctl start php-fpm
- 设置开机自启动
systemctl enable php-fpm
- 测试访问
LNMP
配置信息页面 - 在浏览器的地址栏输入
http://<ECS实例公网IP地址>/phpinfo.php
进行访问http://120.79.150.12
- 访问成功后删除php页面
rm -rf /usr/share/nginx/html/phpinfo.php
其他nginx版本安装 如1.18.1 参考文档 阿里云LNMP环境搭建
[root@iZwz9c743j35koyx2hety8Z mysql]# php -v
PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies
查看LNMP配置信息
[root@iZwz9c743j35koyx2hety8Z mysql]# mysql -V
mysql Ver 14.14 Distrib 5.7.37, for Linux (x86_64) using EditLine wrapper
[root@iZwz9c743j35koyx2hety8Z mysql]# nginx -v
nginx version: nginx/1.20.1
阿里云安装Mysql报错
报错信息
package is: mysql-community-server-5.7.37-1.el7.x86_64GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 源 “MySQL 5.7 Community Server” 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确
解决方法
由于mysql5.7密码强度太高
- 修改mysql密码
mysql> show variables like "%password%";
+----------------------------------------+-----------------+ | Variable_name | Value | +----------------------------------------+-----------------+ | default_password_lifetime | 0 | | disconnect_on_expired_password | ON | | log_builtin_as_identified_by_password | OFF | | mysql_native_password_proxy_users | OFF | | old_passwords | 0 | | report_password | | | sha256_password_auto_generate_rsa_keys | ON | | sha256_password_private_key_path | private_key.pem | | sha256_password_proxy_users | OFF | | sha256_password_public_key_path | public_key.pem | | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +----------------------------------------+-----------------+ 17 rows in set (0.00 sec)
mysql创建新用户方便记忆
- 创建数据库 名称为
wordpress
create database wordpress;
- 创建一个用户管理数据库
wordpress
mysql> create user 'reader'@'localhost' identified by 'PASSword123.';
- 赋予user操作wordpress权限
mysql grant all privileges on wordpress.* to 'user'@'localhost' identified by 'PASSword123.';
- 刷新
flush privileges;
exit;
- 创建数据库 名称为
至此LAMP环境搭建完成
安装
wordpress
根据提示一步步安装
- wordpress 自注册
- 用户名
rudy
密码
lPa^PEfXqY1L92C3aR
域名替换
公网IP
优化访问安全除了搭建LNMP/LAMP环境外 还可以搭建FTP服务器,Gitlab服务等
搭建
Gitlab
示例前提条件
-
Linux 实例已配置安全组规则:放通80端口 拥有一台服务器 内存至少4G
安装mysql后再安装postfix,系统会针对已安装mysql-server服务安装对应的postfix
-
安装
GitLab
- 执行以下命令,安装依赖包
- yum install -y curl policycoreutils-python openssh-server
- 依次执行以下命令,设置 SSH 开机自启动并启动 SSH 服务
systemctl enable sshd
systemctl start sshd
- 执行以下命令,安装
Postfix
yum install -y postfix
- 执行以下命令,设置
Postfix
服务开机自启动systemctl enable postfix
- 执行以下命令,打开
Postfix
的配置文件main.cf
vim /etc/postfix/main.cf
gitlab命令安装
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="120.79.150.12" yum install -y gitlab-ce
- 修改配置启动端口
vim /etc/gitlab/gitlab.rb
- 修改/添加行如下
-
external_url 'http://192.168.1.9'
nginx['listen_port'] = 8000
- unicorn不在适用gitlab高版本 建议使用上面一行配置
unicorn['port']=9000
-
- 执行重启命令
gitlab-ctl reconfigure
gitlab-ctl restart
- 创建项目
- 克隆项目
gitlab
卸载
Linux
基于CentOS7卸载Gitlab
- 停止
gitlab
进程gitlab-ctl stop
- 卸载
gitlab
rpm -e gitlab-ce
- 查看
gitlab
进程ps aux | grep gitlab
- 杀掉第一个进程
kill -9 18777
(18777 是第一个进程的pid号,根据显示情况输入)
- 杀掉后,使用
ps aux | grep gitlab
确认一遍,还有没有gitlab
的进程 - 如果还有进程请用以下命令杀死所有进程
ps -ef | grep gitlab | xargs kill -s 9
- 删除所有包含gitlab文件
- 停止
MySQL
安装报错- warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY - Public key for mysql-community-common-5.7.37-1.el7.x86_64.rpm is not installed - (1/4): mysql-community-common-5.7.37-1.el7.x86_64.rpm | 311 kB 00:00:00 - (2/4): mysql-community-libs-5.7.37-1.el7.x86_64.rpm | 2.4 MB 00:00:00 - (3/4): mysql-community-client-5.7.37-1.el7.x86_64.rpm | 25 MB 00:00:01 - (4/4): mysql-community-server-5.7.37-1.el7.x86_64.rpm | 174 MB 00:00:06 - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Total 27 MB/s | 202 MB 00:00:07 - Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql - Importing GPG key 0x5072E1F5: - Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" - Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 - Package : mysql57-community-release-el7-9.noarch (installed) - From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql - - - Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed -
报错分析
- Failing package is: mysql-community-server-5.7.37-1.el7.x86_64 - GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
报错原因:需安装
GPG
密钥- 执行如下命令
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 再继续执行安装
mysql-server
gitlab
修改访问端口
gitlab
安装完成默认访问的是80
端口,这个其实是gitlab
自带nigix
的端口- 修改
80
端口为8000
,修改方式为
vim /etc/gitlab/gitlab.rb
nginx['listen_port'] = 8000
重启配置
gitlab-ctl reconfigure
- 修改监听端口
- `vim /var/opt/gitlab/nginx/conf/gitlab-http.conf ` - ```listen *:8000;```
- 然后重启
gitlab
服务- `gitlab-ctl restart`
- 注意:如果修改完
gitlab-http.conf
再运行gitlab-ctl reconfigure
,就会被还原,修改并不会被覆盖- 查看端口占用情况
netstat -tunlp mkdir /var/ftp/upload
- 如下显示,则
nigix 8000
端口启动成功
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 78769/nginx: master
gitlab-ctl tail
命令可以查看启动报错问题