安装前准备
1.停止firewall防火墙:
systemctl stop firewalld.service #停止firewall
2.关闭SELINUX:
临时关闭
setenforce 0 #不用重启立即生效
永久关闭
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
SELINUX=disabled #增加
:wq! #保存退出
3.更换YUM源
安装Nginx
检查YUM源中是否有nginx 如果无则配置一个nginx源文件
vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
通过以下命令查看nginx源文件是否配置成功(如有信息显示代表成功)
yum list nginx
yum list | grep nginx
进行安装nginx(安装的是nginx官网的最新版本)
yum -y install nginx
检查是否安装成功
curl 127.0.0.1 (在终端输入命令,如果安装成功,就会看到输出一个HTML的一个反馈)
loalhost (或者在浏览器访问)
nginx管理
nginx #启动Nginx
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止
systemctl stop status.service #查看nginx状态
systemctl restart nginx.service #重启
systemctl enable nginx.service #设置开机启动
systemctl daemon-reload 重新载入systemd,扫描新的或有变动的单元
安装MySql(5.7)
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
查看5.7版本是否已经启用
yum repolist all | grep mysql
!mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 74
mysql-connectors-community-source MySQL Connectors Community - Sou 禁用
!mysql-tools-community/x86_64 MySQL Tools Community 启用: 74
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - Sou 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - Sou 禁用
!mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 307
mysql57-community-source MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - Sou 禁用
如果没有启用的话,我们可以修改源文件
vim /etc/yum.repos.d/mysql-community.repo
把mysql5.7版本的enabled改为1就可以了,其他的版本改为0
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改完成之后查看可用的版本
yum repolist enabled | grep mysql
如果看到5.7版本启用了之后就可以安装MySql了
!mysql-connectors-community/x86_64 MySQL Connectors Community 74
!mysql-tools-community/x86_64 MySQL Tools Community 74
!mysql57-community/x86_64 MySQL 5.7 Community Server 307
yum -y install mysql-community-server
MySql安装完成之后会在LOG文件(/var/log/mysqld.log)中生成一个root的默认密码
grep 'temporary password' /var/log/mysqld.log #查看默认密码
2018-12-03T02:57:01.088822Z 1 [Note] A temporary password is generated for root@localhost: yox/0QRosy6a
登录MySql并修改root密码
mysql -uroot -p
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPwd';
mysql5.7默认安装了密码安全检查插件,默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
通过msyql环境变量可以查看密码策略的相关信息:
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_proxy_users | OFF |
| 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 |
+---------------------------------------+--------+
14 rows in set (0.01 sec)
默认的密码策略
validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置:
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
修改默认编码
在/etc/my.cnf配置文件的[mysqld]下添加编码配置:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
mysql管理
systemctl start mysqld #启动mysql
systemctl stop mysqld #停止
systemctl stop status.mysqld #查看mysql状态
systemctl restart mysqld #重启
systemctl enable mysqld #设置开机启动
systemctl daemon-reload 重新载入systemd,扫描新的或有变动的单元
远程登录用户添加
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我们添加一个新的帐户:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'badPerson'@'%' IDENTIFIED BY '123456Qwe.' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
这样远程就可以用账户名为 badPerson,密码为 123456Qwe. 来登录数据库了
查看用户
mysql> select host,user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | badPerson |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
安装PHP7
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
PHP7.0安装
yum install 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-mysql.x86_64 php70w-pdo.x86_64
PHP7.2安装
yum install php72w php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64
安装php-fpm
yum install php70w-fpm php70w-opcache
启动php-fpm
systemctl start php-fpm
设置开机启动
systemctl enable php-fpm
systemctl daemon-reload
修改nginx配置文件
vim /etc/nginx/conf.d/default.conf
修改下面这段
location ~ \.php$ {
root /var/www/html; #定义跟目录
fastcgi_pass 127.0.0.1:9000; #定义http代理到哪个fastcgi服务端接口
fastcgi_index index.php; #定义fastcgi默认使用的脚本
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #定义fastcgi请求中的参数
include fastcgi_params;
}
接着到 /var/www/html 目录下创建一个test.php文件,内容为phpinfo():
vi /var/www/html/test.php
<?php
phpinfo();
重启nginx
systemctl restart nginx
打开浏览器运行
127.0.0.1/test.php #出现PHP信息表示ok
开启防火墙打开80和3306端口
systemctl start firewalld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload #更新防火墙规则
查看端口是否开启成功
firewall-cmd --zone=public --list-ports
出现以下信息代表成功
[root@localhost /]# firewall-cmd --zone=public --list-ports
22/tcp 80/tcp 3306/tcp
感谢
作者:890624
https://www.jianshu.com/p/02baa54283ba