应用服务器未能连接数据库,华为云应用服务器无法连接 MySQL 数据库 3306 端口...

开发反馈华为云应用服务器突然无法连接 MySQL 服务器的 3306 端口了。

查看现象

从应用服务器 telnet MySQL 服务器的 22 3306 端口,发现 22 能通,3306 不通。

查看 iptables 记录,发现有 REJECT 记录(真实的 IP 使用 x.x.x.x 代替了)。Chain INPUT (policy ACCEPT)

target prot opt source destination

IN_HIDS_MYSQLD_BIP_DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306

IN_HIDS_MYSQLD_DENY_DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306

Chain FORWARD (policy ACCEPT)

target prot opt source destination

Chain OUTPUT (policy ACCEPT)

target prot opt source destination

Chain IN_HIDS_MYSQLD_BIP_DROP (1 references)

target prot opt source destination

Chain IN_HIDS_MYSQLD_DENY_DROP (1 references)

target prot opt source destination

LOG all -- x.x.x.x 0.0.0.0/0 LOG flags 0 level 4 prefix "mysqld_drop: "

REJECT all -- x.x.x.x 0.0.0.0/0 reject-with icmp-port-unreachable

解决问题

删除了 iptables 的相关记录,问题解决。

问题原因

在 /var/log/messages 日志中发现有mysqld_drop的字眼,遂查看iptables规则[4333361.597329] mysqld_drop: IN=eth0 OUT= MAC=fa:16:3e:c0:96:2a:fa:16:3e:90:0d:c4:08:00 SRC=124.70.xxx.xxx DST=192.168.0.38 LEN=60 TOS=0x00 PREC=0x00 TTL=56 ID=15889 DF PROTO=TCP SPT=54734 DPT=3306 WINDOW=29200 RES=0x00 SYN URGP=0

[4333361.702625] mysqld_drop: IN=eth0 OUT= MAC=fa:16:3e:c0:96:2a:fa:16:3e:90:0d:c4:08:00 SRC=124.70.xxx.xxx DST=192.168.0.38 LEN=60 TOS=0x00 PREC=0x00 TTL=56 ID=30534 DF PROTO=TCP SPT=47370 DPT=3306 WINDOW=29200 RES=0x00 SYN URGP=0

[4333362.150774] mysqld_drop: IN=eth0 OUT= MAC=fa:16:3e:c0:96:2a:fa:16:3e:90:0d:c4:08:00 SRC=124.70.xxx.xxx DST=192.168.0.38 LEN=60 TOS=0x00 PREC=0x00 TTL=56 ID=52149 DF PROTO=TCP SPT=44338 DPT=3306 WINDOW=29200 RES=0x00 SYN URGP=0

同时在 iptables 中发现多出来 IN_HIDS_MYSQLD_BIP_DROP 和 IN_HIDS_MYSQLD_BIP_DROP 2条链,这2条链还被INPUT 链引用了,而且规则中的ip是测试服的公网ip。

通过规则可以看出来自测试服的ip访问3306被丢弃+记录日志。

这2条链并不是我加的,发工单问华为云客服,客服也不知道,让排查是否自己安装。(估计客服也不懂)

ps查进程,发现有个hostguard进程[root@ecs-38b6-0002 conf]# ps aux | grep hostguard

root 7361 0.0 0.0 112712 968 pts/0 S+ 16:33 0:00 grep --color=auto hostguard

root 9206 0.0 0.0 49044 1468 ? Ss Jun17 9:34 /usr/local/hostguard/bin/hostguard

root 27978 0.1 0.0 1398848 7388 ? Sl Jul13 99:12 /usr/local/hostguard/bin/hostguard

[root@ecs-38b6-0002 conf]# cd /usr/local/hostguard/conf/

[root@ecs-38b6-0002 conf]# ll

total 2448

-r-------- 1 root root 32 May 14 13:00 agent.conf

-rw-r--r-- 1 root root 105 Aug 31 00:00 agentinfo

drwxr-xr-x 2 root root 4096 May 14 13:00 benchmarkconf

-r-------- 1 root root 14340 May 14 13:00 cmsvul.dat

-r-x------ 1 root root 1497 May 14 13:00 config_ssh_log.sh

-r-x------ 1 root root 3193 May 14 13:00 config_ssh_xinetd.sh

-r-------- 1 root root 35332 May 14 13:00 dict.dat

-rw-r--r-- 1 root root 33 Jun 17 12:28 lb.dat

-r-------- 1 root root 1751200 May 14 13:00 magic.mgc

-rw-r--r-- 1 root root 63 Aug 31 16:29 master.dat

-rw-r--r-- 1 root root 0 Aug 30 23:36 modlogin_deny.conf

-rw-r--r-- 1 root root 0 Jul 13 19:19 mysqld_iptables_bip

-rw-r--r-- 1 root root 0 Aug 28 11:21 mysqld_iptables_block

-rw-r--r-- 1 root root 5128 Jun 17 12:29 policy.dat

-rw-r--r-- 1 root root 24 Jul 13 19:18 priv_cpu.dat

-r-------- 1 root root 65 May 14 13:00 res.conf

-r-------- 1 root root 40181 May 14 13:00 rootkit.json

-r-------- 1 root root 3332 May 14 13:00 selfitgr.dat

-rw-r--r-- 1 root root 10 Aug 31 16:33 sending.dat

-r-------- 1 root root 149 Jun 17 12:28 system.conf

-r-------- 1 root root 426 May 14 13:00 user.key

-r-------- 1 root root 26 May 14 13:00 version

-r-------- 1 root root 590648 May 14 13:00 wsyrules.dat

发现也有mysql相关的文件,估计就是这个进程导致的了。查华为文档发现,hostguard是华为主机安全软件。

至于原因,推测是测试服发起了大量连接(有对mysql连接池操作过加大动作),导致云服务器中的安全进程判断为不安全连接,直接给拒绝了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值