前提
有mycat + HAProxy
- mycat安装地址 : https://blog.csdn.net/getchar97/article/details/105224303
- HAProxy安装地址: https://blog.csdn.net/getchar97/article/details/105244238
一 : 安装 Keepalived
1、准备好Keepalived安装包,传到/opt目录下
下载地址: https://mirrors.huaweicloud.com/keepalived/
2、解压到/usr/local/src
tar -zxvf keepalived-1.4.2.tar.gz -C /usr/local/src
3、安装依赖插件
yum install -y gcc openssl-devel popt-devel
4、进入解压后的目录,进行配置,进行编译
cd /usr/local/src/keepalived-1.4.2
./configure --prefix=/usr/local/keepalived
5、进行编译,完成后进行安装
make && make install
6、运行前配置
cp /usr/local/src/keepalived-1.4.2/keepalived/etc/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/src/keepalived-1.4.2/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
7、修改配置文件
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
xlcocoon@foxmail.com
}
notification_email_from keepalived@showjoy.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
#主机配MASTER,备机配BACKUP
state MASTER
#所在机器网卡 ifconfig 查看
interface ens33
virtual_router_id 51
#数值越大优先级越高
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
#虚拟 IP
66.88.88.200
}
}
virtual_server 66.88.88.200 48066 { # 通过此ip+端口 可访问到真实的 端口地址
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 66.88.88.170 48066 { # 真实物理机位置 使用的端口是 HAPorxy的端口
weight 1 # 权重
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 66.88.88.172 48600 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
二 : 启动验证
1、启动Keepalived
service keepalived start
2、登录验证
mysql -umycat -p123456 -h 66.88.88.200 -P 48066