无法在 centos7 上的 mariadb 10 中增加打开文件限制

cannot increase open-files-limit in mariadb 10 on centos7

我搜索了主题并测试了选项,但我仍然无法增加用作 cpanel/whm 服务器的远程数据库服务器的 mariadb 服务器上的打开文件限制。 这是很好的参考 http://duntuk.com/how-raise-ulimit-open-files-and-mysql-openfileslimit

我在

增加了它
/etc/my.cnf 

open-files-limit=65550

这是一些结果

#ulimit -a 
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 63471
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 65535
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited

最大用户进程数 (-u) 65535 虚拟内存(千字节,-v)无限制 文件锁 (-x) 无限制

#ulimit -Hn -Sn                              
open files                      (-n) 65535
open files                      (-n) 65535

cat /etc/systemd/system/mariadb.service.d/limits.conf 
[Service]
LimitNOFILE=65500

cat /usr/lib/systemd/system/mariadb.service

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql
LimitNOFILE=infinity
LimitMEMLOCK=infinity

并且还在 mysql 我得到

显示全局变量,如 'open%';

+----------------+--------+

| Variable_name |值 |

+----------------+--------+

| open_files_limit | 1024 |

+----------------+--------+

一组中的 1 行(0.00 秒)

我在重新启动后一遍又一遍地收到以下错误

60108 16:30:02 [ERROR] mysqld: Can't open file: './username_wp/wp_users.frm' (errno: 24)
160108 16:30:02 [ERROR] Error in accept: Too many open files
160108 16:30:04 [ERROR] Error in accept: Too many open files
160108 16:30:06 [ERROR] Error in accept: Too many open files
160108 16:30:11 [ERROR] mysqld: Can't open file: './username_db/strikes.frm' (errno: 24)

这里是mariadb的启动日志

[Warning] Could not increase number of max_open_files to more than 1024 (request: 132107)

这是一个 OS 问题。

我认为你必须增加 /etc/security/limits.conf 中的 "hard limit",像这样:

* hard nofile 65536
* soft nofile 16384

然后使用ulimit增加"soft limit"。

终于我找到了解决方案,但没有任何合理的原因! 我是 运行 MariaDB 5.5,所有设置都很好,但软限制不超过 1024! 我以为我的 mariadb 是 10.0,因为我刚安装它

在我发现它是 5.5 之后,我尝试将它升级到 v10.0!然后砰!无需任何额外操作或设置即可解决问题(内核设置允许最大文件限制,如参考文献 link 中所述)

我希望它能帮助其他人遇到同样的问题(但在尝试所有其他必需的设置之后)

在mariadb.service文件中可以看到官方说明;

[root@db1 system]# cat /usr/lib/systemd/system/mariadb.service | grep exam -A 5
# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#       [Service]
#       LimitNOFILE=10000

虽然我觉得应该写在official manual...

RH/CentOS mariadb 集成非常混乱,在某些地方使用 mariadb 作为其名称,在其他地方使用 mysqld...
您应该编辑(或创建)一个 .conf 文件 /etc/systemd/system/mariadb.service.d/ 例如:/etc/systemd/system/mariadb.service.d/centreon.conf

然后按照kujiy的建议进行编辑

[Service]
LimitNOFILE=320000

不要忘记重新加载 systemd 服务文件:

# systemctl daemon-reload

塞德里克

我从 official repo 安装了带有 MariaDB 10.0.29 的 CentOS 7.3。

出于某种原因,systemd 单元被命名为 mysql,我不得不创建 /etc/systemd/system/mysql.service.d/oioki.conf:

[Service]
LimitNOFILE=500000

之后别忘了运行systemctl daemon-reload

我遇到了这个问题 运行使用软件集 (SCL) 和 SystemD

使用 RedHat Enterprise Linux 7.2
rh-mariadb100-mariadb-server-10.0.20-1.el7.x86_64

在我的情况下,硬限制没问题,但软限制卡在 1024

新旧总结

old : RHEL6.x : MySQL : init.d : mysql_safe : 'root', mysqld : 'mysql'
new : RHEL7.x : MariaDB : SystemD : mysql_safe : 'mysql', mysqld 'mysql'

请注意,旧的 initl.d 包装脚本 运行 作为 root,但新的 SystemD 包装脚本 运行 作为 'mysql'。这会导致 mysql_safe 无法调用 ulimit。在我的例子中,在 SystemD 中设置 LimitNOFILE 没有帮助——它所做的只是增加包装器的文件限制,而不是守护进程本身。 我找到了一个两步过程来让它工作

第 1 步 - 将 mysqld_safe 部分重新设置到 conf 文件,以便 mysql_safe 读取它

sudo vi /etc/opt/rh/rh-mariadb100/my.cnf.d/mariadb-server.cnf
[mysqld_safe]
open_files_limit=2048

第 2 步 - 创建一个 SystemD 插件以以 root 身份启动包装器(守护进程仍将 运行 作为 'mysql')。请注意,LimitNOFILE 已被注释掉。

/etc/systemd/system
mkdir rh-mariadb100-mariadb.service.d
cd rh-mariadb100-mariadb.service.d
vi limits.conf
[Service]
#LimitNOFILE=2048
User=
Group=

重新加载 SystemD 服务文件

systemctl daemon-reload

现在重新启动服务,检查 mysql 客户端中 open_files_limit 的值 现在应该说 2048(新的软限制)

正确的解决方案可能是摆脱包装器并使用本机 SystemD。

更新 看起来这在最新版本中已修复,不再使用 mysql_safe 包装器

rh-mariadb101-mariadb-10.1.19-6.el7.x86_64

要在 Centos 7 上的 MySQL 5.6 中增加打开文件限制,您必须:

nano /usr/lib/systemd/system/mysqld.service

在文件末尾添加:

LimitNOFILE=65535
LimitNPROC=65535

然后:

systemctl daemon-reload
systemctl restart mysqld

完成! ,我假设对于 MariaDB 来说是一样的

open_files_limit 是取决于下一个参数的动态值:

#my.cnf file

# max connections
max_connections = 64
# table_open_cache = max_connections * tables used in one transaction + 5
table_open_cache = 800
# table_definition_cache = all tables(50) + max_connections + 5
table_definition_cache = 400
# open_files_limit = table_open_cache * 1.4
open_files_limit = 1120

要检查 open_files_limit 的值 运行 此命令来自 mysql:

mysql> select @@open_files_limit;

...它将输出:

+--------------------+
| @@open_files_limit |
+--------------------+
|              12903 |
+--------------------+
1 row in set (0.000 sec)

确保没有其他文件存在于: /etc/systemd/system/mariadb.service.d 可能限制文件数量的文件夹。 那是我的情况,还有另一个文件减少了我设置的限制:)