PHP網站簡單架構 – 單獨跑php-fpm

這個架構比較簡單,不作過多的說明
前端1臺Nginx:負載均衡+nfs
中間2臺php:php-fpm
後端1臺數據庫:MySQLphp

安裝略,參考lnmp最新源碼一鍵安裝包
192.168.112安裝Tengine
192.168.1.113/192.168.1.115安裝php
192.168.1.114安裝MySQLhtml

nfs配置
nfs服務端:192.168.1.112
檢查nfs否已安裝,這裏我已經都安裝了。前端

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

若是你檢查發現沒有安裝,能夠使用一下命令進行安裝;mysql

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

設置固定端口,方便配置iptableslinux

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

開機自動啓動nfsnginx

chkconfig portmap on
chkconfig nfs on
service portmap start
service nfs start

如今看看啓動的端口:sql

rpcinfo -p localhost

nfs客戶端:192.168.1.113,192.168.1.115數據庫

yum -y install portmap
chkconfig portmap on
service portmap start

查看遠程nfs共享信息後端

showmount -e 192.168.1.112

在/etc/fstab配置文件中添加以下,開機自動掛載架構

192.168.1.112:/home/wwwroot  /home/wwwroot      nfs     defaults        00

從新讀取/etc/fstab配置文件掛載全部

mount -a

數據庫:192.168.1.114
如:舉例網站程序是discuz,建立數據庫、賦權,讓php能遠程訪問,以下:

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

iptables配置

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

php:192.168.113
lnmp腳本用的是本機127.0.0.1,爲了支持讓前端Tengine訪問,修改配置文件/usr/local/php/etc/php-fpm.conf

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

iptables配置

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

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

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

iptables配置

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

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

        upstream cluster_discuz {
                ip_hash;
                server 192.168.1.112:9000;
                server 192.168.1.115:9000;}

添加虛擬主機文件
運行lnmp/vhost.sh,建立虛擬主機(我這裏添加的直接是ip192.168.1.112)
修改虛擬主機配置文件/usr/local/tengine/conf/vhost/192.168.1.112.conf

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

重啓nginx

service nginx restart

原文地址:http://blog.linuxeye.com/358.html

相關文章
相關標籤/搜索