HA1:192.168.152.140
HA2:192.168.152.143
RS1:192.168.152.141
RS2:192.168.152.142
VIP:192.168.152.190
配置HA1
vim /etc/keepalived/keepalived.conf
global_defs { notification_email { root@localhost } #设置通知邮件地址 notification_email_from Alexandre.Cassen@firewall.loc #设置发件人地址 smtp_server 127.0.0.1 #设置邮件服务器IP smtp_connect_timeout 30 #超时时长 router_id LVS_DEVEL #辨识主机字符串 vrrp_mcast_group4 224.0.0.18 #vrrp的IPV4组播地址,同一域内组播地址一致 vrrp_instance VI_1 { state MASTER interface eno16777736 virtual_router_id 51 #虚拟路由器ID号保持一直(0-255) priority 150 #优先级,越高约优先 advert_int 1 #通告时间间隔 authentication { auth_type PASS #认证方式,还可用AH认证 auth_pass 1111 #最长为8位,可用opssl rand -base64 8生成 } virtual_ipaddress { 192.168.152.190 #虚拟IP,此设置用ip addr list可以查看获取的虚拟ip,如想用ifconfig看到虚拟地址可配置为:192.168.152.190 dev eno16777736 label eno16777736:0即可 } }
HA2
vrrp_instance VI_1 { state BACKUP interface eno16777736 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.152.190 } }
可在vrrp_instance中使用notify_master,notify_backup,notify_fault调用脚本发送通知邮件
亦可跟踪服务实现高可用,主备均配置,注意修改优先级,使主优先级减权重后小于备的优先级
vim /etc/keepalived/keepalived.conf
vrrp_script chk_nginx { script "killall -0 nginx" interval 2 weight -60 } vrrp_instance VI_1 { track_script { chk_nginx } }
HA1
vim /etc/keepalived/keepalived.conf
global_defs { notification_email { root@localhost } notification_email_from admin@test.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id ha1 vrrp_mcast_group4 224.0.0.18 } vrrp_instance VI_1 { #配置高可用 state MASTER interface eno16777736 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1G9Kiv8A } virtual_ipaddress { 192.168.152.190 dev eno16777736 label eno16777736:0 } virtual_server 192.168.152.190 80 { #配置负责均衡,模型为LVS-DR delay_loop 6 lb_algo wrr lb_kind DR protocol TCP sorry_server 127.0.0.1 80 #定义sorry-server,即后端主机挂掉,返回给客户端页面 real_server 192.168.152.141 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.152.142 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
HA2配置类似,virtual-instance改为BACKUP,优先级降低即可
RS1,RS2配置见LVS-DR的RS1,RS2配置http://edonkey.blog.51cto.com/887243/1772290
HA1为VIP:192.168.152.190主,192.168.152.191备
HA2为VIP:192.168.152.191备,192.168.152.190主
HA1
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { #配置HA1为190主 state MASTER interface eno16777736 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1G9Kiv8A } virtual_ipaddress { 192.168.152.190 dev eno16777736 label eno16777736:0 } } vrrp_instance VI_2 { #配置HA1为191备 state BACKUP interface eno16777736 virtual_router_id 151 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1G9Kiv8 } virtual_ipaddress { 192.168.152.191 dev eno16777736 label eno16777736:1 } }
HA2
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { state BACKUP interface eno16777736 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1G9Kiv8A } virtual_ipaddress { 192.168.152.190 dev eno16777736 label eno16777736:0 } } vrrp_instance VI_2 { state MASKTER interface eno16777736 virtual_router_id 151 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1G9Kiv8 } virtual_ipaddress { 192.168.152.191 dev eno16777736 label eno16777736:1 } }
本文出自 “liberalism” 博客,请务必保留此出处http://edonkey.blog.51cto.com/887243/1772291
原文地址:http://edonkey.blog.51cto.com/887243/1772291