实现原理是靠 TCP/IP 的 ARP 协议。因为 IP 地址只是一个逻辑 地址,在以太网中 MAC 地址才是真正用来进行数据传输的物理地址,每台主机中都有一个 ARP 缓存,存储同一个网络内的 IP 地址与 MAC 地址的对应关系,以太网中的主机发送数据时会先从这个缓存中查询目标 IP 对应的 MAC 地址,会向这个 MAC 地址发送数据。操作系统会自动维护这个缓存。
yum install -y keepalived # 安装
systemctl status keepalived # 查看服务状态
systemctl restart keepalived # 启动服务
systemctl stop keepalived # 停止服务
systemctl enable keepalived # 开机启动
systemctl disable keepalived # 开机禁用
cat /etc/keepalived/keepalived.conf # 查看配置
vi /etc/keepalived/keepalived.conf # 编辑配置
ip addr show eth0 # 查看网卡信息,eth0 为网卡名
IP | 名称 |
---|---|
192.168.100.199 | VIP |
192.168.100.115 | Master |
192.168.100.116 | Backup |
! Configuration File for keepalived
global_defs {
script_user root
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER # 主备配置不一致
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass aaaaaaa # 主备该配置必须一样
}
virtual_ipaddress {
192.168.100.199/24 # VIP,可配置多个
}
# 当这台机器成为 Master 时发送通知
# notify_master "/etc/keepalived/notify.sh 192.168.100.199 master"
# notify_backup "/etc/keepalived/notify.sh 192.168.100.199 backup"
# notify_fault "/etc/keepalived/notify.sh 192.168.100.199 fault"
}
! Configuration File for keepalived
global_defs {
script_user root
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP # 主备配置不一致
interface eth0
virtual_router_id 51
priority 90 # 备机权重比主机低
advert_int 1
nopreempt # 防止争抢 VIPA,只有 state 设置为 BACKUP 才能使用该选项
authentication {
auth_type PASS
auth_pass aaaaaaa # 主备该配置必须一样
}
virtual_ipaddress {
192.168.100.199/24 # VIP,可配置多个
}
}
https://www.cnblogs.com/schaepher/p/12842624.html
https://www.jianshu.com/p/11f6e16cf8d9
甲骨文免费的 Oracle 两台小鸡部署失败,默认网卡名为 ens3,或许姿势不对需要哪里配置一下,换到本地虚拟机部署成功,网卡名默认 eth0