Centos 7,WHM高Mysql&MariaDB CPU使用率%600

时间:2018-11-28 19:23:44

标签: mysql mariadb

我有问题。 我的网站很慢 我认为是mysql。 最多可连接100个用户。 在大多数情况下为30-40人。

我的服务器:

  • 英特尔至强E3-1230v3

  • 16 GB DDR3 Ram

  • 240 GB OCZ SSD磁盘

  • Centos 7 WHM-cPanel MariaDB

...

PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
12496 mysql   20   0   14.1g   1.3g  12228 S 576.1  8.2 116:38.62 

/ usr / sbin / mysqld

/etc/my.cnf:

port        = 1905
socket      = /var/lib/mysql/mysql.sock

# The MySQL Safe server
[mysqld_safe]
open_files_limit = 58000
# The MySQL server
[mysqld]
max_connections = 300
local-infile    = 0
socket      = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 1024M
table_open_cache = 4096
open_files_limit = 40960
max_allowed_packet=1073741824
sort_buffer_size = 4M
read_buffer_size = 4M
join_buffer_size = 4M
sort_buffer_size = 4M
read_rnd_buffer_size = 128M
myisam_sort_buffer_size = 128M
thread_cache_size = 16
#query_cache_size= 32M
tmp_table_size = 64M
max_heap_table_size = 64M

#table_cache    = 1024

#Slowly log
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
long_query_time = 1

# Uncomment the following if you are using InnoDB tables
innodb_file_per_table= 1
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:50M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 8096M
#innodb_additional_mem_pool_size = 64M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

# Connection Settings
wait_timeout = 60
skip-external-locking



[mysqldump]
quick
max_allowed_packet = 64M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 256M
read_buffer = 8M
write_buffer = 8M
# Query Cache Settings
query_cache_type = 1
query_cache_limit = 256K
query_cache_min_res_unit = 2k
query_cache_size = 80M
skip-external-locking

[mysqlhotcopy]
interactive-timeout

我该怎么办?

谢谢。

3 个答案:

答案 0 :(得分:1)

底线:添加一些索引会很有帮助:

INDEX(islemkey)
INDEX(site, durum, islem_baslangic)
INDEX(durum, site, site_durum, id)

详细信息

UPDATE odemeler SET step='odeme_kontrol' WHERE islemkey = '78TNgyacgjwt'

您需要在INDEX(islemkey)上使用odemeler

`expire` varchar(255) DEFAULT NULL,
AND islem_baslangic LIKE '2018-11-29%'

如果expireDATEDATETIME,则应声明为islem_baslangic。如果采用某些非标准日期格式,则需要进行转换。 SELECT * FROM odemeler WHERE site = '71' AND durum = '1' 和其他任何包含日期的列也一样。

odemeler

INDEX(site, durum)需要此复合SELECT id,tcno, miktar,durum,islem_baslangic,site,site_durum FROM odemeler WHERE site = '74' AND durum = '1' AND site_durum = '0' ORDER BY id DESC LIMIT 20 ;可选地,它们可以以相反的顺序列出。

INDEX(site, durum, site_durum,  -- in any order
      id)   -- last

需要

PROCESSLIST

原因

在没有可用索引的情况下,PROCESSLIST中显示的大多数查询必须扫描整个表。这会占用大量CPU。而且它会减慢每个查询的速度。然后查询堆积。 (一次在scatter中有很多查询。)

有了可用的索引,每个查询的来来去去更快,并且使用的CPU更少。这就是索引的目的!

答案 1 :(得分:0)

以root用户登录WHM,在Multi PHP manager中,将网站切换到PHP 7.1。 为该特定网站启用php-fpm。

第二,下载mysql调谐器脚本,该脚本将帮助您调整/etc/my.cnf设置以获得最佳的mysql性能。

如果即使进行了所有这些更改后一切仍然无法正常工作,则您将不得不优化mysql数据库。

答案 2 :(得分:0)

每秒速率= RPS建议,用于my.cnf [mysqld]部分以提高性能,

read_rnd_buffer_size=256K  # from 128M to reduce handler_read_rnd_next RPS from 6 million +
innodb_io_capacity=1900  # from 200 to enable more of your SSD io capacity
thread_cache_size=100  # from 16 to reduce threads_created count of 24,136 in 8 hrs
aria_pagecache_buffer_size=64M  # from 128M to conserve RAM, only 2 blocks used in 8 hrs
key_buffer_size=128M  # from 1G to conserve RAM, 15M used was the High Water Mark

Aras and Furkan,如果仍未创建索引(由Rick James建议),请发表评论,表明您需要此请求的帮助,以通过索引管理来提高性能。