เว็บบน 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 หรือดาต้าเบสตัวอื่น ๆ โดยให้ดูบรรทัดที่ขึ้นต้นด้วย [!!] เป็นหลัก - แก้มายเอสคิวเอล และเทสโดยคำสั้ง
mysqld --validate-config
sudo systemctl restart mysql.service
perl mysqltuner.pl
วนไปจนกว่าจะได้ performance ที่พอใจ - ตัวอย่างไฟล์ config ที่ได้สำหรับ NAS ที่มี ram 1 GB
/etc/mysql/my.conf 123456789101112131415161718192021222324252627282930313233343536#
# 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
#
# * 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.
skip-name-resolve
# Ratio InnoDB redo log capacity / InnoDB Buffer pool size should be equal to 25%.
#of RAM but beware of setting memory usage too high
innodb_buffer_pool_size=300M
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 |
อ่านเพิ่มเติม