Mysql Tunning Server使用64 GB Ram占用50%的CPU

时间:2018-05-18 18:12:11

标签: mysql wordpress

我有一台64 GB Ram的专用服务器,运行Centos 7,包含4个内核和8个线程。

我主持了一些流量不足的wordpress网站。

总共约有20个网站,其中只有2-3个网站每天有1000个访问者

我的cpu负载大约是200% - 400%,而且这个用量的90%是由MySQL采用的

是的,有人能帮帮我吗?我有几天的研究和尝试优化,但我不知道。

my.cnf如下:

    [mysql]

# CLIENT #
port                           = 3306
socket                         = /home/mysql/mysql.sock

[mysqld]
local-infile                   = 0
performance_schema             = ON

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /home/mysql/mysql.sock
pid-file                       = /home/mysql/mysql.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover-options         = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000

# DATA STORAGE #
datadir                        = /home/mysql/

# BINARY LOGGING #
log-bin                        = /home/mysql/mysql-bin
expire-logs-days               = 2
sync-binlog                    = 1

# CACHES AND LIMITS #
tmp_table_size                 = 256M
max_heap_table_size            = 256M
query_cache_type               = 1
query_cache_size               = 128M
query_cache_limit              = 2M
max_connections                = 500
thread_cache_size              = 50
open-files-limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 4096


# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 5G
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 40G
innodb-buffer-pool-instances   = 40
join_buffer_size               = 4M


# LOGGING #
log-error                      = /home/mysql/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 0
slow-query-log-file            = /home/mysql/mysql-slow.log

1 个答案:

答案 0 :(得分:0)

为my.cnf-ini [mysqld]部分考虑的建议

max_connect_errors=10  # from 1000000 to limit hacker/cracker pw guessing
#join_buffer_size=4M  # lead to allow DEFAULT to work for you
innodb_buffer_pool_instances=8  # from 40  will serve you better than 40
innodb_lru_scan_depth=128  # from 1024 default
log_warnings=2  # for additional info in error log when aborted_connection

请参考innodb_lru_scan_depth描述的refman,以了解为什么8优于40。每个SECOND的CPU工作负载将被最小化。

提供所需的额外信息将允许更深入的分析。