【问题标题】:Increasing mysql max_connections to 1024 in a docker container在 docker 容器中将 mysql max_connections 增加到 1024
【发布时间】:2017-10-31 19:54:03
【问题描述】:

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

我通过在my.cnf 中添加max_connections=1024 将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 ? 中提到的解决方案。但这在我的情况下不起作用。以下是我的设置:

普通会话

# 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": [
{
  "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 容器的更多信息,请告诉我。

【问题讨论】:

    标签: mysql docker amazon-ec2 database-connection amazon-ecs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      对于 Amazon ECS 任务定义,可以这样做:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-14
        • 2017-08-31
        • 1970-01-01
        • 1970-01-01
        • 2017-04-21
        • 2019-04-14
        • 2021-06-08
        • 2019-12-16
        相关资源
        最近更新 更多