码迷,mamicode.com
首页 > 其他好文 > 详细

Keepalive双主搭建配置

时间:2016-05-31 20:33:32      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

Keepalive 双主搭建配置

环境说明:

192.168.1.10  keepalive 主1

192.168.1.20  keepalive 主2

192.168.1.111  keepalive 主1  从2 VIP

192.168.1.222  keepalive 从1  主2 VIP

1 官网下载最新版本

keepalived-1.2.19

2 部署安装:

yum install gcc gcc-c++ make openssl openssl-devel

tar zxvf keepalived-1.2.19.tar.gz

cd keepalived-1.2.19

./configure --sysconf=/etc/ --with-kernel-dir=/usr/src/linux --prefix=/usr/local/keepalived

make ; make install

cp /usr/local/keepalive/sbin/keepalived /usr/bin/

cp /usr/local/keepalived/sbin/keepalived /usr/bin/

cp /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

chkconfig keepalived on

3 建立配置文件:

vim /etc/keepalived/keepalived.conf

global_defs {

   notification_email {

     cwliu@atman.com

   }

   notification_email_from root@localhost

   smtp_server 127.0.0.1

   smtp_connect_timeout 30    

   router_id Mariadb_keepalive1

}

vrrp_script notification {

   script "/data/ops/script/mail.sh"

   interval 1

   weight 2

   }

vrrp_script check_alive {

   script "/data/ops/script/mysql_check.sh"

   interval 1

   weight 2

   }

vrrp_instance Mariadb_keepalive_channel1 {

    state MASTER

    interface eth0

    virtual_router_id 100

    priority 200

    advert_int 1

    authentication {

     auth_type PASS

     auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.111

    }

    track_script {

check_alive

    }

}

vrrp_instance Mariadb_keepalive_channel2 {

    state BACKUP

    interface eth0

    virtual_router_id 101

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.222

    }

    track_script {

check_alive

    }

}

4  然后启动即可

/etc/init.d/keepalived start

5  Keepalive 另一主服务器除配置文件不一样,其他配置步骤如上,配置文件如下:

vim /etc/keepalived/keepalived.conf

global_defs {

   notification_email {

     cwliu@atman.com

   }

   notification_email_from root@localhost

   smtp_server 127.0.0.1

   smtp_connect_timeout 30    

   router_id Mariadb_keepalive

}

vrrp_script notification {

   script "/data/ops/script/mail.sh"

   interval 1

   weight 2

}

vrrp_script check_alive {

   script "/data/ops/script/mysql_check.sh"

   interval 1

   weight 2

}

vrrp_instance Mariadb_keepalive_channel1 {

    state BACKUP

    interface eth0

    virtual_router_id 100

    priority 100

    advert_int 1

    authentication {

     auth_type PASS

     auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.111

    }

    track_script {

check_alive

    }

}

vrrp_instance Mariadb_keepalive_channel2 {

    state MASTER

    interface eth0

    virtual_router_id 101

    priority 200

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.222

    }

    track_script {

check_alive

    }

}

6  效果图:

两台同时运行:

192.168.1.10:

技术分享

192.168.1.20

技术分享

192.168.1.10 keepalive 关闭后:

技术分享

Keepalive双主搭建配置

标签:

原文地址:http://www.cnblogs.com/wangyangliuping/p/5547221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!