欢迎光临
我们一直在努力

PHP网站简单架构 – 单独跑php-fpm

前端1台Nginx:负载均衡+nfs
中间2台php:php-fpm
后端1台数据库:MySQL

PHP网站简单架构 – 单独跑php-fpm

安装略,参考
192.168.112安装Tengine
192.168.1.113/192.168.1.115安装php
192.168.1.114安装MySQL

nfs配置
nfs服务端:192.168.1.112
检查nfs否已安装,这里我已经都安装了。

  1. [root@linux2 ~]# rpm -qa | grep nfs
  2. nfs-utils-1.0.9-66.el5
  3. nfs-utils-lib-1.0.8-7.9.el5
  4. [root@linux2 ~]# rpm -qa | grep portmap
  5. portmap-4.0-65.2.2.1

如果你检查发现没有安装,可以使用一下命令进行安装;

  1. yum -y install nfs-utils portmap
  1. cat /etc/exports
  2. /home/wwwroot 192.168.1.0/24(rw)

设置固定端口,方便配置iptables

  1. cat >> /etc/sysconfig/nfs << EOF
  2. RQUOTAD_PORT=50001
  3. LOCKD_TCPPORT=50002
  4. LOCKD_UDPPORT=50002
  5. MOUNTD_PORT=50003
  6. STATD_PORT=50004
  7. EOF
  1. iptables -I INPUT 5 -s 192.168.1.0/24 -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
  2. iptables -I INPUT 6 -s 192.168.1.0/24 -p udp --dport 111 -j ACCEPT
  3. iptables -I INPUT 7 -s 192.168.1.0/24 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
  4. iptables -I INPUT 8 -s 192.168.1.0/24 -p udp --dport 2049 -j ACCEPT
  5. iptables -I INPUT 9 -s 192.168.1.0/24 -p tcp -m state --state NEW -m tcp --dport 50001:50004 -j ACCEPT
  6. iptables -I INPUT 10 -s 192.168.1.0/24 -p udp --dport 50001:50004 -j ACCEPT
  7. service iptables save

开机自动启动nfs

  1. chkconfig portmap on
  2. chkconfig nfs on
  1. service portmap start
  2. service nfs start

现在看看启动的端口:

  1. rpcinfo -p localhost

nfs客户端:192.168.1.113,192.168.1.115

  1. yum -y install portmap
  1. chkconfig portmap on
  2. service portmap start

查看远程nfs共享信息

  1. showmount -e 192.168.1.112

在/etc/fstab配置文件中添加如下,开机自动挂载

  1. 192.168.1.112:/home/wwwroot /home/wwwroot nfs defaults 0 0

重新读取/etc/fstab配置文件挂载所有

  1. mount -a

数据库:192.168.1.114
如:举例网站程序是discuz,创建数据库、赋权,让php能远程访问,如下:

  1. # mysql -uroot -p
  2. mysql> create database linuxeye_bbs;
  3. mysql> grant all privileges on linuxeye_bbs.* to linuxeye_user@'192.168.1.%' identified by 'linuxeye_password';
  4. mysql> flush privileges;

iptables配置

  1. iptables -I INPUT 5 -s 192.168.1.0/24 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
  2. service iptables save

php:192.168.113
lnmp脚本用的是本机127.0.0.1,为了支持让前端Tengine访问,修改配置文件/usr/local/php/etc/php-fpm.conf

  1. listen = 192.168.1.113:9000
  2. listen.allowed_clients = 192.168.1.112
  1. service php-fpm restart

iptables配置

  1. iptables -I INPUT 5 -s 192.168.1.112 -p tcp -m state --state NEW -m tcp --dport 9000 -j ACCEPT
  2. service iptables save

php:192.168.115
同理,修改/usr/local/php/etc/php-fpm.conf

  1. listen = 192.168.1.115:9000
  2. listen.allowed_clients = 192.168.1.112
  1. service php-fpm restart

iptables配置

  1. iptables -I INPUT 5 -s 192.168.1.112 -p tcp -m state --state NEW -m tcp --dport 9000 -j ACCEPT
  2. service iptables save

Tengine:192.168.112
配置Tengine负载均衡,在主配置文件/usr/local/tengine/conf/nginx.conf中http段添加如下

  1. upstream cluster_discuz {
  2. ip_hash;
  3. server 192.168.1.112:9000;
  4. server 192.168.1.115:9000;
  5. }

添加虚拟主机文件
运行lnmp/vhost.sh,创建虚拟主机(我这里添加的直接是ip192.168.1.112)
修改虚拟主机配置文件/usr/local/tengine/conf/vhost/192.168.1.112.conf

  1. location ~ .*\.(php|php5)?$ {
  2. fastcgi_pass cluster_discuz;
  3. fastcgi_index index.php;
  4. include fastcgi.conf;
  5. }

重启nginx

  1. service nginx restart
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

除特别注明外,本站所有文章均基于CC-BY-NC-SA 4.0原创,转载请注明出处。
文章名称:《PHP网站简单架构 – 单独跑php-fpm》
文章链接:https://www.xpn.cc/242/fy.html
分享到: 更多 (0)

热门推荐

评论 抢沙发

登录

忘记密码 ?