标签:mysql php lnmp linux 动静分离 负载均衡
架构图:
运行原理:
用户通过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
/web192.168.61.0/24(rw,no_root_squash)
启动
servicenfs start
(b) wordpress准备
下载地址https://cn.wordpress.org/wordpress-4.3.1-zh_CN.tar.gz
解压到/web/wordpress
(b) nginx安装
安装过程参考http://dengxi.blog.51cto.com/4804263/1710472
安装好之后编辑/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段增加
upstreambbs {
server192.168.61.139:9000;
server192.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
PHP安装,参考http://dengxi.blog.51cto.com/4804263/1710479
编译安装完成之后,把/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添加好启动服务
最后启动服务
servicephp-fpm start
3.配置Usvr2
挂载ngsvr的nfs
mkdir/web
mount-t nfs 192.168.61.131:/web /web
mysql安装,参考http://dengxi.blog.51cto.com/4804263/1713256
PHP安装,参数Usvr1
最后启动mysql、php-fpm服务
4.后续整合配置
Usvr2:
登陆mysql增加wordpress数据库和用户wordpress,密码123456
mysql -uroot -p
createdatabase wordpress;
GRANTALL ON *.* TO wordpress@‘0.0.0.0‘ IDENTIFIED BY ‘123456‘;
Ngsvr:
浏览器运行http://192.168.61.131/wp-admin/install.php进行wordpress安装
安装完成后,即可以http://192.168.61.131/index.php访问wordpress
LNMP基于FastCGI实现Nginx,PHP,MySQL的架构分离
标签:mysql php lnmp linux 动静分离 负载均衡
原文地址:http://dengxi.blog.51cto.com/4804263/1713318