首页
学
【学】PHP
【学】前端
【学】Linux
【学】杂学
【学】支付
【学】Docker
享
【享】文件
【享】工具
日记
Me
【Me】我
【Me】留言
老郭博客-程序员客栈
文章模型
下载模型
首页
学
【学】PHP
【学】前端
【学】Linux
【学】杂学
【学】支付
【学】Docker
享
【享】文件
【享】工具
日记
Me
【Me】我
【Me】留言
首页
学
【学】Linux
Centos7.3搭建LNMP
Centos7.3搭建LNMP
发布时间:
3年前
作者:
老郭
热度:
1843 ℃
评论数:
# 1. 安装Nginx YUM源中没有Nginx,我们需要增加一个nginx的源nginx.repo. ``` # 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 ``` 出现如下提示: ``` 已加载插件:fastestmirror nginx | 2.9 kB 00:00:00 nginx/7/x86_64/primary_db | 18 kB 00:00:04 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 可安装的软件包 nginx.x86_64 1:1.10.2-1.el7.ngx nginx ``` ``` #yum list |grep nginx ``` ``` nginx.x86_64 1:1.10.2-1.el7.ngx nginx nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx nginx-debuginfo.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-geoip.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-geoip-debuginfo.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-image-filter.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-image-filter-debuginfo.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-njs.x86_64 1:1.10.2.0.0.20160414.1c50334fbea6-2.el7.ngx nginx nginx-module-njs-debuginfo.x86_64 1:1.10.2.0.0.20160414.1c50334fbea6-2.el7.ngx nginx nginx-module-perl.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-perl-debuginfo.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-xslt.x86_64 1:1.10.2-1.el7.ngx nginx nginx-module-xslt-debuginfo.x86_64 1:1.10.2-1.el7.ngx nginx nginx-nr-agent.noarch 2.0.0-10.el7.ngx nginx pcp-pmda-nginx.x86_64 3.10.6-2.el7 base ``` 安装成功后,就可以直接安装nginx了 ``` #yum -y install nginx ``` 安装的就是Nginx官网的最新版本。 启动nginx服务 ``` sudo systemctl start nginx.service ``` 关闭防火墙 ``` systemctl start firewalld.service#启动firewall systemctl stop firewalld.service#停止firewall systemctl disable firewalld.service#禁止firewall开机启动 ``` 可以使用curl命令查看是否安装成功: ``` #curl 127.0.0.1 ``` 如果安装成功的话,就会看到输出一个HTML的一个反馈 ``` <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> ``` 开机启动设置: ``` sudo systemctl enable nginx.service ``` # 2. 安装MySql(5.7)不成功,并且下载慢,不建议使用。 [Mysql官网](http://dev.mysql.com/downloads/repo/yum/) ``` #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 启用: 24 mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用 mysql-tools-community/x86_64 MySQL Tools Community 启用: 38 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 - Sourc 禁用 mysql56-community/x86_64 MySQL 5.6 Community Server 禁用 mysql56-community-source MySQL 5.6 Community Server - Sourc 禁用 mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 146 mysql57-community-source MySQL 5.7 Community Server - Sourc 禁用 mysql80-community/x86_64 MySQL 8.0 Community Server 禁用 mysql80-community-source MySQL 8.0 Community Server - Sourc 禁用 ``` 如果没有启用的话,我们可以修改源文件: ``` # vi /etc/yum.repos.d/mysql-community.repo ``` ``` [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 ``` 把enabled改为1就可以了,其他的版本改为0 ``` [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 ``` ``` mysql-connectors-community/x86_64 MySQL Connectors Community 24 mysql-tools-community/x86_64 MySQL Tools Community 38 mysql57-community/x86_64 MySQL 5.7 Community Server 146 ``` 如果看到5.7版本启用了之后就可以安装MySql了 ``` #yum -y install mysql-community-server ``` 安装完成之后,就可以启动mysql了 ``` #service mysqld start ``` 查看MySql的启动状态 ``` #service mysqld status ``` ``` Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 日 2017-05-23 22:51:48 CST; 3min 14s ago Process: 36884 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 36810 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 36887 (mysqld) CGroup: /system.slice/mysqld.service └─36887 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 5月 23 22:51:45 192.168.0.14 systemd[1]: Starting MySQL Server... 5月 23 22:51:48 192.168.0.14 systemd[1]: Started MySQL Server. 5月 23 22:52:24 192.168.0.14 systemd[1]: Started MySQL Server. ``` 开机启动设置 ``` #systemctl enable mysqld #systemctl daemon-reload ``` MySql安装完成之后会在LOG文件(/var/log/mysqld.log)中生成一个root的默认密码: ``` #grep 'temporary password' /var/log/mysqld.log ``` ``` 2017-05-23T14:51:45.705458Z 1 [Note] A temporary password is generated for root@localhost: d&sqr7dcf7P_ ``` 登录MySql并修改root密码: ``` #mysql -uroot -p mysql>set global validate_password_policy=0; mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new psd'; ``` 扩展阅读: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_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 restart mysqld ``` 远程登录用户添加 ``` mysql> GRANT ALL PRIVILEGES ON . TO 'lmc'@'%' IDENTIFIED BY '1qazXsw@' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES; ``` 查看用户 ``` mysql> select host,user from mysql.user; ``` ``` +-----------+-----------+ | host | user | +-----------+-----------+ | % | lmc | | localhost | mysql.sys | | localhost | root | +-----------+-----------+ 3 rows in set (0.00 sec) ``` ``` 由于开始没有关闭SELinux,引起mysql连接失败的解决: http://www.jianshu.com/p/ddd3ce15cb84 ``` # 3. 安装MariaDB(5.5.56) MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。 1. 安装MariaDB ``` sudo yum install mariadb-server mariadb ``` 2. 开启MariaDB ``` sudo systemctl start mariadb ``` 3. 安装安全措施 在成功启动 MariaDB/MySQL 服务后,执行在 MariaDB/MySQL 服务包中的脚本。这一次的运行会为为数据库服务器进行一些安全强化措施,如设置(非空)的 root 密码、删除匿名用户、锁定远程访问。 ``` sudo mysql_secure_installation ``` 接下来在命令行会提示设置mysql用户名和密码,全选yes。 4. 设置开机自动重启mysql ``` sudo systemctl enable mariadb.service ``` # 4. 安装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 ``` #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 ``` 或者 ``` Centos 5.X rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm CentOs 6.x rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm CentOs 7.X rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm ``` 编辑php配置文件 ``` sudo vi /etc/php.ini cgi.fix_pathinfo=0 ``` 安装php-fpm ``` #yum install php70w-fpm php70w-opcache ``` 设置php-fpm配置文件 ``` sudo vi /etc/php-fpm.d/www.conf listen = /var/run/php-fpm/php-fpm.sock ``` 启动php-fpm ``` #systemctl start php-fpm ``` 开机启动设置 ``` #systemctl enable php-fpm #systemctl daemon-reload ``` 配置nginx站点 ``` sudo vi /etc/nginx/conf.d/default.conf ``` ``` server { listen 80; server_name localhost; root /opt/data; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; #支持thinkphp中的url重定向 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?s=$1 last; } } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` ``` vi /etc/php-fpm.d/www.conf ``` 将 ``` ;listen.owner = nobody ;listen.group = nobody ;listen.mode = 0660 ``` 改为: ``` listen.owner = apache listen.group = apache listen.mode = 0777 ``` 重启Nginx使修改生效. # Phpmyadmin报2003错误,命令行可以进入mysql 1.数据库没有授权 远程连接数据库的时候需要输入用户名和密码 用户名:root 密码:123456 指点ip:%代表所有Ip,此处也可以输入Ip来指定Ip ``` MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) ``` 输入后使修改生效还需要下面的语句 ``` MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) ```
Centos7,LNMP,Linux,Nginx,PHP,MariaDB
上一篇:
Centos7安装Redis
下一篇:
Centos7.3搭建LNMP(文章二)
栏目导航
【学】PHP
【学】前端
【学】Linux
【学】杂学
【学】支付
【学】Docker
相关文章
Centos7中 ntp 定时时间同步
3608 ℃
Centos7搭建LAMP
1169 ℃
Centos7搭建Git及安装使用
1514 ℃
Centos7搭建JDK+Tomcat
1148 ℃
Centos7安装Redis
1344 ℃
Centos7.3搭建LNMP
1843 ℃
Centos7.3搭建LNMP(文章二)
1621 ℃
Centos7搭建SVN服务器
2006 ℃
Centos 6.x 或 7.x yum安装php5.6.X(最新版)
1461 ℃
Nginx-一个IP配置多个站点(无域名)
3506 ℃
Centos7使用FireWall开放8888端口
2102 ℃
Centos7.4编译安装Nginx_1.13.8、php_7.2.1、mysql_5....
1238 ℃
Cenots7下添加Php的Redis扩展
1259 ℃
Redis引起的删库跑路加勒索事件
3301 ℃
创业耗费百万,为何DDoS如此要命Part 1
2052 ℃
记一次被黑后的经历
3275 ℃
(最新)CentOS7.4搭建LN(1.14.0)M(MariaDB)P(7....
2893 ℃
微信小程序
手机扫码访问