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就没用了。

 

转载于:https://www.cnblogs.com/itqingtian/p/10730390.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值