设为首页 收藏本站
查看: 373|回复: 0

[经验分享] MySql Database HA:Keepalived+MySQL Replication-Oracle&Mysql DBA-51CTO博客

[复制链接]

尚未签到

发表于 2018-10-2 09:59:45 | 显示全部楼层 |阅读模式
[root@amb01 ~]# mysql -uroot -pabcd.1234  
mysql> show slave status\G;
  
*************************** 1. row ***************************
  
               Slave_IO_State: Waiting for master to send event
  
                  Master_Host: 192.168.1.202
  
                  Master_User: repl
  
                  Master_Port: 3306
  
                Connect_Retry: 60
  
              Master_Log_File: mysql-bin.000003
  
          Read_Master_Log_Pos: 120
  
               Relay_Log_File: relay-bin.000002
  
                Relay_Log_Pos: 283
  
        Relay_Master_Log_File: mysql-bin.000003
  
             Slave_IO_Running: Yes
  
            Slave_SQL_Running: Yes
  
              Replicate_Do_DB:
  
          Replicate_Ignore_DB:
  
           Replicate_Do_Table:
  
       Replicate_Ignore_Table:
  
      Replicate_Wild_Do_Table:
  
  Replicate_Wild_Ignore_Table:
  
                   Last_Errno: 0
  
                   Last_Error:
  
                 Skip_Counter: 0
  
          Exec_Master_Log_Pos: 120
  
              Relay_Log_Space: 450
  
              Until_Condition: None
  
               Until_Log_File:
  
                Until_Log_Pos: 0
  
           Master_SSL_Allowed: No
  
           Master_SSL_CA_File:
  
           Master_SSL_CA_Path:
  
              Master_SSL_Cert:
  
            Master_SSL_Cipher:
  
               Master_SSL_Key:
  
        Seconds_Behind_Master: 0
  
Master_SSL_Verify_Server_Cert: No
  
                Last_IO_Errno: 0
  
                Last_IO_Error:
  
               Last_SQL_Errno: 0
  
               Last_SQL_Error:
  
  Replicate_Ignore_Server_Ids:
  
             Master_Server_Id: 2
  
                  Master_UUID: 69d85c84-25be-11e8-93a5-0800277b1412
  
             Master_Info_File: mysql.slave_master_info
  
                    SQL_Delay: 0
  
          SQL_Remaining_Delay: NULL
  
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
  
           Master_Retry_Count: 86400
  
                  Master_Bind:
  
      Last_IO_Error_Timestamp:
  
     Last_SQL_Error_Timestamp:
  
               Master_SSL_Crl:
  
           Master_SSL_Crlpath:
  
           Retrieved_Gtid_Set:
  
            Executed_Gtid_Set:
  
                Auto_Position: 0
  
1 row in set (0.00 sec)
  

  
[root@amb02 ~]# mysql -uroot -pabcd.1234
  
mysql> show slave status\G;
  
*************************** 1. row ***************************
  
               Slave_IO_State: Waiting for master to send event
  
                  Master_Host: 192.168.1.201
  
                  Master_User: repl
  
                  Master_Port: 3306
  
                Connect_Retry: 60
  
              Master_Log_File: mysql-bin.000007
  
          Read_Master_Log_Pos: 120
  
               Relay_Log_File: relay-bin.000008
  
                Relay_Log_Pos: 283
  
        Relay_Master_Log_File: mysql-bin.000007
  
             Slave_IO_Running: Yes
  
            Slave_SQL_Running: Yes
  
              Replicate_Do_DB:
  
          Replicate_Ignore_DB:
  
           Replicate_Do_Table:
  
       Replicate_Ignore_Table:
  
      Replicate_Wild_Do_Table:
  
  Replicate_Wild_Ignore_Table:
  
                   Last_Errno: 0
  
                   Last_Error:
  
                 Skip_Counter: 0
  
          Exec_Master_Log_Pos: 120
  
              Relay_Log_Space: 613
  
              Until_Condition: None
  
               Until_Log_File:
  
                Until_Log_Pos: 0
  
           Master_SSL_Allowed: No
  
           Master_SSL_CA_File:
  
           Master_SSL_CA_Path:
  
              Master_SSL_Cert:
  
            Master_SSL_Cipher:
  
               Master_SSL_Key:
  
        Seconds_Behind_Master: 0
  
Master_SSL_Verify_Server_Cert: No
  
                Last_IO_Errno: 0
  
                Last_IO_Error:
  
               Last_SQL_Errno: 0
  
               Last_SQL_Error:
  
  Replicate_Ignore_Server_Ids:
  
             Master_Server_Id: 1
  
                  Master_UUID: 6dc7ad57-25b9-11e8-9384-08002746e9d6
  
             Master_Info_File: mysql.slave_master_info
  
                    SQL_Delay: 0
  
          SQL_Remaining_Delay: NULL
  
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
  
           Master_Retry_Count: 86400
  
                  Master_Bind:
  
      Last_IO_Error_Timestamp:
  
     Last_SQL_Error_Timestamp:
  
               Master_SSL_Crl:
  
           Master_SSL_Crlpath:
  
           Retrieved_Gtid_Set:
  
            Executed_Gtid_Set:
  
                Auto_Position: 0
  
1 row in set (0.00 sec)
  

  
[root@amb01 ~]# yum install -y libnl libnl-devel
  
[root@amb01 ~]# cd /usr/local/src
  
[root@amb01 src]# tar zxvf keepalived-1.2.19.tar.gz
  
[root@amb01 src]# cd keepalived-1.2.19
  
[root@amb01 keepalived-1.2.19]# ./configure --sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64
  
[root@amb01 keepalived-1.2.19]# make && make install
  
[root@amb01 keepalived-1.2.19]# ln -s /usr/local/sbin/keepalived /sbin/
  
[root@amb01 ~]# chkconfig --add keepalived
  
[root@amb01 ~]# chkconfig --level 35 keepalived on
  
[root@amb01 ~]# chkconfig --list |grep keepalived
  
keepalived      0:off   1:off   2:off   3:on    4:off   5:on    6:off
  

  
[root@amb01 ~]# vi /etc/keepalived/keepalived.conf
  
! Configuration File for keepalived
  
global_defs {
  
   notification_email {
  
     acassen@firewall.loc
  
     failover@firewall.loc
  
     sysadmin@firewall.loc
  
   }
  
   notification_email_from Alexandre.Cassen@firewall.loc
  
   smtp_server 192.168.200.15
  
   smtp_connect_timeout 30
  
   router_id king01
  
}
  
vrrp_script check_mysql {
  
        script "/usr/local/mysql/scripts/check_mysql.sh"
  
        interval 2
  
}
  
vrrp_instance v01 {
  
    state BACKUP
  
    interface eth0
  
    virtual_router_id 200
  
    priority 100
  
    advert_int 1
  
    nopreempt
  
    authentication {
  
        auth_type PASS
  
        auth_pass 1111
  
    }
  
    virtual_ipaddress {
  
        192.168.1.200
  
    }
  
        track_script {
  
        check_mysql
  
    }
  
}
  

  
[root@amb01 ~]# vi /usr/local/mysql/scripts/check_mysql.sh
  
#!/bin/bash
  
MYSQL=/usr/local/mysql/bin/mysql
  
MYSQL_HOST=localhost
  
MYSQL_USER=root
  
MYSQL_PASSWORD=abcd.1234
  
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD -e "show status;" >/dev/null 2>&1
  
if [ $? == 0 ]
  
then
  
    echo " $host mysql login successfully "
  
    exit 0
  
else
  
    echo " $host mysql login faild"
  
    exit 1
  
fi
  
[root@amb01 ~]# chmod a+x /usr/local/mysql/scripts/check_mysql.sh
  

  
[root@amb01 ~]# service keepalived start
  
Starting keepalived:                                       [  OK  ]
  

  
[root@amb01 ~]# service keepalived status
  
keepalived (pid  3452) is running...
  

  
[root@amb01 ~]# tail -n 100 /var/log/messages
  
Feb 23 05:09:04 king01 Keepalived[11667]: Starting Keepalived v1.2.19 (02/23,2018)
  
Feb 23 05:09:04 king01 Keepalived[11668]: Starting Healthcheck child process, pid=11670
  
Feb 23 05:09:04 king01 Keepalived[11668]: Starting VRRP child process, pid=11671
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Netlink reflector reports IP 192.168.1.201 added
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Netlink reflector reports IP fe80::a00:27ff:fe2b:d617 added
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Registering Kernel netlink reflector
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Registering Kernel netlink command channel
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Registering gratuitous ARP shared channel
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Opening file '/etc/keepalived/keepalived.conf'.
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Configuration is using : 69135 Bytes
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Netlink reflector reports IP 192.168.1.201 added
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: Using LinkWatch kernel netlink reflector...
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) Entering BACKUP STATE
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Netlink reflector reports IP fe80::a00:27ff:fe2b:d617 added
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Registering Kernel netlink reflector
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Registering Kernel netlink command channel
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Opening file '/etc/keepalived/keepalived.conf'.
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Configuration is using : 11739 Bytes
  
Feb 23 05:09:04 king01 Keepalived_healthcheckers[11670]: Using LinkWatch kernel netlink reflector...
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
  
Feb 23 05:09:04 king01 Keepalived_vrrp[11671]: VRRP_Script(check_mysql) succeeded
  
Feb 23 05:09:08 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) Transition to MASTER STATE
  
Feb 23 05:09:09 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) Entering MASTER STATE
  
Feb 23 05:09:09 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) setting protocol VIPs.
  
Feb 23 05:09:09 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) Sending gratuitous ARPs on eth0 for 192.168.1.200
  
Feb 23 05:09:09 king01 Keepalived_healthcheckers[11670]: Netlink reflector reports IP 192.168.1.200 added
  
Feb 23 05:09:14 king01 Keepalived_vrrp[11671]: VRRP_Instance(v01) Sending gratuitous ARPs on eth0 for 192.168.1.200
  

  
[root@amb01 ~]# ip addr
  
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
  
    link/ether 08:00:27:2b:d6:17 brd ff:ff:ff:ff:ff:ff
  
    inet 192.168.1.201/24 brd 192.168.1.255 scope global eth0
  
    inet 192.168.1.200/32 scope global eth0
  
    inet6 fe80::a00:27ff:fe2b:d617/64 scope link
  
       valid_lft forever preferred_lft forever



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-607431-1-1.html 上篇帖子: Centos6.5 源码搭建MYSQL5.5+MySQL主从复制 下篇帖子: Mysql DBA 高级运维学习之路-Mysql数据库字符集知识
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表