เว็บบน DigitalOcean มันชอบบอกว่า monitoring resolved: Memory Utilization is running high กับ NAS server ที่บ้าน ram แค่ 1 GB มันต๊อแต๊ อยากจะสลบอยู่ตลอด เลยต้อง configuration เพิ่มประสิทธิภาพใหม่ให้มันทำงานได้ โดยใช้ MySQLTuner ที่จะช่วยปรับแต่ง database server ได้หลายตัวทั้ง Galera, MariaDB, MySQL, Percona
- ก่อนอื่นก็ download MySQLTuner มาช่วยตรวจสอบการติดตั้งที่เหมาะสมก่อนโดยใช้ command
wget http://mysqltuner.pl/ -O mysqltuner.pl
- เรียกใช้โดย
perl mysqltuner.pl
จะเห็นข้อความที่จะต้องใช้ในการปรับแต่ง MySql หรือดาต้าเบสตัวอื่น ๆ โดยให้ดูบรรทัดที่ขึ้นต้นด้วย [!!] เป็นหลัก
- หาว่า config ของ mariadb / mysql อยู่ที่ไหนโดยคำสั่ง
mysqld --help --verbose | grep -A 1 "Default options"
- แก้มายเอสคิวเอล และเทสโดยคำสั้ง
mysqld --validate-config
sudo systemctl restart mysql.service
perl mysqltuner.pl
วนไปจนกว่าจะได้ performance ที่พอใจ
- ตัวอย่างไฟล์ config ที่ได้สำหรับ NAS ที่มี ram 1 GB
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * 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/
!includedir /etc/mysql/mysql.conf.d/
#test by mysqltuner
[mysqld]
# Skip reverse DNS lookup of clients.
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_skip_name_resolve
skip-name-resolve
# Ratio InnoDB redo log capacity / InnoDB Buffer pool size should be equal to 25%.
#https://dev.mysql.com/doc/refman/8.0/en/innodb-buffer-pool-resize.html
#of RAM but beware of setting memory usage too high
innodb_buffer_pool_size=300M
#https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_connections
max_connections=70
นอกจากนี้ คำสั่ง perl mysqltuner.pl ยังสามารถใช้ options เพิ่มเติมได้อีก เช่น
| options | ความหมาย | ค่าเริ่มต้น | ตัวอย่าง | ชนิดตัวแปร |
| –debug | debugging information | | | |
| –dumpdir | export to | | –dumpdir=./result | file path |
| –forcemem | แรมทั้งหมด | 1024 | –forcemem 32768 | megabytes |
| –forceswap | swap memory | | –forceswap 16384 | megabytes |
| –host | remote server | localhost | –host 127.0.0.1 | IP |
| –json | ออกรายงานเป็น JSON | | –json > reports.json | file path |
| –outputfile | ออกรายงานเป็นไฟล์ | | –outputfile /tmp/result_mysqltuner.txt | file path |
| –pass, –password | รหัสผ่าน | | –pass admin_password | string |
| –port | port | 3306 | –port 3306 | int |
| –socket | ใช้ socket ต่างออกไปสำหรับ localhost | | | |
| –user | username | | –user admin_user | string |
| –verbose | รายละเอียด | | –verbose | |
options บางส่วนที่สามารถใช้ได้
อ่านเพิ่มเติม