我的伺服器遇到一些問題。我正處於高峰期,我的伺服器負載非常高。
我有 3 台伺服器,一台用於前端,一台用於資料庫(mysql),一台用於交付映像(這台沒問題)
以下是我目前的配置和 1500 名訪客的平均負載:
伺服器1(前端):
load average: 143.08, 120.50, 66.99
CentOS 6.3
Apache/2.2.15
8 x Intel(R) Xeon(R) CPU E5645 @ 2.40GHz
16GB RAM
httpd.conf
PidFile run/httpd.pid
Timeout 60
KeepAlive Off
MaxKeepAliveRequests 1000
KeepAliveTimeout 15
<IfModule prefork.c>
ServerLimit 520
StartServers 16
MinSpareServers 5
MaxSpareServers 20
MaxClients 500
MaxRequestsPerChild 1000
</IfModule>
<IfModule worker.c>
ServerLimit 520
StartServers 16
MaxClients 500
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
ExtendedStatus On
UseCanonicalName Off
HostnameLookups Off
ErrorLog logs/error_log
LogLevel warn
ServerSignature On
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
伺服器2(MySQL my.cnf)
load average: 12.84, 23.39, 22.85
CentOS 6.4
MYSQL 5.5.34
8 x Intel(R) Xeon(R) CPU E5645 @ 2.40GHz
16GB RAM
我的cnf
[mysqld]
port=3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections = 2000
key_buffer = 384M
query_cache_type=1
query_cache_size=512M
query_cache_limit=4M
innodb_buffer_pool_size = 8G
slow_query_log=1
slow_query_log_file=log-slow-queries.log
thread_cache_size=8
table_cache=128k
tmp_table_size=256M
max_heap_table_size=256M
init_connect='SET collation_connection = latin1_swedish_ci'
init_connect='SET NAMES latin1'
character-set-server=latin1
collation-server=latin1_swedish_ci
skip-character-set-client-handshake
log-error=/var/log/mysqld.error.log
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
mysqltuner 輸出
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.34-log
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in InnoDB tables: 3G (Tables: 57)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 57
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 5h 11m 15s (4M q [241.514 qps], 537K conn, TX: 11B, RX: 2B)
[--] Reads / Writes: 87% / 13%
[--] Total buffers: 9.1G global + 2.8M per thread (2000 max threads)
[OK] Maximum possible memory usage: 14.5G (46% of installed RAM)
[OK] Slow queries: 1% (55K/4M)
[OK] Highest usage of available connections: 37% (756/2000)
[OK] Key buffer size / total MyISAM indexes: 384.0M/96.0K
[OK] Key buffer hit rate: 100.0% (46K cached / 0 reads)
[!!] Query cache efficiency: 0.0% (0 cached / 2M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 480K sorts)
[OK] Temporary tables created on disk: 16% (112K on disk / 684K total)
[OK] Thread cache hit rate: 83% (87K created / 537K connections)
[OK] Table cache hit rate: 99% (2K open / 2K opened)
[OK] Open file limit used: 0% (19/264K)
[OK] Table locks acquired immediately: 100% (7M immediate / 7M locks)
[OK] InnoDB data size / buffer pool: 3.6G/8.0G
申請詳情
php 5.4 Symfony 1.2 資料庫大小:6GB
你能幫助我嗎?
答案1
我在這裡看到的主要問題是前端伺服器的平均負載較高。 MySQL 伺服器可以做得更好,但也沒有那麼糟。 Apache 伺服器經常成為瓶頸。如果不知道您的應用程式在做什麼,就很難解決問題。一般性建議如下:
- 在前端伺服器上設定 Munin,其中包含 Apache 的指標。有了這些訊息,您調整 Apache 就會容易得多。 Munin 還可以幫助您確定平均負載增加的頻率和時間。
- 分析 Apache 和您的應用程式日誌。最重和最頻繁的請求是什麼?可能存在一些與應用程式相關的問題(例如使用 PHP 提供靜態檔案)。
- 考慮切換到 nginx/php-fpm 而不是 Apache。 Apache 是非常好的網頁伺服器,但 nginx 成為了許多不需要某些特定 Apache 功能的現代設定的標準。
考慮MySQL優化。您只有 96.0K 的 MyISAM 索引,但有 384.0M 的鍵緩衝池。您可以安全地減少此參數。您也可以使用 Percona 的 pt-query-digest 檢查慢速查詢,這非常方便。