1.LVS-DR 集群
部署环境:
localhost | 客户机 | 192.168.100.122 |
node1 | lvs | 192.168.100.123 |
node2 | rs | 192.168.100.124 |
node3 | rs | 192.168.100.125 |
配置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的VIP :
[root@node1 ~]# ifconfig ens33:200 192.168.100.200 netmask 255.255.255.0 up
测试httpd
[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.124
web test page,ip is 192.168.100.124[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.125
web test page,ip is 192.168.100.125
在RS端绑定VIP :
[root@node2 ~]# ifconfig lo:200 192.168.100.200 netmask 255.255.255.255 up
[root@node3 ~]# 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响应 :
调整内核参数
[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
配置添加LVS服务并增加两台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.124:80 -g
[root@node1 ~]# ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.125:80 -g
ipvs查看配置状态 :
[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.124:80 Route 1 0 0
-> 172.168.100.125:80 Route 1 0 0
客户机检测配置 :
[root@localhost ~]# for ((i=1;i<=4;i++)); do curl 192.168.100.200; done
web test page,ip is 192.168.100.124
web test page,ip is 192.168.100.125
web test page,ip is 192.168.100.124
web test page,ip is 192.168.100.125
2.配置nginx负载均衡
localhost | 192.168.100.126 | 负载均衡服务器 |
node1 | 192.168.100.127 | nginx服务器 |
node2 | 192.168.100.128 | nginx服务器 |
启动服务并向主机 node1 node2 写入内容:
[root@localhost ~]#systenctl start nginx
[root@localhost ~]#echo "web test page ip is `hostname -I`" >/usr/share/nginx/html/index.html
[root@localhost ~]#systenctl start nginx
在localhost负载均衡服务器上配置 :
vim /etc/nginx/nginx.conf
server {
listen 80;
server_name test.ng.test;
location / {
proxy_pass http://web_server;
}
}
upstream web_server {
server 192.168.100.127:80;
server 192.168.100.128:80;}
测试nginx负载均衡:
[root@localhost ~]# for ((i=1;i<=4;i++)); do curl 192.168.100.126; done
web test page,ip is 192.168.100.127
web test page,ip is 192.168.100.128
web test page,ip is 192.168.100.127
web test page,ip is 192.168.100.128