首页 > 其他 > 详细

lnmp分离部署

时间:2021-05-30 19:59:08      阅读:23      评论:0      收藏:0      [点我收藏+]

 

 

lnmp分离部署的准备环境

 

主机名 IP地址 环境 安装
nginx 192.168.170.132 centos8 nginx
mysql 192.168.170.133 centos8 mysql
php 192.168.170.134  centos8 php

 

 

准备工作

//关闭防火墙selinux
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# setenforce 0

[root@mysql ~]# systemctl stop firewalld
[root@mysql~]# setenforce 0

[root@php ~]# systemctl stop firewalld
[root@php ~]# setenforce 0

 

 

 

安装nginx

//创建系统用户nginx
[root@nginx ~]# useradd -r -M -s /sbin/nologin nginx

//安装开发工具包
[root@nginx ~]# yum -y groups mark install Development Tools

//安装依赖包和一些常用命令
[root@nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget

//创建日志存放目录
[root@nginx ~]# mkdir -p /var/log/nginx
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx

//下载nginx
[root@nginx ~]# wget http://nginx.org/download/nginx-1.20.0.tar.gz

[root@nginx ~]# tar xf nginx-1.20.0.tar.gz -C /usr/local/src/



//编译安装
[root@nginx ~]# cd /usr/local/src/nginx-1.20.0/
[root@nginx nginx-1.20.0]# ./configure > --prefix=/usr/local/nginx > --user=nginx > --group=nginx > --with-debug > --with-http_ssl_module > --with-http_realip_module > --with-http_image_filter_module > --with-http_gunzip_module > --with-http_gzip_static_module > --with-http_stub_status_module > --http-log-path=/var/log/nginx/access.log > --error-log-path=/var/log/nginx/error.log

[root@nginx ~]# make && make install
//配置环境变量
[root@nginx nginx-1.20.0]# echo export PATH=/usr/local/nginx/sbin:$PATH > /etc/profile.d/nginx.sh
[root@nginx nginx-1.20.0]# . /etc/profile.d/nginx.sh

 

 

安装mysql

//安装依赖包
[root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建mysql的用户和组
[root@mysql ~]# useradd -r -M -s /sbin/nologin mysql


//我这里已经下载好了所以直接解压
[root@mysql ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/src/

//设置软链接并修改属主和属组
[root@mysql src]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64/    mysql
[root@mysql src]# ll
total 0
lrwxrwxrwx. 1 root root   36 May 30 15:50 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 7161 31415 129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64
[root@mysql src]# chown -R mysql.mysql mysql*


//创建存放数据目录,配置环境变量
[root@mysql src]# mkdir /opt/data
[root@mysql src]# chown -R mysql.mysql /opt/data/
[root@mysql src]#  echo export PATH=/usr/local/src/mysql/bin:$PATH > /etc/profile.d/mysql.sh
[root@mysql src]# source /etc/profile.d/mysql.sh 



//初始化安装
[root@mysql ~]# /usr/local/src/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2021-05-30T07:54:14.378927Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-30T07:54:14.379080Z 0 [ERROR] Cant find error-message file /usr/local/mysql/share/errmsg.sys. Check error-message file location and lc-messages-dir configuration directive.
2021-05-30T07:54:14.575530Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-30T07:54:14.610797Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-30T07:54:14.671383Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3a534812-c11c-11eb-908f-000c29fa2c7d.
2021-05-30T07:54:14.671895Z 0 [Warning] Gtid table is not ready to be used. Table mysql.gtid_executed cannot be opened.
2021-05-30T07:54:15.073002Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-30T07:54:15.387645Z 1 [Note] A temporary password is generated for root@localhost: Jw5<kgfnu+X1


[root@mysql ~]# echo "Jw5<kgfnu+X1" > pass


 //配置mysql

[root@mysql support-files]# vim /etc/my.cnf
...
...
[mysqld]
basedir = /usr/local/src/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve



//配置服务启动脚本
[root@mysql ~]# cd /usr/local/src/mysql/support-files/
[root@mysql support-files]# cp mysql.server  /etc/init.d/mysqld
[root@mysql support-files]# vim /etc/init.d/mysqld
...
basedir=/usr/local/src/mysql
datadir=/opt/data
...

//启动mysql
[root@mysql support-files]# service mysqld start
Starting MySQL.Logging to /opt/data/mysql.err.
 SUCCESS! 
[root@mysql support-files]# ss -antl
State    Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN   0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN   0          128                      [::]:22                   [::]:*       
LISTEN   0          80                          *:3306                    *:*



[root@mysql ~]# cat pass 
Jw5<kgfnu+X1

[root@mysql ~]# mysql -uroot -pJw5<kgfnu+X1
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

//安装依赖包
[root@mysql ~]# yum whatprovides libncurses.so.5
Last metadata expiration check: 0:37:28 ago on Sun 30 May 2021 03:28:49 PM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : BaseOS
Matched from:
Provide    : libncurses.so.5


[root@mysql ~]# yum -y install ncurses-compat-libs


//进入数据库更改密码
[root@mysql ~]# mysql -uroot -pJw5<kgfnu+X1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

mysql> set password = password (123);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@mysql ~]# mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

mysql> quit
Bye


//安装后配置
[root@mysql ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/src/mysql/man
[root@mysql ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/src/mysql/lib
[root@mysql ~]# ldconfig

 

 

 

 

安装php

 

[root@php ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel  readline readline-devel libxslt libxslt-devel  php-mysqlnd


//安装php
[root@php ~]# yum -y install php-*

//配置php
[root@php ~]# vim /etc/php-fpm.d/www.conf
......................
;listen = /run/php-fpm/www.sock #注释此行
listen = 0.0.0.0:9000  #添加监听端口
...........................
...........................
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 192.168.248.132  #安装nginx主机的ip
.................


    
//生成测试页面

[root@php ~]# vim /var/www/html/index.php
<?php
  phpinfo();
?>
[root@php ~]# chown -R apache.apache /var/www/html/

[root@php ~]# systemctl restart php-fpm.service 
[root@php ~]# ss -antl
State    Recv-Q     Send-Q          Local Address:Port         Peer Address:Port    
LISTEN   0          128                   0.0.0.0:22                0.0.0.0:*       
LISTEN   0          128                   0.0.0.0:9000              0.0.0.0:*       
LISTEN   0          128                      [::]:22                   [::]:*   

 

 

整合Nginx和PHP

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
        location / {
            root       html;  #更改目录
            index  index.php index.html index;  #添加一个index.php
        }
        location ~ \.php$ {
            root       /var/www/html;#更改目录
            fastcgi_pass   192.168.170.134:9000;  #这里为PHP服务器的地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
            include        fastcgi_params;
        }




 

[root@nginx ~]# nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# nginx  -s stop
[root@nginx ~]# nginx 

 

 

访问测试

技术分享图片

 

lnmp分离部署

原文:https://www.cnblogs.com/meijianbiao/p/14828450.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!