我想将mysql 5.6托管的AWS EC2 docker容器中的max_connections增加到1024。 EC2的实例类型为m4.large

我通过在max_connections=1024中添加my.cnf来将max_connections设置为1024,但是在键入show varialbes like 'max_connections'; mysql命令时,我只看到214。这是我的my.cnf:

my.cnf

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
skip-host-cache
skip-name-resolve
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

max_connections=1024
max_connect_errors=100000

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

#log-error      = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

我已经尝试过MySQL Max_connections stuck on 214 ?中提到的解决方案。但这对我来说不起作用。以下是我的设置:

普通 session
# here are the per-package modules (the "Primary" block)
session [default=1]         pam_permit.so
# here's the fallback if no module succeeds
session requisite           pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
session required            pam_permit.so
# and here are more per-package modules (the "Additional" block)
session required    pam_unix.so

session required    pam_limits.so
# end of pam-auth-update config

limits.conf
#<domain>      <type>  <item>         <value>
* soft  nofile 65536
* hard  nofile 65536
* soft  nproc  100000
* hard  nproc  127466

我也尝试过解决方案here

mysql.service
[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/bin/mysqld_safe
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure

LimitNOFILE=infinity
LimitMEMLOCK=infinity

这个解决方案对我也不起作用。

我通过ECS任务定义中的mountPointsvolumes将上述文件从主机传递到docker容器中。

以下是我的ECS任务定义的mountPoints和卷:
"mountPoints": [
{
  "containerPath": "/docker-entrypoint-initdb.d/user.sql",
  "sourceVolume": "user",
  "readOnly": true
},
{
  "containerPath": "/etc/mysql/my.cnf",
  "sourceVolume": "mysql_config",
  "readOnly": false
},
{
  "containerPath": "/etc/security/limits.conf",
  "sourceVolume": "limits_conf",
  "readOnly": null
},
{
  "containerPath": "/etc/systemd/system/mysql.service",
  "sourceVolume": "mysql_service",
  "readOnly": null
},
{
  "containerPath": "/etc/pam.d/common-session",
  "sourceVolume": "common_session",
  "readOnly": null
}
],

"volumes": [
{
  "host": {
    "sourcePath": "/home/docker/mysql/user.sql"
  },
  "name": "user"
},
{
  "host": {
    "sourcePath": "/home/docker/mysql/my.cnf"
  },
  "name": "mysql_config"
},
{
  "host": {
    "sourcePath": "/home/docker/mysql/limits.conf"
  },
  "name": "limits_conf"
},
{
  "host": {
    "sourcePath": "/home/docker/mysql/mysql.service"
  },
  "name": "mysql_service"
},
{
  "host": {
    "sourcePath": "/home/docker/mysql/common-session"
  },
  "name": "common_session"
}
],

我还能做什么,以便max_connections可以达到1024?

如果您需要了解我的Docker容器的更多信息,请告诉我。

最佳答案

最后,我发现添加--ulimit nofile=65536:65536可以解决我的问题。

选项中的第一个65536代表软限制,第二个65536代表硬限制。

07-24 09:39
查看更多