分离式部署LNMP


-------Nginx----------PHP+NFS------------MySql------
192.168.56.202 192.168.56.201 192.168.56.200
安装MySql
安装Nginx
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost nginx-1.6.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.6.0]# nginx -t
[root@localhost nginx-1.6.0]# nginx
测试:http://192.168.56.202

安装PHP
[root@localhost php-5.3.28]# yum install gd libxml2-devel libjpeg-devel libpng-devel -y
[root@localhost php-5.3.28]# ./configure --prefix=/usr/local/php
--with-gd
--with-zlib
--with-mysql=mysqlnd
--with-pdo-mysql=mysqlnd
--with-mysqli=mysqlnd
--with-config-file-path=/usr/local/php
--enable-mbstring
--enable-fpm
--with-jpeg-dir=/usr/lib
[root@localhost php-5.3.28]# cp php.ini-development /usr/local/php/php.ini
[root@localhost php-5.3.28]# vim /usr/local/php/php.ini
default_charset = "utf-8"
short_open_tag = On
[root@localhost php-5.3.28]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.3.28]# chmod +x /etc/init.d/php-fpm
[root@localhost php-5.3.28]#chkconfig --add php-fpm
[root@localhost php-5.3.28]#chkconfig php-fpm on
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf
pid = run/php-fpm.pid
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
[root@localhost ~]# service php-fpm start

整合nginx与PHP
Nginx server 192.156.56.202
[root@localhost ~]# mkdir /www
[root@localhost ~]# chown -R nginx.nginx /www/

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root /www;
index index.php index.html index.htm;
}
location ~ .php$ {
root /www;
fastcgi_pass 192.168.56.201:9000; //注意为PHP服务器
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}

[root@localhost ~]#/etc/init.d/nginx restart
在PHP服务器上,建立nginx用户,要保证和nginx服务器上的nginx用户id号、组id号一致
[root@localhost ~]# useradd nginx
[root@localhost ~]# vim /usr/local/php/etc/php-fpm.conf
listen = 192.168.56.201:9000     
user = nginx
group = nginx
[root@localhost ~]# /etc/init.d/php-fpm restart

在PHP服务器上,创建NFS共享
[root@localhost ~]# mkdir /www
[root@localhost ~]# chown -R nginx.nginx /www
[root@localhost ~]# vim /etc/exports
/www 192.168.56.0/24(rw,no_root_squash,sync)
no_root_squash:登入 NFS 主机使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限!这个项
目『极不安全』,不建议使用!
root_squash:在登入 NFS 主机使用分享之目录的使用者如果是 root 时,那么这个使用者的权限将被压缩成为匿名使用者,通常他的 UID
与 GID 都会变成 nobody 那个系统账号的身份。
[root@localhost ~]# service nfs start

nginx服务器挂载nfs文件,并测试php,测试成功后删除index.php:
[root@localhost ~]# showmount -e 192.168.56.201 //查看共享
[root@localhost ~]# mount -t nfs 192.168.56.201:/www /www
[root@localhost ~]# vim /www/index.php
[root@localhost ~]# service nginx restart

整合PHP与MYSQL
在mysql服务器上创建php服务器能够访问的数据库和用户:
mysql> grant all on *.* to 'root'@'192.168.56.201' identified by 'redhat'
//注意授权的是PHP服务器的登录地址
mysql> flush privileges;
[root@localhost ~]# unzip Discuz_7.2_FULL_SC_UTF8.zip
[root@localhost ~]# mv upload/* /www/
[root@localhost ~]# chmod -R 777 /www/*

浏览器登录:http://http://192.168.56.202/install //注意mysql地址为:192.168.56.200
在mysql服务器上测试:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| discuz |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)

原文地址:https://www.cnblogs.com/luoyan01/p/9734162.html