環(huán)境配置:
RHCE | 客戶機(jī) | 192.168.100.146 |
node1 | lvs | 192.168.100.145 |
node2 | RS | 192.168.100.147 |
node3 | RS | 192.168.100.148 |
?配置ipvsadm? httpd:
[root@node1 ~]# yum install ipvsadm.x86_64
[root@node2 ~]# yum install http -y????????
[root@node2?~]# systemctl start httpd
[root@node3?~]# yum install http -y
[root@node3 ~]# systemctl start httpd
配置LVS虛擬IP(VIP)
[root@node1 ~]# ifconfig ens33:200 192.168.100.200 netmask 255.255.255.0 up
將內(nèi)容寫入/var/www/html 測(cè)試httpd
[root@node3 ~]# echo "web test page,ip is `hostname -I`" > /var/www/html/index.html
[root@node3 ~]# systemctl start httpd
[root@node3 ~]# curl 192.168.100.148
web test page,ip is 192.168.100.148?[root@node2 ~]# echo "web test page,ip is `hostname -I`" > /var/www/html/index.html
[root@node2 ~]# systemctl start httpd
[root@node2 ~]# curl 192.168.100.147
web test page,ip is 192.168.100.147?
?手工在RS端綁定VIP
[root@node3 ~]# ifconfig lo:200 192.168.100.200 netmask 255.255.255.255 up
[root@node2?~]# ifconfig lo:200 192.168.100.200 netmask 255.255.255.255 up
?添加RS訪問VIP路由
[root@node2?~]# route add -host 192.168.100.200 dev lo
[root@node3 ~]# route add -host 192.168.100.200 dev lo
?手工在RS端一直ARP響應(yīng)
調(diào)整內(nèi)核參數(shù)
[root@node3 all]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node3 all]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@node3 conf]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node3 conf]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
?[root@node3 ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node3 ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
[root@node3 ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node3 ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
arp_ignore- INTEGER
?手工執(zhí)行配置添加LVS服務(wù)并增加兩臺(tái)RS
[root@node1 ~]# ipvsadm -A -t 192.168.100.200:80 -s rr?
[root@node1 ~]# ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.147:80? -g
[root@node1 ~]# ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.148:80? -g
?ipvs查看配置狀態(tài)
[root@node1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
? -> RemoteAddress:Port ? ? ? ? ? Forward Weight ActiveConn InActConn
TCP ?192.168.100.200:80 rr
? -> 172.168.100.147:80 ? ? ? ? ? Route ? 1 ? ? ?0 ? ? ? ? ?0 ? ? ? ??
? -> 172.168.100.148:80 ? ? ? ? ? Route ? 1 ? ? ?0 ? ? ? ? ?0?
?客戶機(jī)檢測(cè)配置
[root@RHCE ~]# for ((i=1;i<=6;i++)); do curl 192.168.100.200; done
web test page,ip is 192.168.100.147
web test page,ip is 192.168.100.148
web test page,ip is 192.168.100.147
web test page,ip is 192.168.100.148
web test page,ip is 192.168.100.147
web test page,ip is 192.168.100.148
使用nginx配置負(fù)載均衡
RHCE | 192.168.100.146 | 負(fù)載均衡服務(wù)器 |
node2 | 192.168.100.148 | nginx服務(wù)器 |
node3 | 192.168.100.149 | nginx服務(wù)器 |
?安裝nginx可以使用如下倉(cāng)庫(kù):
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
?關(guān)閉防火墻 以及SELinux寬容模式
systemctl? stop? ?firewalld?
setenforce? ?0
啟動(dòng)服務(wù)并向主機(jī) node2 node3 寫入內(nèi)容? ? ? ?
systenctl start nginx? 啟動(dòng)nginx服務(wù)
echo "web test page ip is `hostname -I`" > /usr/share/nginx/html/index.html #寫入內(nèi)容
systenctl start nginx? 再次啟動(dòng)nginx服務(wù)
?在RHCE負(fù)載均衡服務(wù)器上配置
vim /etc/nginx/nginx.conf
#在 http模塊中寫入如下內(nèi)容
server {
listen 80;
server_name test.ng.test; 定義域名 也可以用ip
location / {
proxy_pass http://web_server;
}
}
upstream web_server {
server 192.168.100.148:80; nginx服務(wù)器地址
server 192.168.100.149:80;
}
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-648748.html
?測(cè)試結(jié)果:
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-648748.html
到了這里,關(guān)于基于 CentOS 7 構(gòu)建 LVS-DR 群集 && 配置nginx負(fù)載均衡的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!