厚积薄发

不忘初心,方得始终!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Keepalive 双主搭建配置

keepalived保证双主数据库的可用性

环境说明

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 关闭后:

posted on 2016-05-31 19:55  欢迎来到Java的世界  阅读(4170)  评论(0编辑  收藏  举报