3.PHP的本地Session信息
3.1 问题
通过Nginx调度器负载后端两台Web服务器,实现以下目标:
部署Nginx为前台调度服务器
调度算法设置为轮询
后端为两台LNMP服务器
部署测试页面,查看PHP本地的Session信息
- 1
- 2
- 3
- 4
3.2 方案
使用4台RHEL7虚拟机,其中一台作为Nginx前端调度器服务器(eth0:192.168.4.5,eth1:172.16.2.5)、两台虚拟机部署为LNMP服务器,分别为Web1服务器(192.168.2.100)和Web2服务器(192.168.2.200),另外一台作为测试用的Linux客户机(172.16.4.100),拓扑如图-2所示。
图-2
3.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:部署后端LNMP服务器相关软件
注意:以下部署LNMP服务器的操作,需要在两台后端服务器做相同的操作,下面我们以一台Web1服务器(192.168.2.100)为例,对Web2服务器执行相同操作即可。
1)使用yum安装基础依赖包
[root@web1 ~]# yum -y install gcc openssl-devel pcre-devel zlib-devel
.. ..
- 1
- 2
2)源码安装Nginx
[root@web1 ~]# tar -xf nginx-1.12.2.tar.gz
[root@web1 ~]# cd nginx-1.12.2
[root@web1 nginx-1.12.2]# ./configure \
> --with-http_ssl_module
[root@web1 nginx-1.12.2]# make && make install
- 1
- 2
- 3
- 4
- 5
3)安装MariaDB数据库
[root@web1 ~]# yum -y install mariadb mariadb-server mariadb-devel
- 1
4)安装PHP
[root@web1 ~]# yum -y install php php-mysql
[root@web1 ~]# yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
- 1
- 2
5)修改Nginx配置文件(修改默认首页与动静分离)
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
步骤二:启动LNMP服务器相关的服务
1)启动Nginx服务
这里需要注意的是,如果服务器上已经启动了其他监听80端口的服务软件(如httpd),则需要先关闭该服务,否则会出现冲突。
[root@web1 ~]# systemctl stop httpd //如果该服务存在,则关闭该服务
[root@web1 ~]# /usr/local/nginx/sbin/nginx
[root@web1 ~]# netstat -utnlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:*