构建 LVS-DR 集群 && 配置nginx负载均衡

1.LVS-DR 集群

部署环境:

localhost客户机192.168.100.122
node1lvs192.168.100.123
node2rs192.168.100.124
node3rs192.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负载均衡 

localhost192.168.100.126负载均衡服务器
node1192.168.100.127nginx服务器
node2192.168.100.128nginx服务器

启动服务并向主机 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值