我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

keepalivedMysql双主热备配置的示例分析

这篇文章主要介绍keepalived MySQL双主热备配置的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联公司是专业的六合网站建设公司,六合接单;提供成都做网站、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行六合网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

基于keepalived双主热备:
一.环境:
OS:CentOS 6.5 X64
DB Version:Percona Mysql 5.7.15-9-log
路径:/app/mysql57
数据文件路径:/data/mysql57/data
DB1:192.168.213.4
DB2:192.168.213.5


二.安装keepalived包(两台主机都需操作)
1.下载keepalived包
cd /usr/local/tools
wget http://www.keepalived.org/software/keepalived-1.2.23.tar.gz


2.安装所需包
yum -y install openssl-devel


3.安装keepalived
mkdir -pv /app/keepalived
cd /usr/local/tools
tar xf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/app/keepalived/
make
make install


4.配置keepalived
cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /app/keepalived/sbin/keepalived /usr/sbin/


db01 keepalived配置
cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0    !虚拟IP对应接口,也就是业务接口对应的网卡编号
    virtual_router_id 51
    priority 105    !权重
    advert_int 1
    nopreempt    !自己上线后不抢占当前 master 的位置,即使其权重比自己低
    virtual_ipaddress {
        192.168.213.100    !VIP
    }
    track_script {
        chk_mysql    !启用头部定义的检查MySQL状态的脚本
    }
}
virtual_server 192.168.213.100 3306 {
    delay_loop 3
    lb_algo rr
    lb_kind NAT
    persistence_timeout 60
    protocol TCP    sorry_server 192.168.213.5 3306    ! real_server 挂掉后临时使用 sorry_server 顶上
    real_server 192.168.213.4 3306 {
        weight 1
        TCP_CHECK {
            connect_port    3306
            connect_timeout 3
        }
    }
}




db02 keepalived配置
[root@ORADB-213-5 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   router_id HA_MYSQL
}
vrrp_script chk_mysql {
script "/etc/init.d/mysql57 status"
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0    !虚拟IP对应接口,也就是业务接口对应的网卡编号
    virtual_router_id 51
    priority 100    !权重
    advert_int 1
    nopreempt    !自己上线后不抢占当前 master 的位置,即使其权重比自己低
    virtual_ipaddress {
        192.168.213.100    !VIP
    }
    track_script {
        chk_mysql    !启用头部定义的检查MySQL状态的脚本
    }
}
virtual_server 192.168.213.100 3306 {
    delay_loop 3
    lb_algo rr
    lb_kind NAT
    persistence_timeout 60
    protocol TCP    sorry_server 192.168.213.4 3306    ! real_server 挂掉后临时使用 sorry_server 顶上
    real_server 192.168.213.5 3306 {
        weight 1
        TCP_CHECK {
            connect_port    3306
            connect_timeout 3
        }
    }
}


5.两台DB启动keepalived
/etc/init.d/keepalived start


查看VIP
[root@ORA11G-213-4 keepalived-1.2.23]# ip addr
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c7:d5:27 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.4/24 brd 192.168.213.255 scope global eth0
    inet 192.168.213.100/32 scope global eth0
    inet6 fe80::20c:29ff:fec7:d527/64 scope link 
       valid_lft forever preferred_lft forever
  
测试
[root@ORA11G-213-4 keepalived-1.2.23]# mysql -unetdata -pnetdata -h 192.168.213.100
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2881
Server version: 5.7.15-9-log Source distribution


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


netdata@192.168.213.100 23:41:  [(none)]> system ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C7:D5:27  
          inet addr:192.168.213.4  Bcast:192.168.213.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec7:d527/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:156643 errors:0 dropped:0 overruns:0 frame:0
          TX packets:191173 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:39459924 (37.6 MiB)  TX bytes:31911844 (30.4 MiB)


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:17378 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17378 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1002566 (979.0 KiB)  TX bytes:1002566 (979.0 KiB)
 
停止掉db01
[root@ORA11G-213-4 keepalived-1.2.23]# /etc/init.d/mysql57 stop
Shutting down MySQL (Percona Server)............. SUCCESS! 


查看db02
[root@ORADB-213-5 ~]# ip addr
1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:63:54:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.5/24 brd 192.168.213.255 scope global eth0
    inet 192.168.213.100/32 scope global eth0
    inet6 fe80::20c:29ff:fe63:5439/64 scope link 
       valid_lft forever preferred_lft forever

以上是“keepalived Mysql双主热备配置的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


当前标题:keepalivedMysql双主热备配置的示例分析
分享URL:http://mswzjz.cn/article/gdhigs.html

其他资讯