配置VIP
先解释下以下步骤中的几个变量(默认使用root权限)
$node1: 服务器A的内网IP
$node2: 服务器B的内网IP
$vip: 内网VIP
服务器A(node1)
1、编辑/etc/keepalived/keepalived.conf
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
#unicast peer 格式必须完全匹配!否则会起不来,必须写成三行。
unicast_peer {
$node2
}
virtual_router_id 51
priority 100 advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
$vip dev eth0
}
}
2、启动keepalived
# service keepalived start
服务器B(node2)
1、编辑/etc/keepalived/keepalived.conf
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
#unicast peer 格式必须完全匹配!否则会起不来,必须写成三行。
unicast_peer {
$node1
}
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
$vip dev eth0
}
}
2、启动keepalived
# service keepalived start
四、测试VIP
1、检查系统日志, 观察keepalived是否成功
# tail /var/log/messsages
2、在node1上停止掉keepalived,然后在node1和node2上分别观察IP信息
# service keepalived stop
# ip a
PSPS:
官网: http://www.keepalived.org
PSPSPS:
centos7 yum源中的版本是 1.2.13,如果想用最新稳定版,可能需要自己去编译安装。
systemd 启停脚本,如果自己编译可以修改一下路径啥的。。。
cat /usr/lib/systemd/system/keepalived.service
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
KillMode=process
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
网友评论