LNMP分开部署安装

lnmp分开安装

ip 设备
192.168.89.132 NGINX
192.168.89.129 PHP
192.168.89.131 MYSQL

1.安装mysql(192.168.89.131)

1.1下载mysql

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

1.2创建mysql的用户和组

[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql

1.3解压mysql包

[root@localhost src]# tar xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              nginx  share
etc  include  lib64  mysql-5.7.23-linux-glibc2.12-x86_64  sbin   src
[root@localhost local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/      mysql      创建软连接
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"
[root@localhost local]# ll
lrwxrwxrwx   1 root root  36 10月 19 08:34 mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
drwxr-xr-x   9 root root 129 10月 19 08:33 mysql-5.7.23-linux-glibc2.12-x86_64

1.4修改解压位置mysql文件的属主和组

[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll
lrwxrwxrwx   1 mysql mysql  36 10月 19 08:34 mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
drwxr-xr-x   9 root  root  129 10月 19 08:33 mysql-5.7.23-linux-glibc2.12-x86_64

1.5创建环境变量

[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql

1.6建立数据存放目录并初始化

[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# ll /opt/data/ -d
drwxr-xr-x 2 mysql mysql 6 10月 19 08:36 /opt/data/
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
······
2018-10-19T00:37:36.976376Z 1 [Note] A temporary password is generated for root@localhost: /gfwaEeY8FBs    最后一行为随机密码

1.7配置mysql

[root@localhost local]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@localhost local]# ll /usr/local/include/
总用量 0
lrwxrwxrwx 1 root root 25 10月 19 08:39 mysql -> /usr/local/mysql/include/
[root@localhost local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# ldconfig -v

1.8生成配置文件

[root@localhost local]# cat > /etc/my.cnf < [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@localhost local]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

1.9配置服务启动脚本

[root@localhost local]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# vim mysql.server

basedir=/usr/local/mysql
datadir=/opt/data    修改这两行

1.10启动服务mysql

[root@localhost support-files]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 

1.11修改密码

[root@localhost support-files]# mysql -uroot -p 
Enter password: 
mysql> set password = password('wscl1996.');
Query OK, 0 rows affected, 1 warning (0.00 sec)

2.安装php(192.168.89.129)

2.1创建nginx用户

[root@localhost ~]# groupadd -r -g 955 nginx
[root@localhost ~]# useradd -M -s /sbin/nologin -g 955 -u 955 nginx
[root@localhost ~]# id nginx
uid=955(nginx) gid=955(nginx) 组=955(nginx)  确保php和nginx的nginx用户的uid,gid,组id一致

2.2安装php依赖包

[root@localhost ~]# yum -y install epel-release gcc gcc-c++
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel

2.3下载并解压安装php

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@localhost src]# tar xvf php-7.2.8.tar.xz
[root@localhost src]# cd php-7.2.8/
[root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install

2.4配置环境变量

[root@localhost php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost php-7.2.8]# source /etc/profile.d/php7.sh 
[root@localhost php-7.2.8]# which php
/usr/local/php7/bin/php

2.5配置php-fpm

[root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@localhost php-7.2.8]# cd /usr/local/php7/etc/
[root@localhost etc]# ll
总用量 12
-rw-r--r-- 1 root root 1244 10月 19 09:16 pear.conf
-rw-r--r-- 1 root root 4468 10月 19 09:16 php-fpm.conf.default
drwxr-xr-x 2 root root   30 10月 19 09:16 php-fpm.d

[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf

2.6修改php-fpm配置文件

[root@localhost php-fpm.d]# cd ..
[root@localhost etc]# vim php-fpm.conf
user = nginx
group = nginx
listen = 192.168.89.129:9000       本机ip 
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8 

2.7启动php-fpm


[root@localhost etc]# service php-fpm start
Starting php-fpm  done
[root@localhost etc]# ss -antl
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                  127.0.0.1:9000                                     *:*                  

LISTEN      0      100                  127.0.0.1:25                                       *:*                  

LISTEN      0      80                          :::3306                                    :::*                  

LISTEN      0      128                         :::80                                      :::*                  

3.nginx安装与配置(192.168.89.132)

3.1创建nginx用户

[root@localhost ~]# groupadd -r -g 955 nginx
[root@localhost ~]# useradd -M -s /sbin/nologin -g 955 -u 955 nginx
[root@localhost ~]# id nginx
uid=955(nginx) gid=955(nginx) 组=955(nginx)  

3.2安装nginx依赖环境

[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@localhost ~]# yum -y groups mark install 'Development Tools'

3.3建立nginx日志存放目录

[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/
[root@localhost ~]# ll /var/log/nginx/ -d
drwxr-xr-x 2 nginx nginx 6 10月 18 10:39 /var/log/nginx/

3.4下载并安装nginx

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@localhost src]# tar -xvf nginx-1.12.0.tar.gz
[root@localhost src]# cd nginx-1.12.0/
[root@localhost nginx-1.12.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@localhost nginx-1.12.0]# make && make install

3.5配置nginx的环境变量

[root@localhost nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.12.0]# . /etc/profile.d/nginx.sh 
[root@localhost nginx-1.12.0]# which nginx
/usr/local/nginx/sbin/nginx
[root@localhost nginx-1.12.0]# nginx   启动nginx
[root@localhost nginx-1.12.0]# ss -antl
State       Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
LISTEN      0      128                 *:80                              *:*                  
LISTEN      0      128                 *:22                              *:*                  
LISTEN      0      100         127.0.0.1:25                              *:*                  
LISTEN      0      128                :::22                             :::*                  
LISTEN      0      100               ::1:25                             :::*                

3.6nginx的控制方式

-t      检查配置文件语法
-v      输出nginx版本
-c      制定配置文件路径
-s      发送服务控制信号ํ{stop|quit|reopen|reload}

3.7配置nginx

[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.php index.html index.htm;    在后面加上index.php
······
        location ~ \.php$ {
            root           html;
            fastcgi_pass   192.168.89.129:9000;    php的ip地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;    
            include        fastcgi_params;       去掉这几行前面的#号
            

4.查看效果

4.1 创建html(192.168.89.129)

[root@localhost ~]# mkdir -R /usr/local/nginx/html/
[root@localhost ~]# chown -R nginx.nginx /usr/local/nginx/html/
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost ~]# vim index.php

4.2 创建html(192.168.89.132)

[root@localhost ~]# cd /usr/local/nginx/html
[root@localhost ~]# vim index.php

4.3重载nginx的配置文件和重启php服务

[root@localhost ~]# nginx -s reload
[root@localhost ~]# service php-fpm restart 

4.4登录网页

LNMP分开部署安装_第1张图片

5.mysql配置

5.1数据库服务器上创建wordpress数据库及授权帐户(192.168.89.131)

[root@localhost ~]# mysql -uroot -p
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on wordpress.* to root@'%' identified by 'cl996.';
Query OK, 0 rows affected, 1 warning (0.00 sec)

5.2下载wordpress并解压到nginx的服务器

[root@localhost ~]# wget https://wordpress.org/latest.tar.gz
[root@localhost ~]# tar zxf latest.tar.gz 
[root@localhost ~]# mv wordpress/* /usr/local/nginx/html/

5.3下载wordpress并解压到PHP的服务器

[root@localhost ~]# wget https://wordpress.org/latest.tar.gz
[root@localhost ~]# tar zxf latest.tar.gz 
[root@localhost ~]# mv wordpress/* /usr/local/nginx/html/

5.4测试访问

在这里插入图片描述LNMP分开部署安装_第2张图片
LNMP分开部署安装_第3张图片
LNMP分开部署安装_第4张图片

你可能感兴趣的:(作业)