一 环境规划
节点 | IP | 功能 | VIP |
node-01 | 192.168.174.120 | keepalived master/slave | 192.168.174.20 |
node-02 | 192.168.174.121 | keepalived slave/master | 192.168.174.21 |
二 设置node-01节点
2.1 查看node-01节点配置
root@node-01:~# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node-01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
include /etc/keepalived/conf.d/*.conf
2.2 创建配置文件路径
root@node-01:~# mkdir -pv /etc/keepalived/conf.d
mkdir: created directory '/etc/keepalived/conf.d'
2.3 配置实例master.conf
root@node-01:~# cat /etc/keepalived/conf.d/master.conf
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 101
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.174.20
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
2.4 设置实例slave.conf
root@node-01:~# cat /etc/keepalived/conf.d/slave.conf
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 102
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.174.21
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
2.5 启动keepalived服务
root@node-01:~# systemctl start keepalived
21.6 查看node-01节点VIP
root@node-01:~# hostname -I
192.168.174.120 192.168.174.20 192.168.174.21
三 设置node-02节点
3.1 查看node-01节点配置
root@node-02:~# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node-01
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
include /etc/keepalived/conf.d/*.conf
3.2 创建配置文件路径
root@node-02:~# mkdir -pv /etc/keepalived/conf.d
mkdir: created directory '/etc/keepalived/conf.d'
3.3 配置实例master.conf
root@node-02:~# cat /etc/keepalived/conf.d/master.conf
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 102
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.174.21
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
3.4 设置实例slave.conf
root@node-02:~# cat /etc/keepalived/conf.d/slave.conf
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 101
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.174.20
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
3.5 启动keepalived服务
root@node-02:~# systemctl start keepalived
3.6 查看node-02节点VIP
root@node-02:~# hostname -I
192.168.174.121 192.168.174.21
3.7 查看node-01节点VIP
root@node-01:~# hostname -I
192.168.174.120 192.168.174.20