1.什么是keepalived Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,当web服务器工作正常后Keepalived自动将web服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的web服务器。
2. keepalived 安装
wget http://www.keepalived.org/software/keepalived-1.1.12.tar.gz tar -zxvf keepalived-1.1.12.tar.gz cd keepalived-1.1.12 ./configure --prefix=/usr/local/keepalived make && make install !如果出现: configure: error: Popt libraries is required yum -y install popt-devel
3. 配置
1. 主 vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.18 } }
2. 备 vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.18 } }
4. keepalived启用 /usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
5. 查看ip ip add show eth0