分类: 系统运维
2016-05-19 14:49:38
说明:使用keepalived集群分别配置在两台nginx前端服务器上,两台机器做高可用,可以配置主从模式,也可以配置不抢占的从从模式。当 一台机器宕机,另一台马上接管服务,并把对外的vip接管过来。这样,对于外部访问是透明的。及时保障服务不中断。下面是配置步骤:
# yum -y install gcc-c++ openssl-devel
# wget
# tar xf keepalived-1.2.7.tar.gz
# ./configure --prefix=/usr/local/keepalived
# make && make install
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
# chmod +x /etc/init.d/keepalived
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# chkconfig --add keepalived
# chkconfig --level 345 keepalived on
# mkdir /etc/keepalived
#vim /etc/keepalived/keepalived.conf
notification_email {
}
notification_email_from
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 150
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.100.100 //VIP
}
}
实际配置的时候,把 上面 "//vip“去掉,并且ip地址后面不留空格。
#service keepalived start
#ip addr show //查看vip绑定
注:当然,还可以自己写个脚本做定时任务,检测服务否运行,如果服务不能正常运行,就停止本地的keepalived。这个可以根据自己服务情况来写,可以是apache,nginx等多种服务。