架构图:
运行原理:
用户通过Ngsvr调度器访问wordpress,Ngsvr服务器会根据调度算法把请求负载均衡调度至Usvr1和Usvr2.并通过fastcgi协议与Usvr1、Usvr2通信返回动态数据
总体配置:
Ngsvr: IP 192.168.61.131,需安装的软件nginx,wordpress
Usvr1: IP 192.168.61.139,需安装的软件php
Usvr2: IP 192.168.61.140需安装的软件php,mysql
1.配置Ngsvr
(a) 、配置nfs
安装
yum -y install nfs-utils
添加开机启动
chkconfig nfs on
设定wordpress目录
mkdir -pv /web
编辑vim /etc/exports
/web 192.168.61.0/24(rw,no_root_squash)
启动
service rpcbind start (不启动的话会报错)
chkconfig rpcbind on
service nfs start
检查是否正常共享,有显示所设置的目录即为正常
showmount -e 192.168.61.131
(b)、 wordpress准备
解压到/web/wordpress
(c)、 nginx安装
安装好之后编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
修改/etc/nginx/nginx.conf文件
在http段增加
upstream bbs {
server 192.168.61.139:9000;
server 192.168.61.140:9000;
}
/etc/nginx/nginx.conf,最后面有php配置的案例,去掉注释修改
# pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000
location ~ \.php$ {
root /web/wordpress; #指定wordpress目录
fastcgi_pass bbs; #指定刚才定义的上游服务器组
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; #使用扩展的fastcgi参数
}
最后启动服务
service nginx start
2.配置Usvr1
挂载ngsvr的nfs
mkdir /web
mount -t nfs 192.168.61.131:/web /web
编译安装完成之后,把/usr/local/php/etc目录下php-fpm.conf.default配置示例文件改名php-fpm.conf作为配置文件。
拷贝源码目录下的php.ini-production到编译时指定的配置文件目录 /usr/local/php/etc下,并改名为php.ini。
拷贝源码目录下sapi/fpm/init.d.php-fpm 到/etc/init.d/php-fpm添加好启动服务
最后启动服务
service php-fpm start
3.配置Usvr2
挂载ngsvr的nfs
mkdir /web
mount-t nfs 192.168.61.131:/web /web
PHP安装,参考Usvr1
最后启动mysql、php-fpm服务
4.后续整合配置
Usvr2:
登陆mysql增加wordpress数据库和用户wordpress,密码123456
mysql -uroot -p
create database wordpress;
GRANTALL ON *.* TO wordpress@'0.0.0.0' IDENTIFIED BY '123456';
Ngsvr: