我的站目前都放在DigitalOcean上的1G VPS上面。除了这个博客还跑另外两个博客,都是跑在docker上,本想着1G内存足够了,没想到ghost退出过好几次,通过查log和监控发现,都是因为内存不够用被kill了。后来发现是mysql的配置还是默认配置,没有针对小内存优化过,所以很吃内存。不多说了,直接上配置。
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid-file = /var/lib/mysql/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
skip-name-resolve
innodb = FORCE
# DATA STORAGE #
datadir = /var/lib/mysql/
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 512M
# LOGGING #
log-error = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
最后的慢查询部分可以根据你自己的需要调整下值,或者干脆关闭了。
via.https://www.pangxiekr.com/1g-vpsshang-mysql-pei-zhi-you-hua/