mysql - 在 docker 容器中将 mysql max_connections 增加到 1024

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

我想在 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' 时我只看到 214 ; mysql命令。这是我的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": [
{
  "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代表硬限制。

关于mysql - 在 docker 容器中将 mysql max_connections 增加到 1024,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39054410/

相关文章:

Azure Devops Pipeline ACR 部署到 Web 应用容器

testing - Amazon EC2 原型(prototype)制作

mysql - MySQL IF 等于 COALESCE 吗?

MySQL 合并两个表

docker - 错误未知时区America/Los_Angeles在时间。

mysql 不尊重 my.cnf 中的 wait_timeout 设置

mongodb - robomongo aws ec2 ubuntu

mysql - 查询SQL数据库-一对多查询

mysql - 获取 SQL 表中两行的最小日期

docker - 为什么我可以在环回设备上安装一个镜像,而不能在容器内的另一个设备上安装第二个镜像?