; keepalived+lvs负载均衡两个httpd | Linux运维部落

keepalived+lvs负载均衡两个httpd

准备4台主机

1
172.16.71.2

 

1
172.16.71.3

 

1
172.16.71.4

 

1
172.16.71.5

前两个做后端httpd服务器。后两个做keepalived


首先配置好后端主机

1
172.16.71.2

 和

1
172.16.71.3


1
# 172.16.71.2<br />yum install httpd<br />cd /var/www/html<br />vim index.html<br />server1 71.2<br />

1
# 172.16.71.3<br />yum install httpd<br />cd /var/www/html<br />vim index.html<br />server2 71.3<br />

由于lvs采用的是DR模式,所以要写脚本修改内核参数并添加路由信息,以下是keepalived双主需要的脚本,两台主机上都需要运行一次:


1
#!/bin/bash<br />#<br />vip=172.16.71.80<br />vip2=172.16.71.90<br />mask=&#039;255.255.255.255&#039;<br />interface=&#039;lo:0&#039;<br />interface2=&#039;lo:1&#039;<br /><br />case $1 in<br />start)<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 1 &gt; /proc/sys/net/ipv4/conf/all/arp_ignore<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 1 &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 2 &gt; /proc/sys/net/ipv4/conf/all/arp_announce<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 2 &gt; /proc/sys/net/ipv4/conf/lo/arp_announce<br /> &nbsp; &nbsp; &nbsp; &nbsp;ifconfig $interface &nbsp;$vip netmask $mask broadcast $vip up<br /> &nbsp; &nbsp; &nbsp; &nbsp;ifconfig $interface2 &nbsp;$vip2 netmask $mask broadcast $vip2 up<br /> &nbsp; &nbsp; &nbsp; &nbsp;route add -host $vip dev $interface<br /> &nbsp; &nbsp; &nbsp; &nbsp;route add -host $vip2 dev $interface2<br /> &nbsp; &nbsp; &nbsp; &nbsp;;;<br />stop)<br /> &nbsp; &nbsp; &nbsp; &nbsp;ifconfig $interface down<br /> &nbsp; &nbsp; &nbsp; &nbsp;ifconfig $interface2 down<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 0 &gt; /proc/sys/net/ipv4/conf/all/arp_ignore<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 0 &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 0 &gt; /proc/sys/net/ipv4/conf/all/arp_announce<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo 0 &gt; /proc/sys/net/ipv4/conf/lo/arp_announce<br /> &nbsp; &nbsp; &nbsp; &nbsp;;;<br />*)<br /> &nbsp; &nbsp; &nbsp; &nbsp;echo &quot;Usage $(basename $0) start|stop&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;exit 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;;;<br />esac<br />

执行完成后启动httpd

1
systemctl start httpd


然后配置前端的keepalived,这里采用的是双主模式。

配置文件如下:


1
# 172.16.71.4<br /><br />! Configuration File for keepalived<br /><br />global_defs {<br /> &nbsp; notification_email {<br /> &nbsp; &nbsp;root@localhost<br /> &nbsp; } &nbsp; <br /><br /> &nbsp; notification_email_from kaadmin@localhost <br /> &nbsp; smtp_server 127.0.0.1<br /> &nbsp; smtp_connect_timeout 30<br /> &nbsp; router_id node1<br /> &nbsp; vrrp_mcast_group4 224.0.71.1<br />}<br /><br />vrrp_instance VI_1 {<br /> &nbsp; &nbsp;state MASTER<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 71<br /> &nbsp; &nbsp;priority 100 <br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass bashrc<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.80/16 dev eno16777736 label eno16777736:0<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br />vrrp_instance VI_2 {<br /> &nbsp; &nbsp;state BACKUP<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 45<br /> &nbsp; &nbsp;priority 98<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass shell<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.90/16 dev eno16777736 label eno16777736:1<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br /><br />virtual_server fwmark 3 {<br /> &nbsp; &nbsp;delay_loop 2<br /> &nbsp; &nbsp;lb_algo rr<br /> &nbsp; &nbsp;lb_kind DR<br /> &nbsp; &nbsp;nat_mask 255.255.0.0<br /> &nbsp; &nbsp;protocol TCP<br /><br /> &nbsp; &nbsp;sorry_server 127.0.0.1 80<br /><br /> &nbsp; &nbsp;real_server 172.16.71.2 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br /><br /> &nbsp; &nbsp;real_server 172.16.71.3 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br />}<br />

1
# 172.16.71.5<br /><br />! Configuration File for keepalived<br /><br />global_defs {<br /> &nbsp; notification_email {<br /> &nbsp; &nbsp;root@localhost<br /> &nbsp; } &nbsp; <br /><br /> &nbsp; notification_email_from kaadmin@localhost <br /> &nbsp; smtp_server 127.0.0.1<br /> &nbsp; smtp_connect_timeout 30<br /> &nbsp; router_id node2<br /> &nbsp; vrrp_mcast_group4 224.0.71.1<br />}<br /><br />vrrp_instance VI_1 {<br /> &nbsp; &nbsp;state BACKUP<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 71<br /> &nbsp; &nbsp;priority 98<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass bashrc<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.80/16 dev eno16777736 label eno16777736:0<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br /><br /><br />}<br />vrrp_instance VI_2 {<br /> &nbsp; &nbsp;state MASTER<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 45<br /> &nbsp; &nbsp;priority 100<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass shell<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.90/16 dev eno16777736 label eno16777736:1<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br /><br /><br />virtual_server fwmark 3 {<br /> &nbsp; &nbsp;delay_loop 2<br /> &nbsp; &nbsp;lb_algo rr<br /> &nbsp; &nbsp;lb_kind DR<br /> &nbsp; &nbsp;nat_mask 255.255.0.0<br /> &nbsp; &nbsp;protocol TCP<br /><br /> &nbsp; &nbsp;sorry_server 127.0.0.1 80<br /><br /> &nbsp; &nbsp;real_server 172.16.71.2 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br /><br /> &nbsp; &nbsp;real_server 172.16.71.3 80 &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br />}<br /><br />

1
# 告警脚本<br /><br />#!/bin/bash<br />#<br />contact=&#039;root@localhost&#039;<br />notify() {<br /> &nbsp; &nbsp;mailsubject=&quot;$(hostname) to be $1, vip floating&quot;<br /> &nbsp; &nbsp;mailbody=&quot;$(date +&#039;%F %T&#039;): vrrp transition, $(hostname) changed to be $1&quot;<br /> &nbsp; &nbsp;echo &quot;$mailbody&quot; | mail -s &quot;$mailsubject&quot; $contact<br />}<br />case $1 in<br />master)<br /> &nbsp; &nbsp;notify master<br /> &nbsp; &nbsp;;;<br />backup)<br /> &nbsp; &nbsp;notify backup<br /> &nbsp; &nbsp;;;<br />fault)<br /> &nbsp; &nbsp;notify fault<br /> &nbsp; &nbsp;;;<br />*)<br /> &nbsp; &nbsp;echo &quot;Usage: $(basename $0) {master|backup|fault}&quot;<br /> &nbsp; &nbsp;exit 1<br /> &nbsp; &nbsp;;;<br />esac &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />

在两个主机上添加iptables


1
iptables -t mangle -A PREROUTING -d 172.16.71.80 -p tcp --dport 80 -j MARK --set-mark 3<br />iptables -t mangle -A PREROUTING -d 172.16.71.90 -p tcp --dport 80 -j MARK --set-mark 3<br />

在两台主机上安装httpd并添加sorry page,启动httpd和keepalived


1
# 172.16.71.4<br />yum install httpd<br />cd /var/www/html<br />vim index.html<br />sorry page 1<br />systemctl start httpd keepalived<br />

1
# 172.16.71.5<br />yum install httpd<br />cd /var/www/html<br />vim index.html<br />sorry page 2<br />systemctl start httpd keepalived<br />

测试

访问

1
172.16.71.80

或者

1
172.16.71.90

时,会显示

1
server1 71.2

 或

1
server2 71.3

页面。

断掉后端两个httpd服务器,再次访问会显示

1
sorry page 1

或者

1
sorry page 2

断掉不同的keepalived会显示不同的sorry page


下面是keepalived单主模式的配置:


1
# /etc/keepalived/keepalived.conf<br /><br /># 172.16.71.4<br /><br />! Configuration File for keepalived<br /><br />global_defs {<br /> &nbsp; notification_email {<br /> &nbsp; &nbsp;root@localhost<br /> &nbsp; } &nbsp; <br /><br /> &nbsp; notification_email_from kaadmin@localhost <br /> &nbsp; smtp_server 127.0.0.1<br /> &nbsp; smtp_connect_timeout 30<br /> &nbsp; router_id node1<br /> &nbsp; vrrp_mcast_group4 224.0.71.1<br />}<br /><br />vrrp_instance VI_1 {<br /> &nbsp; &nbsp;state MASTER<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 71<br /> &nbsp; &nbsp;priority 100 <br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass bashrc<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.80/16 dev eno16777736 label eno16777736:0<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br />vrrp_instance VI_2 { # 这段可以注释掉,不用。<br /> &nbsp; &nbsp;state BACKUP<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 45<br /> &nbsp; &nbsp;priority 98<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass shell<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.90/16 dev eno16777736 label eno16777736:1<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br /><br />virtual_server 172.16.71.80 80 {<br /> &nbsp; &nbsp;delay_loop 2<br /> &nbsp; &nbsp;lb_algo rr<br /> &nbsp; &nbsp;lb_kind DR<br /> &nbsp; &nbsp;nat_mask 255.255.0.0<br /> &nbsp; &nbsp;protocol TCP<br /><br /> &nbsp; &nbsp;sorry_server 127.0.0.1 80<br /><br /> &nbsp; &nbsp;real_server 172.16.71.2 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br /><br /> &nbsp; &nbsp;real_server 172.16.71.3 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br />}<br /><br />

1
# /etc/keepalived/keepalived.conf<br /><br /># 172.16.71.5<br /><br />! Configuration File for keepalived<br /><br />global_defs {<br /> &nbsp; notification_email {<br /> &nbsp; &nbsp;root@localhost<br /> &nbsp; } &nbsp; <br /><br /> &nbsp; notification_email_from kaadmin@localhost <br /> &nbsp; smtp_server 127.0.0.1<br /> &nbsp; smtp_connect_timeout 30<br /> &nbsp; router_id node2<br /> &nbsp; vrrp_mcast_group4 224.0.71.1<br />}<br /><br />vrrp_instance VI_1 {<br /> &nbsp; &nbsp;state BACKUP<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 71<br /> &nbsp; &nbsp;priority 98<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass bashrc<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.80/16 dev eno16777736 label eno16777736:0<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;} &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br /><br /><br />}<br />vrrp_instance VI_2 { # 这段可以注释掉,不用。<br /> &nbsp; &nbsp;state MASTER<br /> &nbsp; &nbsp;interface eno16777736<br /> &nbsp; &nbsp;virtual_router_id 45<br /> &nbsp; &nbsp;priority 100<br /> &nbsp; &nbsp;advert_int 1<br /> &nbsp; &nbsp;authentication {<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_type PASS<br /> &nbsp; &nbsp; &nbsp; &nbsp;auth_pass shell<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;virtual_ipaddress {<br /> &nbsp; &nbsp; &nbsp; &nbsp;172.16.71.90/16 dev eno16777736 label eno16777736:1<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp;track_interface {<br /> &nbsp; &nbsp; &nbsp; &nbsp;eno16777736<br /> &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_master &quot;/etc/keepalived/notify.sh master&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_backup &quot;/etc/keepalived/notify.sh backup&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;notify_fault &quot;/etc/keepalived/notify.sh fault&quot;<br />}<br /><br /><br />virtual_server 172.16.71.80 80 {<br /> &nbsp; &nbsp;delay_loop 2<br /> &nbsp; &nbsp;lb_algo rr<br /> &nbsp; &nbsp;lb_kind DR<br /> &nbsp; &nbsp;nat_mask 255.255.0.0<br /> &nbsp; &nbsp;protocol TCP<br /><br /> &nbsp; &nbsp;sorry_server 127.0.0.1 80<br /><br /> &nbsp; &nbsp;real_server 172.16.71.2 80 {<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br /><br /> &nbsp; &nbsp;real_server 172.16.71.3 80 &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp;weight 1<br /> &nbsp; &nbsp; &nbsp; &nbsp;HTTP_GET {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;url {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path /<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status_code 200<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;connect_timeout 2<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nb_get_retry 3<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_before_retry 2<br /> &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp;}<br />}<br /><br />

单主模式不需要手动添加iptables。


原创文章,作者:wangshuai,如若转载,请注明出处:/68329

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1660809109@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班

友情链接:万达娱乐开户  万达娱乐直属  万达招商  万达注册  万达直属QQ  万达娱乐主管QQ  万达招商QQ  万达直属QQ  万达娱乐登录  万达娱乐招商QQ