温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

记一次数据库连接问题

发布时间:2020-02-26 06:52:57 来源:网络 阅读:450 作者:wlmint 栏目:数据库

最近做项目的时候发现一个问题,网站打开的时候,一停的在转,大概5分钟以后返回504网关超时

当时第一反应是我的网络架构出问题了,于是从前端LVS一直往下查,我的架构是LVS+NGINX+TOMCAT,一直到nginx这块都没问题,从nginx的错误日志也看不出什么,同样的报504网关超时,当时就在想502坏的网关是以为nginx把请求抛给tomcat的时候找不到tomcat的端口,504会不会也一样呢?

[root@web1 ~]# netstat  -lntup|grep 800
tcp        0      0 :::8000                     :::*                        LISTEN      4208/java              
tcp        0      0 :::8002                     :::*                        LISTEN      4208/java           
没看出什么问题,再与线上服务器对比的时候找到问题

[root@web1 ~]# netstat  -lntup|grep 800
tcp        0      0 :::8000                     :::*                        LISTEN      4208/java           
tcp        0      0 ::ffff:127.0.0.1:8001       :::*                        LISTEN      4208/java           
tcp        0      0 :::8002                     :::*                        LISTEN      4208/java          
发现tomcat少了一个端口,为什么没会导致这个问题呢?

查看tomcat日志,发现tomcat没起来,一直卡在连接连接数据库那块

于是我在web端查看mysql端口,发现能通

[root@web2 server]# telnet 10.10.0.126 3306
Trying 10.10.0.126...
Connected to 10.10.0.126.
Escape character is '^]'.
^]
telnet> \q
Connection closed.

到这里发现自己的思路断了!!

峰回路转,无意中在db2上查看了一下mysql端口,发现和在web上的结果不一样

[root@db2 root]# telnet 10.10.0.126 3306
Trying 10.10.0.126...
Connected to 10.10.0.126.
Escape character is '^]'.
N
5.5.32-log0pKhJw=db!>MIgIxAwW,s"mysql_native_password
这是为什么呢?

于是一点点的回忆,思考web和db的区别,最后终于找到问题所在

10.10.0.126和10.10.0.127是我数据的读vip和写vip,只有这两台机器才有10.10.0.0网段的ip

web上只有一个外网ip,于是route -n查看了一下web和db的网关

[root@web1 server]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
202.192.168.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth2
0.0.0.0         202.192.168.1   0.0.0.0         UG    0      0        0 eth2

[root@db2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
202.192.168.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.10.0.0       0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         202.192.168.1   0.0.0.0         UG    0      0        0 eth0

很明显,web上缺少10.10.0.0的网关

于是在web端添加了一个网关
route add -net 10.10.0.0 netmask 255.255.255.0 dev eth2
再查看一下

[root@web1 server]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
202.192.168.0   0.0.0.0         255.255.255.0   U     0      0        0 eth2
10.10.0.0       0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth2
0.0.0.0         202.192.168.1   0.0.0.0         UG    0      0        0 eth2
已经和db端一样了

查看一下mysql端口

[root@web1 server]# telnet 10.10.0.126 3306
Trying 10.10.0.126...
Connected to 10.10.0.126.
Escape character is '^]'.
N
5.5.32-log±vj3[SkES!Q{9H=9E0]fjamysql_native_password
成功啦!!!!!

重启tomcat,查看tomcat端口

[root@web1 server]# netstat -lntup|grep 800
tcp        0      0 :::8000                     :::*                        LISTEN      4208/java           
tcp        0      0 ::ffff:127.0.0.1:8001       :::*                        LISTEN      4208/java           
tcp        0      0 :::8002                     :::*                        LISTEN      4208/java           
端口起来啦

页面访问也正常了!!!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI