接上篇应用通过MySQL Router连接MGR数据库失败原因-1,介绍应用通过MySQL Router连接MGR数据库失败第二种原因。
原因二:连接数达到上限
1、问题现象
MySQL客户端或应用代码报错出现关键字:Too many connections
[kingly@rhel7]$ mysql -uapp -pxxx -h127.0.0.1 -P23306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Too many connections '127.0.0.1' (111)
2、问题原因
应用到MySQL Router的连接数达到上限(默认512)。
官方介绍如下:
max_connections
<colgroup style="box-sizing: border-box;"><col style="box-sizing: border-box;"><col style="box-sizing: border-box;"></colgroup>
|
Type
|
Integer
|
|
Default Value
|
512
|
|
Minimum Value
|
1
|
|
Maximum Value
|
65536
|
Each routing can limit the number of routes or connections. One possible use is to help prevent possible Denial-Of-Service (DOS) attacks. The default value is 512, and the valid range is between 1 and 65536.
This is similar to MySQL Server's max_connections server system variable.
[routing:mycluster_default_rw]
max_connections = 512
Alternatively, use the newer max_total_connections configuration option that sets one value for all Router sections combined.
MySQL Router 8.0.22 introduced functionality that increases the concurrent connection limit from around 5,000 to 50,000 connections. The maximum depends both on the system's poll (or linux_epoll) limitations and the number of available CPU cores/threads. See also the [IO] backend and threads configuration options.
Optionally setting max_connections in the [DEFAULT] section sets the default value for each routing destination.
也就是每一个routing服务可以限制连接数的上限,默认是512,最小是1,最大是65536,主要是防止DOS攻击。用户可以调整此参数值的大小。
3、解决方法
- 调大最大连接数
查看mysqlrouter.conf配置文件中,是否有设置最大连接数max_connections,如果没有配置,默认是512。
修改配置文件mysqlrouter.conf,在[routing:mycluster_rw]模块下添加max_connections=XXXX,XXXX为最大连接数。
[kingly@rhel7]$vi /home/mw/mysqlrouter/mycluster_23306/mysqlrouter.conf
[routing:mycluster_rw]
max_connections=1000
bind_address=0.0.0.0
bind_port=23306
destinations=metadata-cache://mycluster/?role=PRIMARY
routing_strategy=first-available
protocol=classic
重启MySQL Router。
调整连接数后,需要关注服务器的性能是否能支撑这么多的连接业务。
4、验证结果
测试连接情况,通过MySQL客户端尝试连接数据库,看能否正常连接数据库。
[kingly@rhel7]$ mysql -uapp -pxxx -h127.0.0.1 -P23306
=======================欢迎大家同时关注我其他平台========================
微信公众号 | 老王聊MySQL
知乎 | 老王聊MySQL | https://www.zhihu.com/people/old_king CSDN | 老王聊MySQL | https://blog.csdn.net/wly619?spm=1010.2135.3001.5421 简书 | 老王聊MySQL | https://www.jianshu.com/u/80e4c9cd3af5
网友评论