keepalived 软主备

tar -zxvf keepalived-1.1.20.tar.gz
cd keepalived-1.1.20
./configure --disable-fwmark --prefix=/usr/local/keepalived




遇到错误提示:configure: error: Popt libraries is required
这个错误是因为没有安装popt的开发包导致的,解决方法也很简单,只要yum install popt-devel 就可以安装好popt的开发包了。
重新./configure
或者


tar -zxvf popt-1.16.tar.gz
cd popt-1.16
./configure
make && make install


make && make install


整理:


mkdir /etc/keepalived/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/


配置: 
vi /etc/keepalived/keepalived.conf

global_defs {
        #notification_email {  #指定keepalived在发生切换时需要发送email到的对象,一行一个
        #   [email protected]
        #}
        #notification_email_from [email protected] #指定发件人
        #smtp_server xx.com #指定smtp服务器地址
        #smtp_connect_timeout 30 #指定smtp连接超时时间   
        router_id VIP_EPG_B #运行keepalived机器的一个标识
}


vrrp_script chk_mysql{
        script "/etc/keepalived/mysql_pid.sh" #检查mysql状态的脚本
        interval 1
        weight 2



vrrp_instance training{
    state BACKUP #主节点
    interface eth0 #备用节点
    virtual_router_id 51 #主备必需一样
    priority 90 #优先级 主>备 1-254 高优先级竞选为master
    advert_int 1 #检查间隔,默认1秒
    authentication {
        auth_type PASS #VRRP认证,主备一致
        auth_pass DSFEPG #密码
    }


    notify_master "/etc/keepalived/vi1master.sh"
    notify_backup "/etc/keepalived/vi1backup.sh"
    notify_fault "/etc/keepalived/vi1fault.sh"
    virtual_ipaddress {
        172.31.246.220/27
    }
    #执行脚本
    track_script {
        chk_mysql
    }
    
}


停止
service keepalived stop
启动
service keepalived start
重启
service keepalived restart
查看状态
service keepalived status
查看虚拟ip
ip add 

你可能感兴趣的:(keepalived 软主备)