keepalived安装
1、下载解压
wget http://www.keepalived.org/software/keepalived-1.2.16.tar.gz
注意:如果安装出错可能需要安装一些插件
yum -y install openssl-devel
2、解压安装
tar –zxvf keepalived-1.2.16.tar.gz
cd keepalived-1.2.16
./configure --prefix=/iflytek/soft/keepalived
make && make install
3、添加进系统服务
cp /iflytek/soft/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /iflytek/soft/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /iflytek/soft/keepalived/sbin/keepalived /usr/sbin/
mkdir /etc/keepalived
cp /iflytek/soft/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
chmod +x /etc/init.d/keepalived
4、配置keepalived.conf
vim /etc/keepalived/keepalived.cfg
master配置
! Configuration File for keepalived
global_defs {
notification_email {
sample@sample.com
}
notification_email_from sample@sample.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAProxy_DEVEL
}
vrrp_script chk_haproxy {
script "killall -0 haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance HAProxy_HA {
interface eth0 # interface to monitor
state MASTER # MASTER on ha1, BACKUP on ha2
virtual_router_id 51
# mcast_src_ip 10.1.100.219
priority 101 # 101 on ha1, 100 on ha2
advert_int 1
authentication {
auth_type PASS
auth_pass 1qaz2wsx
}
virtual_ipaddress {
172.16.17.222 dev eth0 label eth0:1 # virtual ip address
}
track_interface {
eth0
}
track_script {
chk_haproxy
}
unicast_src_ip 172.16.17.100
unicast_peer {
172.16.17.89
}
}
slave配置
! Configuration File for keepalived
global_defs {
notification_email {
sample@sample.com
}
notification_email_from sample@sample.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id HAProxy_DEVEL
}
vrrp_script chk_haproxy {
script "killall -0 haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance HAProxy_HA {
interface eth0 # interface to monitor
state BACKUP # MASTER on ha1, BACKUP on ha2
virtual_router_id 51
# mcast_src_ip 10.1.100.219
priority 100 # 101 on ha1, 100 on ha2
advert_int 1
authentication {
auth_type PASS
auth_pass 1qaz2wsx
}
virtual_ipaddress {
172.16.17.222 dev eth0 label eth0:1 # virtual ip address
}
track_interface {
eth0
}
track_script {
chk_haproxy
}
unicast_src_ip 172.16.17.89
unicast_peer {
172.16.17.100
}
}
注意:
备用服务器仅仅只需要改一下 state属性,然后换一下主备IP的位置
5、启动
service keepalived start #启动
service keepalived stop #停止
service keepalived restart #重启