haproxy高可用以及双主模式(二)
haproxy主备虚拟VIP:192.168.33.130
把haproxy-01的配置文件拷贝到haproxy-02机器相应的目录即可
root@haproxy-01 haproxy]# scp haproxy.cfg root@192.168.33.132:/etc/haproxy/
haproxy.cfg 100% 3520 3.4KB/s 00:00启动haproxy-02服务
# /etc/init.d/haproxy restart
Stopping haproxy:
Starting haproxy: 关于haproxy-02日志记录和haproxy-01记录方式一样
客户端访问haproxy-02的ip地址
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s5.运维网.com/wyfs02/M01/83/A3/wKioL1d5NvqCEg88AAAnM2xXe6s577.jpg-wh_500x0-wm_3-wmp_4-s_3957978024.jpghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
安装keepalived
在haproxy机器上分别安装keepalived
# yum install keepalived -y
# yum install keepalived -yhaproxy-01机器上keepalived配置文件内容如下
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
19872672@qq.com
}
notification_email_from root@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_MASTER
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.130
}
}haproxy-02机器上keepalived配置文件内容如下
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
19872672@qq.com
}
notification_email_from root@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_BACKUP
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.130
}
}
分别在haproxy-01/02机器启动keepalived服务
# /etc/init.d/keepalived start
Starting keepalived:
# /etc/init.d/keepalived start
Starting keepalived:
haproxy-01情况
# ip a|grep 130
inet 192.168.33.130/32 scope global eth0haproxy-02情况
# ip a|grep 130通过以上查看情况得知虚拟VIP在haproxy-01机器上
客户端访问虚拟VIP情况
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s2.运维网.com/wyfs02/M01/83/A4/wKiom1d5N1ezZsqVAAAlx2jGBRc788.jpg-wh_500x0-wm_3-wmp_4-s_470639997.jpghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
通过访问得知,虚拟vip访问正常。轮询访问
模拟故障把haproxy-01机上的haproxy和keepalived服务停止
# /etc/init.d/haproxy stop
Stopping haproxy:
# /etc/init.d/keepalived stop
Stopping keepalived: 在haproxy-02机器上查看虚拟VIP情况
# ip a|grep 130
inet 192.168.33.130/32 scope global eth0虚拟VIP已经漂移到haproxy-02机器上了
客户端访问虚拟VIP情况
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s2.运维网.com/wyfs02/M02/83/A4/wKiom1d5N37Ctyu7AAAld_LdRJw695.jpg-wh_500x0-wm_3-wmp_4-s_773572376.jpghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
haproxy-01机器查看keepalived剔除过程日志
http://s4.运维网.com/wyfs02/M00/83/A3/wKioL1d5N6qzk76MAADSwsh_GO8498.jpg-wh_500x0-wm_3-wmp_4-s_557435318.jpg
haproxy-02机器查看keepalived切换获取VIP过程日志
http://s4.运维网.com/wyfs02/M02/83/A3/wKioL1d5N9LiC5EtAACtHTrIN6s362.jpg-wh_500x0-wm_3-wmp_4-s_1284515609.jpg
以上就是haproxy+keepalived主备模式
haproxy+keepalived双主模式
增加虚拟VIP:192.168.33.150
haproxy-01机器虚拟VIP:192.168.33.130
haproxy-02机器虚拟VIP:192.168.33.150haproxy-01机器上keepalived完整配置文件如下
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
1987672@qq.com
}
notification_email_from root@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_MASTER
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.130
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.150
}
}haproxy-02器上keepalived完整配置文件如下
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
1987672@qq.com
}
notification_email_from root@localhost.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_BACKUP
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.130
}
}
vrrp_instance VI_2 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.33.150
}
}分别启动haproxy-01/02机器的haproxy和keepalived服务即可
haproxy-01机器情况如下
# /etc/init.d/haproxy start
Starting haproxy:
# /etc/init.d/keepalived start
Starting keepalived: haproxy-02机器情况如下
# /etc/init.d/haproxy restart
Stopping haproxy:
Starting haproxy:
# /etc/init.d/keepalived restart
Stopping keepalived:
Starting keepalived: 查看haproxy-01机器虚拟VIP情况
# ip a|grep 130
inet 192.168.33.130/32 scope global eth0查看haproxy-02机器虚拟VIP情况
# ip a|grep 33.150
inet 192.168.33.150/32 scope global eth0客户端访问虚拟VIP情况如下
虚拟VIP:130访问情况
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M01/83/A3/wKioL1d5OFTj47VuAAAjPwZY8No125.jpg-wh_500x0-wm_3-wmp_4-s_2506956771.jpg
虚拟VIP:150访问情况
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s5.运维网.com/wyfs02/M01/83/A4/wKiom1d5OF7BpjvpAAAit8lyeho127.jpg-wh_500x0-wm_3-wmp_4-s_2168312603.jpghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
模拟故障,吧haproxy-01机器haproxy和keepalived服务down掉
# /etc/init.d/haproxy stop
Stopping haproxy:
# /etc/init.d/keepalived stop
Stopping keepalived: 查看haproxy-01机器虚拟VIP情况
# ip a|grep 130查看haproxy-01机器日志情况
http://s4.运维网.com/wyfs02/M02/83/A4/wKiom1d5OJnAJZ9iAADMW43o_Vg696.jpg-wh_500x0-wm_3-wmp_4-s_1562037230.jpg
从上面日志中看出虚拟VIP:192.168.33.130已经剔除了
查看haproxy-02机器虚拟VIP情况
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s1.运维网.com/wyfs02/M02/83/A3/wKioL1d5OMSBT9PKAADAGludZ1U462.jpg-wh_500x0-wm_3-wmp_4-s_1652438826.jpg虚拟VIP已经漂移在haproxy-02机器上
查看haproxy-02机器上的日志
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s2.运维网.com/wyfs02/M02/83/A4/wKiom1d5OMzy5LUqAAC6aZ4cuWA674.jpg-wh_500x0-wm_3-wmp_4-s_1529352939.jpg
客户端浏览器访问情况如下
虚拟VIP130
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://s1.运维网.com/wyfs02/M00/83/A3/wKioL1d5OPKi2dn9AAAlK6jUhMI188.jpg-wh_500x0-wm_3-wmp_4-s_2423918968.jpg
虚拟VIP150
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif http://s1.运维网.com/wyfs02/M00/83/A4/wKiom1d5OPzxOZSBAAAkLXSGu58081.jpg-wh_500x0-wm_3-wmp_4-s_1840538886.jpghttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
以上就haproxy+keepalived双主模式,先这样吧
页:
[1]