• keepalived+mysql主从环境,keepalived返回值是RST,需求解决方法?


    环境描述:

      mysql版本5.6.37    keepalived-1.2.19    系统centos 7:3.10.0-514.26.2.el7    web是:windows  server 2012  IIS

      mysql部署了主从,使用keepalived做高可用,防止数据库故障。web中连接数据库使用了keepalived的VIP地址。

    问题描述:

       测试同事在测试时,发现网站的日志如下:

    日志时间:2019-04-11 14:00:14,314 [29]
    日志级别:ERROR
    日 志 类:Logger [(null)]
    Authentication to host '172.16.179.167' for user 'user' using method 'mysql_native_password' failed with message: Reading from the stream has failed.
    MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '172.16.179.167' for user 'dcyy' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.IOException: 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。 ---> System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。
    在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

     尝试过:修改mysql的连接数,skip-name-resolve, 系统的内存够用,系统的ulimit 调整为最大值,包括在IIS中添加sslMode=none.  这个故障还是无法解决!

     通过抓包分析:当web的请求发送到数据库后,完成3次握手以后,建立连接,然后开始走mysql协议,这时候WEB服务使用指定的用户和密码及数据库参数去访问数据库,然后直接被数据库发来RST包拒绝了。

    查看抓取的包,访问使用是数据库协议是正确的。

    正常情况下:数据库是应该给一个返回值的。不可能是RST。如下是正常情况下的抓包。

    经用验证。把使用的keepalived的VIP地址,更换为主库的IP地址后,故障没再出现。现在是怎么解决这个问题。为什么keepalived的回应值是RST呢?

    下面附加keepalived的配置文件:

      主库上keepalived的配置如下:

      [root@DB_M ~]# cat /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.1
    #smtp_connect_timeout 30
    router_id i-tgwtglov
    }

    vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 51
    priority 150
    advert_int 3
    nopreempt
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    172.16.179.167


    }
    }

    virtual_server 172.16.179.167 3306 {
    delay_loop 2
    lb_algo wrr
    lb_kind DR
    persistence_timeout 7200
    protocol TCP

    real_server 172.16.179.165 3306 {
    weight 3
    notify_down /data/mysql/mysql.sh
    TCP_CHECK {
    connect_timeout 10
    nb_get_retry 3
    delay_before_retry 3
    connect_port 3306
    }
    }
    }

    从库上keepalived的配置如下:

    [root@DB_S ~]# cat /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.1
    #smtp_connect_timeout 30
    router_id i-tgwtglov
    }

    vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 51
    priority 50
    advert_int 3
    nopreempt
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    172.16.179.167


    }
    }

    virtual_server 172.16.179.167 3306 {
    delay_loop 2
    lb_algo wrr
    lb_kind DR
    persistence_timeout 7200
    protocol TCP

    real_server 172.16.179.166 3306 {
    weight 3
    notify_down /data/mysql/mysql.sh
    TCP_CHECK {
    connect_timeout 10
    nb_get_retry 3
    delay_before_retry 3
    connect_port 3306
    }
    }
    }

    请忽略配置了一个read_server ,做主从的目的就是防止mysql故障。环境就是只使用主库,当主库宕机后,才使用从库。

    请大家帮忙看看!谁见过这个问题。该怎么处理啊。不然现在环境只用的主库的IP地址,keepalived就没用了。

    作者:Cherry_梅 出处:http://www.cnblogs.com/itqingtian/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    Vue学习笔记之Vue指令系统介绍
    Vue学习笔记之Vue的使用
    Vue学习笔记之Vue介绍
    vim笔记
    python安装包的方式
    基本认证与摘要认证
    curl常用指令
    python优缺点小结
    环境变量的作用
    mac os、linux及unix之间的关系
  • 原文地址:https://www.cnblogs.com/itqingtian/p/10730390.html
Copyright © 2020-2023  润新知