產(chǎn)品型號:Thinkpad E15
系統(tǒng)版本:centos8
安裝nginx服務(wù)
[root@xuegod63 ~]# yum install -y epel-release
[root@xuegod63 ~]# yum install -y nginx
[root@xuegod63 ~]# vim /etc/nginx/nginx.conf
在server字段外添加配置
upstream htmlservers {
server 192.168.1.62:80;
server 192.168.1.64:80;
}
如圖中所示位置:
添加反向代理,將訪問192.168.1.63的數(shù)據(jù),轉(zhuǎn)到另外兩臺服務(wù)器上
改:
51 location / {
52 }
為:
location / {
proxy_pass http://htmlservers;
}
檢查語法
[root@xuegod63 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
配置xuegod62和xuegod64節(jié)點
[root@xuegod62 ~]# yum install -y httpd
[root@xuegod62 ~]# echo "192.168.1.62" > /var/www/html/index.html
[root@xuegod62 ~]# systemctl start httpd
[root@xuegod64 ~]# yum install -y httpd
[root@xuegod64 ~]# echo "192.168.1.64" > /var/www/html/index.html
[root@xuegod64 ~]# systemctl start httpd
訪問web服務(wù):http://192.168.1.63/
刷新頁面即可看到主機(jī)頁面。
總結(jié):
1. 安裝nginx服務(wù)
2. 配置nginx負(fù)載均衡
3. 啟動服務(wù)器
4. 通過訪問web服務(wù)進(jìn)行測試負(fù)載均衡效果