暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

应用通过MySQL Router连接MGR数据库失败原因-2

原创 王同学 2022-03-01
2593

接上篇应用通过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

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

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论