无法在 Ubuntu 15 中为 Mysql 最大连接增加 max_open_files

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30901041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:06:21  来源:igfitidea点击:

Can not increase max_open_files for Mysql max-connections in Ubuntu 15

mysqlperformanceubuntu

提问by hernangarcia

I am running this version of Mysql

我正在运行这个版本的Mysql

Ver 14.14 Distrib 5.6.24, for debian-linux-gnu (x86_64)

On this version of Ubuntu

在这个版本的 Ubuntu 上

Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:    15.04
Codename:   vivid

This is the config I set for Mysql:

这是我为 Mysql 设置的配置:

key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
innodb_buffer_pool_size=20G
innodb_log_buffer_size=16M
tmp_table_size = 32M
max_heap_table_size = 32M
open-files-limit=4510
max_connections=500
myisam-recover         = BACKUP
query_cache_type=1
query_cache_limit   = 32M
query_cache_size        = 32M

These are the warnings I keep getting when starting MYSQL:

这些是我在启动 MYSQL 时不断收到的警告:

2015-06-17 17:28:53 26720 [Warning] Buffered warning: Could not increase number 
of max_open_files to more than 1024 (request: 4510)

2015-06-17 17:28:53 26720 [Warning] Buffered warning: Changed limits: max_connections: 
214 (requested 500)

2015-06-17 17:28:53 26720 [Warning] Buffered warning: Changed limits: table_open_cache: 
400 (requested 2000)

I already tried these steps:

我已经尝试过这些步骤:

1) Adding this to /etc/security/limits.conf

1) 将此添加到 /etc/security/limits.conf

mysql           soft    nofile          65535
mysql           hard    no file          65535

2) Adding this to /etc/pam.d/common-authand /etc/pam.d/commom-session

2)将此添加到/etc/pam.d/common-auth/etc/pam.d/commom-session

session required pam_limits.so

3) Add this to /etc/mysql/mysql.conf.d/mysqld.cnf

3) 将此添加到 /etc/mysql/mysql.conf.d/mysqld.cnf

open-files-limit=4510 or open_files_limit=4510

None of these have worked and I am still not able to raise the mysql max connections to 500.

这些都没有奏效,我仍然无法将 mysql 最大连接数提高到 500。

I'd really appreciate some help at this point.

在这一点上,我真的很感激一些帮助。

Thanks a lot in advance.

非常感谢。

回答by Matt Raines

Ubuntu has moved from Upstart to Systemd in version 15.04 and no longer respects the limits in /etc/security/limits.conf for system services. These limits now apply only to user sessions.

Ubuntu 在 15.04 版本中已从 Upstart 迁移到 Systemd,并且不再遵守 /etc/security/limits.conf 中系统服务的限制。这些限制现在仅适用于用户会话。

The limits for the MySQL service are defined in the Systemd configuration file, which you should copy from its default location into /etc/systemd and then edit the copy.

MySQL 服务的限制在 Systemd 配置文件中定义,您应该将其从其默认位置复制到 /etc/systemd 中,然后编辑副本。

sudo cp /lib/systemd/system/mysql.service /etc/systemd/system/
sudo vim /etc/systemd/system/mysql.service # or your editor of choice

Add the following lines to the bottom of the file:

将以下行添加到文件底部:

LimitNOFILE=infinity
LimitMEMLOCK=infinity

You could also set a numeric limit, eg LimitNOFILE=4510.

您还可以设置数字限制,例如LimitNOFILE=4510.

Now reload the Systemd configuration with:

现在重新加载 Systemd 配置:

sudo systemctl daemon-reload

Restart MySQL and it should now obey the max_connections directive.

重新启动 MySQL,它现在应该遵守 max_connections 指令。

I also had problems stopping MySQL cleanly after upgrading to 15.04. If this affects you (you'll know because it will take 300 seconds to time out when you do service mysql stopor service mysql restart) then adding the following line to the same /etc/systemd/system/mysql.service file fixed it for me:

升级到 15.04 后,我也遇到了干净地停止 MySQL 的问题。如果这对您有影响(您会知道,因为执行service mysql stop或时超时需要 300 秒service mysql restart)然后将以下行添加到相同的 /etc/systemd/system/mysql.service 文件中为我修复它:

ExecStop=/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown

This latter problem seems to have been fixed by 16.04 and this line is no longer required, so before you do a distribution upgrade you'll want to stop MySQL and remove the ExecStopline from the config file.

后一个问题似乎已在 16.04 中修复,并且不再需要此行,因此在进行发行版升级之前,您需要停止 MySQL 并ExecStop从配置文件中删除该行。

回答by Fredrik

As of MySQL 5.7.7, this is what the documentation recommends for Red Hat Enterprise Linux 7, Oracle Linux 7, CentOS 7, SUSE Linux Enterprise Server 12, Fedora 24 and 25:

从 MySQL 5.7.7 开始,这是文档为 Red Hat Enterprise Linux 7、Oracle Linux 7、CentOS 7、SUSE Linux Enterprise Server 12、Fedora 24 和 25 推荐的内容:

https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

On Ubuntu 16.04 the service is called mysql, not mysqld, so this is what I did:

在 Ubuntu 16.04 上,该服务被称为 mysql,而不是 mysqld,所以这就是我所做的:

sudo mkdir /etc/systemd/system/mysql.service.d
sudo vi /etc/systemd/system/mysql.service.d/override.conf

Added this in the new file override.conf:

在新文件 override.conf 中添加了这个:

[Service]
LimitNOFILE=5000

Then restarted the service:

然后重启服务:

sudo systemctl daemon-reload
sudo systemctl restart mysql

回答by Berend de Boer

I suggest you don't copy the existing mysql.service file as suggested, just create a file with only the changes you care about. So do:

我建议您不要按照建议复制现有的 mysql.service 文件,只需创建一个仅包含您关心的更改的文件。所以这样做:

mkdir /lib/systemd/system/mysql.service.d
vim /etc/systemd/system/mysql.service.d/limits.conf

And the contents of limits.conf is simply:

而limits.conf的内容很简单:

[Service]
LimitNOFILE=10000
LimitMEMLOCK=10000

or whatever limits you prefer.

或您喜欢的任何限制。

回答by amalesh

With systemd the file override.conf does not need to be searched for or possibly created. Just use the following command:

使用 systemd 文件 override.conf 不需要搜索或可能创建。只需使用以下命令:

sudo systemctl edit mysql

If the file override.conf exists, it is read in, otherwise it can be created now.

如果文件 override.conf 存在,则将其读入,否则现在可​​以创建。

The rest, as Frederik wrote: Enter LimitNOFILE and restart the services.

其余的,正如 Frederik 所写:输入 LimitNOFILE 并重新启动服务。