监听和替换多台服务器之间的来回切换
一.安装
tar zxvf keepalived-1.1.15.tar.gz
cd keepalived-1.1.15
./configure --prefix=/usr/local/keepalived
make && make install
# 这段配置只是为了使用的方便,可以不这样来操作
--------------------------------------------------------------------------------
cp keepalived-1.1.15/etc/init.d/keepalived.rh.init /etc/init.d/keepalived
chmod a+x /etc/init.d/keepalived
cp keepalived-1.1.15/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived
chkconfig --add keepalived
chkconfig --level 345 keepalived on
cp /usr/local/keepalived/sbin/keepalived /bin/
---------------------------------------------------------------------------------
二.配置
mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf
添加以下内容
#global_defs {
# notification_email {
# root@localhost # 设置报警邮件地址,可以设置多个,每行一个,需要开启sendmail服务
# xxxx@sina.com
# }
# notification_email_from root@localhost # 设置邮件的发送地址
# smtp_server localhost # 设置SMTP Server地址
# smtp_connect_timeout 30 # 设置SMTP Server的超时时间
# router_id LVS_DEVEL # 表示运行keepalived服务器的一个标识,发邮件时显示大邮件主题中的信息
#}
主服务器写法:
vrrp_instance VI_1 {
state MASTER # 指定A节点为主节点 备用节点上设置为BACKUP即可
interface eth0 # 绑定虚拟IP的网络接口
mcast_src_ip 192.168.200.122 # 本机的IP地址
virtual_router_id 51 # VRRP组名,两个节点的设置必须一样,以指明各个节点属于同一VRRP组
priority 100 # 主节点的优先级(1-254之间),备用节点必须比主节点优先级低
advert_int 1 # 组播信息发送间隔,两个节点设置必须一样
authentication { # 设置验证信息,两个节点必须一致
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { # 指定虚拟IP, 两个节点设置必须一样,可以写多个
192.168.200.16
#192.168.200.17/24
#192.168.200.18/24
}
}
从服务器的写法
vrrp_instance VI_1 {
state BACKUP
interface eth0
mcast_src_ip 192.168.200.123
virtual_router_id 51
priority 90 # 优先级要低于主服务器
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.16
#192.168.200.17/24
#192.168.200.18/24
}
}
三.启动
service keepalived start
Keepalived高可用软件的安装与配置,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/ahwu/p/3817791.html