Điểm:2

MYSQL is at 197% CPU usage ~ not allowing site to run

lá cờ cn

Spec: 8 GB memory / 4 vCPUs / 25 GB ssd

Ubuntu 20.04

My website got hit with a DDoS recently and had this continuous high CPU usage error for 4 days and the site will not load up, I take a look using top -c and it showed 200% CPU usage. I tried SQL tuner but I did not see any significant differences and my site is not able to load up

MySQL Tuner:

 >>  MySQLTuner 1.8.5 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.pl/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from Debian maintenance account.
[OK] Currently running supported MySQL version 8.0.27-0ubuntu0.20.04.1
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ---------------------------------------------
[OK] Log file /var/log/mysql/error.log exists
[--] Log file: /var/log/mysql/error.log(108K)
[OK] Log file /var/log/mysql/error.log is not empty
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb
[OK] Log file /var/log/mysql/error.log is readable.
[!!] /var/log/mysql/error.log contains 649 warning(s).
[!!] /var/log/mysql/error.log contains 13 error(s).
[--] 46 start(s) detected in /var/log/mysql/error.log
[--] 1) 2021-11-13T12:29:09.246704Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27-0ubuntu0.20.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
[--] 2) 2021-11-13T12:29:09.246582Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 3) 2021-11-13T12:27:00.187056Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27-0ubuntu0.20.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
[--] 4) 2021-11-13T12:27:00.187031Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 5) 2021-11-13T12:13:39.810528Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27-0ubuntu0.20.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
[--] 6) 2021-11-13T12:13:39.810486Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 7) 2021-11-13T12:03:24.613973Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27-0ubuntu0.20.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
[--] 8) 2021-11-13T12:03:24.613816Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 9) 2021-11-13T12:01:03.461232Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 10) 2021-11-13T12:01:03.460896Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27-0ubuntu0.20.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
[--] 28 shutdown(s) detected in /var/log/mysql/error.log
[--] 1) 2021-11-13T12:29:07.716280Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 2) 2021-11-13T12:26:58.372900Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 3) 2021-11-13T12:13:38.455249Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 4) 2021-11-13T12:13:35.420337Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 5) 2021-11-13T12:13:32.532833Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 6) 2021-11-13T12:13:29.484351Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 7) 2021-11-13T12:13:26.096897Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 8) 2021-11-13T12:13:22.906304Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 9) 2021-11-13T12:03:23.022603Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).
[--] 10) 2021-11-13T12:01:01.884057Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27-0ubuntu0.20.04.1)  (Ubuntu).

-------- Storage Engine Statistics ---------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 114.8M (Tables: 56)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics ---------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ---------------------------------------------
[--] Skipped due to unsupported feature for MySQL 8

-------- CVE Security Recommendations ---------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics ---------------------------------------------
[--] Up for: 13m 19s (1M q [1K qps], 12K conn, TX: 7G, RX: 136M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory     : 7.8G
[--] Max MySQL memory    : 9.8G
[--] Other process memory: 0B
[--] Total buffers: 288.0M global + 97.6M per thread (100 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 9.9G (127.46% of installed RAM)
[!!] Maximum possible memory usage: 9.8G (126.23% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (15/1M)
[!!] Highest connection usage: 100%  (101/100)
[OK] Aborted connections: 0.00%  (0/12875)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[--] Query cache have been removed in MySQL 8
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 50K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (0 on disk / 12K total)
[OK] Thread cache hit rate: 89% (1K created / 12K connections)
[OK] Table cache hit rate: 99% (3M hits / 3M requests)
[OK] table_definition_cache(2000) is upper than number of tables(382)
[OK] Open file limit used: 0% (3/10K)
[OK] Table locks acquired immediately: 100% (4 immediate / 4 locks)
[OK] Binlog cache memory access: 100.00% (7 Memory / 7 Total)

-------- Performance schema ---------------------------------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ---------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ---------------------------------------------
[--] MyISAM Metrics are disabled on last MySQL versions.

-------- InnoDB Metrics ---------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 128.0M/114.8M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal to 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 100.00% (58007737 hits/ 58009344 total)
[!!] InnoDB Write Log efficiency: 89.57% (799 hits/ 892 total)
[OK] InnoDB log waits: 0.00% (0 waits / 93 writes)

-------- Aria Metrics ---------------------------------------------
[--] Aria Storage Engine not available.

-------- TokuDB Metrics ---------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ---------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ---------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics ---------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------
General recommendations:
    Check warning line(s) in /var/log/mysql/error.log file
    Check error line(s) in /var/log/mysql/error.log file
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Reduce or eliminate persistent connections to reduce connection usage
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: 
Variables to adjust:
  *** MySQL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MySQL buffer variables ***
    max_connections (> 100)
    wait_timeout (< 30)
    interactive_timeout (< 28800)
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
Marat Gainutdinov avatar
lá cờ cz
bạn có thể hiển thị đầu ra cho nhật ký chậm không?
lá cờ ua
CPU cao có nghĩa là truy vấn được lập chỉ mục kém và/hoặc được viết kém. Tìm truy vấn chậm đó và hỏi trong stackoverflow.com với các thẻ [mysql] [performance] .
Wilson Hauck avatar
lá cờ jp
Vì vậy, trong khoảng thời gian từ 12;01 đến 12:29, bạn có 5 'Sẵn sàng kết nối" từ những gì hiển thị trong báo cáo mysqltuner. Có vẻ như bạn có chưa đến 10 phút trước khi tự động khởi động lại. Nhận xét tiếp theo của tôi (trong vòng chưa đầy 5 phút ) sẽ là yêu cầu dữ liệu được thu thập sau 5 phút sau khi 'bắt đầu'.
Điểm:1
lá cờ ua

Giải pháp tạm thời: Thay đổi innodb_buffer_pool_size đến 1G. Để có giải pháp lâu dài hơn, hãy tìm truy vấn nào chậm và hỏi về truy vấn đó onstackoverflow.com

Đăng câu trả lời

Hầu hết mọi người không hiểu rằng việc đặt nhiều câu hỏi sẽ mở ra cơ hội học hỏi và cải thiện mối quan hệ giữa các cá nhân. Ví dụ, trong các nghiên cứu của Alison, mặc dù mọi người có thể nhớ chính xác có bao nhiêu câu hỏi đã được đặt ra trong các cuộc trò chuyện của họ, nhưng họ không trực giác nhận ra mối liên hệ giữa câu hỏi và sự yêu thích. Qua bốn nghiên cứu, trong đó những người tham gia tự tham gia vào các cuộc trò chuyện hoặc đọc bản ghi lại các cuộc trò chuyện của người khác, mọi người có xu hướng không nhận ra rằng việc đặt câu hỏi sẽ ảnh hưởng—hoặc đã ảnh hưởng—mức độ thân thiện giữa những người đối thoại.