linux下配置keepalived双机热备

(注:我用的keepalived版本是1.1.19)

1.安装keepalived(在nginx的mater和backup都安装) 

#wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
#tar zxvf keepalived-1.1.19.tar.gz
#cd keepalived-1.1.19
#./configure --prefix=/usr/local/keepalived   #
指定安装目录
#make 
#make install          #
安装
 

2.复制需要的文件信息

#cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
#cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
#cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

3.添加主配置文件:

#mkdir /etc/keepalived
#查看keepalived配置文件cd /etc/keepalived/
#vi keepalived.conf

global_defs {
   router_id web_nginx
}
vrrp_instance VI_1 {  #定义一个实例
   state MASTER    #备份服务器上改成BACKUP
   interface eth0     #指定存活检测的网卡
   smtp_alert
   virtual_router_id 51
   priority 100
   advert_int 1      #同步通知时间间隔,单位为秒
   authentication {   #身份认证
         auth_type PASS
         auth_pass 123
   }
   virtual_ipaddress {     #VIP假如有多个VIP连续 换行写
        192.168.1.1
   }
}
vrrp_instance VI_2 {  #定义第二个实例,可如上书写
   state MASTER
   interface eth1
   smtp_alert
   virtual_router_id 52
   priority 100
   advert_int 1
   authentication {
         auth_type PASS
         auth_pass 321
   }
   virtual_ipaddress {
        192.168.2.1
   }
}
      
4.服务启动keepalived:/etc/init.d/keepalived start

5.从服务器上面的配置文件,state状态为BACKUP,priority的数值要比主服务器至少小50。其他和主服务器对应。