调度器高可用集群拓扑
拓扑图 IP规划主机haproxy98做如下配置
[root@haproxy98 ~]# yum -y install haproxy
[root@haproxy98 ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy98 ~]# systemctl start haproxy
[root@haproxy98 ~]# systemctl enable haproxy
[root@haproxy98 ~]# ps -C haproxy
[root@haproxy98 ~]# ss -antulp | grep haproxy
MySQL [(none)]> select @@hostname;
查询结果MySQL [(none)]> select @@hostname;
查询结果多次连接访问显示不同的主机名
在主机haproxy99/98分别安装软件keepalived
[root@haproxy99 ~]# yum -y install keepalived
[root@haproxy98 ~]# yum -y install keepalived
修改主haproxy99 的 /etc/keepalived/keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_fromAlexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_iptables
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.100
}
}
修改haproxy98的/etc/keepalived/keepalived.conf
[root@haproxy98 ~]# vim
/etc/keepalived/keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_fromAlexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_iptables
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.100
}
}
在两台主机上分别启动keepalived服务
启动主的keepalived服务
[root@haproxy99 ~]# systemctl start keepalived
[root@haproxy99 ~]# systemctl enable keepalived
[root@haproxy99 ~]# systemctl status keepalived
启动备的keepalived服务
[root@haproxy98 ~]# systemctl start keepalived.service
[root@haproxy98 ~]# systemctl enable keepalived.service
[root@haproxy98 ~]# systemctl status keepalived
在客户端连接vip地址访问数据
[root@client ~]# mysql -h 192.168.4.100 -uyaya99 -p123qqq...A
连接vip地址
MySQL [(none)]> select @@hostname;
[root@client ~]# ping 192.168.4.100 查看vip地址能不能ping通
[root@haproxy99 ~]# ip addr show | grep 192.168.4.100
inet 192.168.4.100/32 scopeglobal eth0
[root@haproxy98 ~]# ip addr show | grep 192.168.4.100 //查找不到
在haproxy99上关闭keepalived服务,查看vip会不会转移到haproxy98上去,测试高可用
[root@haproxy99 ~]# systemctl stop keepalived
[root@haproxy98 ~]# ip addr show | grep 192.168.4.100
inet 192.168.4.100/32 scopeglobal eth0
Vip地址转移到了haproxy98上
重启服务,查看vip地址是否回到优先级高的haproxy99
[root@haproxy99 ~]# systemctl start keepalived
[root@haproxy99 ~]# ip addr show | grep 192.168.4.100
inet 192.168.4.100/32 scopeglobal eth0
网友评论