そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

【CentOS8】MariaDB(MySQL)エラー「Could not increase number of max_open_files/Changed limits: max_open_files」対処手順

※[PR]当ブログの記事の中にはプロモーションが含まれています。

CentOS8でMariaDB(MySQL)起動時のエラー「Could not increase number of max_open_files」「Changed limits: max_open_files」の対処手順

自宅ローカル開発環境のCentOS8サーバに、MariaDB10.3を入れていますが、
起動時にエラーが出ていたのでそのときの対処手順のメモです。

CentOS8上のMariaDBで「Could not increase number of max_open_files」「Changed limits: max_open_files」エラーが起きたときの対処手順を紹介します

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。
私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

前提条件

CentOS8に、MariaDB10.3を以下の記事の手順でインストールしてあります。

souiunogaii.hatenablog.com

検知したエラーメッセージ

SYSLOG監視に以下のエラーメッセージが出ていました。

[Warning] Could not increase number of max_open_files to more than 1024 (request: 4183)
[Warning] Changed limits: max_open_files: 1024  max_connections: 151 (was 151)  table_cache: 421 (was 2000)

プロセスのリミットを確認

 cat /proc/`pidof mysqld`/limits |grep "Max open files"
[root@sv-neptune ~]# cat /proc/`pidof mysqld`/limits |grep "Max open files"
Max open files            1024                 4096                 files
  • Soft Limit: 1024
  • Hard Limit: 4096

MariaDBのリミット値を確認

MariaDBにrootでログイン

mysql -uroot -p●●●●●●●●●●●
[root@sv-neptune ~]# mysql -uroot -p●●●●●●●●●●●
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

GLOBAL VARIABLES を確認

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%open_files_limit%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 1024  |
+------------------+-------+
1 row in set (0.001 sec)
MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%table_open_cache%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| table_open_cache           | 421   |
| table_open_cache_instances | 8     |
+----------------------------+-------+
2 rows in set (0.001 sec)
MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%max_connections%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| extra_max_connections | 1     |
| max_connections       | 151   |
+-----------------------+-------+
2 rows in set (0.001 sec)
MariaDB [(none)]> quit
Bye

mariadb.serviceの確認

cat /usr/lib/systemd/system/mariadb.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
#       .include /usr/lib/systemd/system/mariadb.service
#       ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mysql'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

# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload

# Use [mysqld.INSTANCENAME] as sections in my.cnf to configure this instance.

[Unit]
Description=MariaDB 10.3 database server
Documentation=man:mysqld(8)
Documentation=https://mariadb.com/kb/en/library/systemd/
After=network.target

[Install]
WantedBy=multi-user.target
Alias=mysql.service
Alias=mysqld.service

[Service]
Type=notify
User=mysql
Group=mysql

ExecStartPre=/usr/libexec/mysql-check-socket
# '%n' expands to 'Full unit name'; man systemd.unit
ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n
# MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb@.service.d/MY_SPECIAL.conf
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/libexec/mysqld --basedir=/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER
ExecStartPost=/usr/libexec/mysql-check-upgrade

# Setting this to true can break replication and the Type=notify settings
# See also bind-address mysqld option.
PrivateNetwork=false

KillMode=process
KillSignal=SIGTERM

# Don't want to see an automated SIGKILL ever
SendSIGKILL=no

# Restart crashed server only, on-failure would also restart, for example, when
# my.cnf contains unknown option
Restart=on-abort
RestartSec=5s

UMask=007

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

「open-files-limit」を増やしたいときの説明が書いてありました。

# For example, if you want to increase mysql'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

いちおう、Google翻訳に入れると以下でした。

#たとえば、mysqlのopen-files-limitを10000に増やしたい場合、
#systemdのLimitNOFILE設定を増やす必要があるので、
#ar「/etc/systemd/system/miadb.service.d/limits.conf」以下を含む:
#[サービス]
#LimitNOFILE = 10000

「/etc/systemd/system/mariadb.service.d/limits.conf」を作成

mkdir /etc/systemd/system/mariadb.service.d
vi /etc/systemd/system/mariadb.service.d/limits.conf
[root@sv-neptune ~]# mkdir /etc/systemd/system/mariadb.service.d
[root@sv-neptune ~]# vi /etc/systemd/system/mariadb.service.d/limits.conf
[root@sv-neptune ~]#
[Service]
LimitNOFILE=5000

MariaDBのサービス再起動

systemctl daemon-reload
systemctl restart mariadb.service
systemctl status mariadb
[root@sv-neptune ~]# systemctl daemon-reload
[root@sv-neptune ~]# systemctl restart mariadb.service
[root@sv-neptune ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           mqlimits.conf
   Active: active (running) since Sat 2020-06-13 16:09:51 JST; 11s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 8073 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 8003 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
  Process: 7979 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 8041 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 11110)
   Memory: 71.5M
   CGroup: /system.slice/mariadb.service
           mq8041 /usr/libexec/mysqld --basedir=/usr

 613 16:09:51 sv-neptune systemd[1]: Stopped MariaDB 10.3 database server.
 613 16:09:51 sv-neptune systemd[1]: Starting MariaDB 10.3 database server...
 613 16:09:51 sv-neptune mysql-prepare-db-dir[8003]: Database MariaDB is probably initialized in /var/lib/mysql alre>
 613 16:09:51 sv-neptune mysql-prepare-db-dir[8003]: If this is not the case, make sure the /var/lib/mysql is empty >
 6月 13 16:09:51 sv-neptune mysqld[8041]: 2020-06-13 16:09:51 0 [Note] /usr/libexec/mysqld (mysqld 10.3.17-MariaDB) sta>
 613 16:09:51 sv-neptune systemd[1]: Started MariaDB 10.3 database server.
lines 1-23/23 (END)

プロセスのリミットを確認

[root@sv-neptune ~]# cat /proc/`pidof mysqld`/limits |grep "Max open files"
Max open files            5000                 5000                 files

Soft LimitもHard Limitも5000まで引き上げられました。

MariaDBのリミット値を確認

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%open_files_limit%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 4183  |
+------------------+-------+
1 row in set (0.001 sec)
MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%table_open_cache%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| table_open_cache           | 2000  |
| table_open_cache_instances | 8     |
+----------------------------+-------+
2 rows in set (0.001 sec)
MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%max_connections%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| extra_max_connections | 1     |
| max_connections       | 151   |
+-----------------------+-------+
2 rows in set (0.001 sec)

それぞれの値が設定値いっぱいまで引き上げられたことが確認できました。

参考にしたサイト

https://www.denet.ad.jp/technology/2017/10/centos7mysql56.htmlwww.denet.ad.jp

インフラエンジニアになるための勉強のやり方

私は、某SIerに勤務しながら、WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

現在の会社で直接担当している業務の中では、決まった技術しか触れないけれど、
「他にも将来役に立ちそうなインフラ技術を勉強したい」「働きながらでもできる効率的なインフラエンジニアの勉強方法を知りたい」と考えている方のために、
①おすすめの書籍と、②おススメのオンライン学習サイトを紹介します。

働きながら勉強するための、おススメの書籍と、オンラインで学習できるサイトの紹介です。

インフラエンジニアの勉強ができるおススメ書籍

朝の通勤時や帰宅時の電車の中や、社外打合せへの移動中などに勉強するなら、やはり書籍が一番だと思います。

インフラエンジニアの教科書

LINE社に創業時から在籍しているインフラエンジニア・プロマネの「佐野裕」さんの本です。 twitter.com

膨大なトラフィックをさばくLINE社にて構築・保守を行っている現役エンジニアが記すITインフラの必須知識と経験の数々! サーバ、OS、ネットワーク機器、データセンター、購買と商談、障害対応、大規模インフラ、成長するために必要なスキルなど、基礎知識から実践まで言及。 ITインフラの世界が理解できる珠玉の1冊!

インフラエンジニアの教科書
(C&R研究所)
佐野裕

1週間でLPICの基礎が学べる本

Linuxの資格「LPIC」の試験対策を初心者向けに書いた入門書です。

Linuxの資格として広く知られているLPICですが、あまり知識の無いまま試験対策を始める人も多いのではないでしょうか。しかし、試験対策書は試験範囲についてのみ解説しているものが多く、初心者が理解するのは困難です。本書は、初心者がスムーズに試験対策を行えるよう、事前に基礎固めを行うLinux入門書です。試験情報や模擬問題も掲載しているので、資格取得を視野に入れた効率的な基礎学習が行えます。

1週間でLPICの基礎が学べる本
第3版 徹底攻略シリーズ
(インプレス)
中島能和

インフラエンジニアの勉強ができるオンライン学習サイト

Udemy (オンライン動画学習サイト)

Udemy(ユーデミー)は、オンラインで動画で学習できるサービスです。
ITエンジニア系の講座もたくさん公開されています。

≫Udemy 世界最大級のオンライン学習サイト

Udemyの特徴
  • ユーザー登録すれば、第1回の講座は無料で視聴できる
  • 無料のコンテンツもある
  • 過去に受講した人の人数や、受講した人の評価も表示されるので選びやすい

≫Udemy 世界最大級のオンライン学習サイト

開発の人気オンラインコース

以上、読んでいただきありがとうございました。