3.1 問題
通過Nginx排程器負載後端兩台Web伺服器,實作以下目标:
- 部署Nginx為前台排程伺服器
- 排程算法設定為輪詢
- 後端為兩台LNMP伺服器
- 部署測試頁面,檢視PHP本地的Session資訊
3.2 方案
使用4台RHEL7虛拟機,其中一台作為Nginx前端排程器伺服器(eth0:192.168.4.5,eth1:192.168.2.5)、兩台虛拟機部署為LNMP伺服器,分别為Web1伺服器(192.168.2.100)和Web2伺服器(192.168.2.200),另外一台作為測試用的Linux客戶機(192.168.4.100),拓撲如圖-2所示。

步驟一:部署後端LNMP伺服器相關軟體
步驟二:啟動LNMP伺服器相關的服務
步驟三:部署前端Nginx排程伺服器
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
35 upstream webs {
36 server 192.168.2.100:80;
37 server 192.168.2.200:80;
38 }
47 location / {
48 proxy_pass http://webs;
49 root html;
50 index index.php index.html index.htm;
51 }
:wq
開啟後端伺服器:
[[email protected] ~]# systemctl restart httpd
[[email protected] ~]# systemctl restart httpd
步驟四:測試環境是否配置成功
1)浏覽器通路測試頁面驗證。
[[email protected] ~]# firefox http://192.168.4.5/test.php
[[email protected] ~]# curl http://192.168.4.5/index.html
192.168.2.100
[[email protected] ~]# curl http://192.168.4.5/index.html
192.168.2.200
[[email protected] ~]# curl http://192.168.4.5/index.html
192.168.2.100