MariaDB 10とCentOS 7の意外な関係!?open_files_limit設定で知っておくべき重要ポイント
CentOS 7 で MariaDB 10 を使用する場合、open_files_limit
をデフォルトの 1024 から増やせないことがあります。これは、MariaDB が多くのファイルを開く必要がある場合に問題が発生する可能性があります。
解決策
この問題を解決するには、以下の 2 つの方法があります。
systemd サービスファイルを変更する
/etc/systemd/system/mariadb.service.d/
ディレクトリに移動します。- 以下のコマンドを実行して、新しい設定ファイルを作成します。
sudo systemctl edit mariadb.service
- 開いたファイルに以下の行を追加します。
[Service]
LimitNOFILE=65535
- ファイルを保存して閉じます。
sudo systemctl reload mariadb.service
/etc/security/limits.conf ファイルを変更する
- 以下の行を追加します。
mariadb soft nofile 65535
mariadb hard nofile 65535
sudo systemctl restart mariadb.service
注意事項
- 上記のいずれの方法を使用する前に、MariaDB を停止していることを確認してください。
open_files_limit
を変更する前に、現在の値を確認してください。open_files_limit
をあまり大きく増やしすぎると、システムのパフォーマンスに影響を与える可能性があることに注意してください。
補足
上記の方法は、MariaDB 10.1 以降の場合にのみ適用されます。MariaDB 10.0 以前の場合は、/etc/my.cnf
ファイルで open_files_limit
設定を変更する必要があります。
また、CentOS 8 以降を使用している場合は、systemd
サービスファイルの代わりに /etc/sysctl.conf
ファイルを変更する必要があります。
Example 1: Modifying the systemd service file
# Create a new configuration file for the MariaDB systemd service
sudo systemctl edit mariadb.service
# Add the following line to the end of the file to set the open_files_limit to 65535
[Service]
LimitNOFILE=65535
# Save and close the file
# Reload the systemd configuration
sudo systemctl reload mariadb.service
Example 2: Editing the /etc/security/limits.conf file
# Open the `/etc/security/limits.conf` file for editing
sudo nano /etc/security/limits.conf
# Add the following lines to the end of the file to set the open_files_limit for the `mariadb` user
mariadb soft nofile 65535
mariadb hard nofile 65535
# Save and close the file
# Restart the MariaDB service
sudo systemctl restart mariadb.service
Example 3: Setting the open_files_limit in the /etc/my.cnf file (for MariaDB 10.0 and earlier)
# Open the `/etc/my.cnf` file for editing
sudo nano /etc/my.cnf
# Add the following line to the `[mysqld]` section to set the open_files_limit to 65535
open_files_limit=65535
# Save and close the file
# Restart the MariaDB service
sudo systemctl restart mariadb.service
Additional notes:
- Make sure to stop the MariaDB service before making any changes to the configuration files.
- Verify the current value of the
open_files_limit
before increasing it. - Increasing the
open_files_limit
too high can impact system performance. - These examples are for CentOS 7; for other versions of CentOS or MariaDB, the configuration files and settings may differ.
Please let me know if you have any other questions.
Other Methods for Increasing the open_files_limit for MariaDB 10 on CentOS 7
Using the ulimit Command
The ulimit
command can be used to temporarily set the open_files_limit
for the current user session. This can be useful if you need to increase the limit for a specific task or troubleshooting purpose.
To set the open_files_limit
to 65535 for the current session, use the following command:
ulimit -n 65535
This will only affect the current session and will not persist after the session is closed.
Using the sysctl Command
The sysctl
command can be used to modify kernel parameters, including the open_files_limit
. This method will make the change persistent across reboots.
sudo sysctl -w fs.file-max=65535
This will set the open_files_limit
for the entire system.
Some system configuration tools, such as Webmin
or EasyAdmin
, may provide a graphical interface for managing system settings, including the open_files_limit
. This can be a more user-friendly option for those who prefer not to use command-line tools.
Additional Considerations
- Before increasing the
open_files_limit
, make sure you understand the potential impact on system performance. Excessive use of file descriptors can lead to resource exhaustion and performance issues. - If you are unsure about the appropriate value for the
open_files_limit
, consult the MariaDB documentation or seek assistance from a system administrator. - Consider using a more granular approach, such as setting the limit for the specific MariaDB user or process, rather than increasing the global limit for all users and processes.
I hope this provides additional information and options for increasing the open_files_limit
for MariaDB 10 on CentOS 7. Please let me know if you have any further questions.
mysql mariadb