keepalived安装配置

一、安装软件
yum list keepalived*
yum install keepalived.x86_64

二、配置keepalived.
修改“/etc/keepalived/keepalived.conf”目录下主、备两个节点配置文件(两台服务器)。
sudo vi /etc/keepalived/keepalived.conf

(一)、同一网段、keepalived服务中断后切换
主节点参考如下进行配置:
[root@ha80 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.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_instance VI_2 {
state MASTER
interface team0
virtual_router_id 83
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.10.10.53
}
}

备节点参考如下进行配置:
[root@ha81 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.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_instance VI_2 {
state BACKUP
interface team0
virtual_router_id 83
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.10.10.53
}
}

/

(二)、同一网段、条件切换
主节点参考如下进行配置:cat /etc/keepalived/keepalived.conf
global_defs {
router_id master01
}

vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass mysql236
}
virtual_ipaddress {
10.10.10.18
}
}

virtual_server 10.10.10.18 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 10.10.10.16 3306 {
weight 1
notify_down /etc/keepalived/bin/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}

备节点参考如下进行配置:cat /etc/keepalived/keepalived.conf
global_defs {
router_id master02
}

vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
nopreempt
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass mysql236
}
virtual_ipaddress {
10.10.10.18
}
}

virtual_server 10.10.10.18 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 10.10.10.17 3306 {
weight 1
notify_down /etc/keepalived/bin/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}

(三)、不同网段、条件切换
主节点参考如下进行配置:cat /etc/keepalived/keepalived.conf
global_defs {
router_id master01
}

vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass mysql236
}
virtual_ipaddress {
10.10.10.18
}
}

virtual_server 10.10.10.18 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 10.10.103.16 3306 {
weight 1
notify_down /etc/keepalived/bin/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}

备节点参考如下进行配置:cat /etc/keepalived/keepalived.conf
global_defs {
router_id master02
}

vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
nopreempt
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass mysql236
}
virtual_ipaddress {
10.10.10.18
}
}

virtual_server 10.10.10.18 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 10.10.103.17 3306 {
weight 1
notify_down /etc/keepalived/bin/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}

1、停止开机自启动:sudo systemctl disable keepalived.service
2、查看服务当前状态:sudo systemctl status keepalived.service
3、重新启动某服务:sudo systemctl restart keepalived.service
4、停止某服务:sudo systemctl stop keepalived.service
5、执行ip a命令,可查看虚拟IP信息。
6、防火墙影响导致不能访问
完全关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值