多台服务器分离部署lnmp
使用三台主机部署lnmp架构
nginx主机ip:192.168.1.241
php主机ip:192.168.1.242
mariadb主机ip:192.168.1.101
三台主机关闭selinux及firewalld
setenforce 0
systemctl stop firewalld
nginx主机:
1.安装nginx
yum install -y nginx
2.配置nginx关联php-fpm
vi /etc/nginx/nginx.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 192.168.1.242:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3.安装nfs-utils客户端
yum install -y nfs-utils
4.编辑/etc/exports文件
vi /etc/exports
/usr/share/nginx/html 192.168.1.242(rw,sync,insecure,root_squash)
5.启动rpcbind,nfs服务
systemctl start rpcbind
systemctl start nfs-server
6.在/usr/share/nginx/html编写测试文件
vi index.php
<?php
phpinfo();
?>
php主机:
1.安装php,php-fpm,php-mysqlnd
yum install -y php php-fpm php-mysqlnd
2.配置php-fpm
vi /etc/php-fpm.d/www.conf
user=nginx
group=nginx
listen=192.168.1.242:9000
listen.allowed_clients=192.168.1.241
3.启动php-fpm
systemctl start php-fpm
mariadb主机:
1.安装mariadb-server mariadb
yum install -y mariadb-server mariadb
2.启动mariadb-server
systemctl start mariadb
挂载php主机的/usr/share/nginx/html 至nginx主机的/usr/share/nginx/html目录
安装nfs-utils:
mount -t nfs 192.168.1.242:/usr/share/nginx/html /usr/share/nginx/html