Ubuntu

Wordpress 多站點 Ubuntu 伺服器中的記憶體問題

  • January 5, 2016

我有一個 512MB RAM 和 512MB 交換文件的伺服器,託管一個 Wordpress 多站點(8 個網站)。每天訪問者不多(每個站點每天大約 50-100 人)。

現在,一切正常,我的記憶是這樣的:

$ free -m
            total       used       free     shared    buffers     cached
Mem:           484        300        183          0         12        102
-/+ buffers/cache:        185        298
Swap:          511         21        490

但是每天大約有兩次站點關閉,我什至無法在幾個/多個小時內對伺服器進行 ssh。直到伺服器發生某些事情並且它會自行重新啟動。

分析日誌,這或多或少是我得到的:

在 /var/log/mysql/error.log

160105 13:00:59 InnoDB: The InnoDB memory heap is disabled
160105 13:01:03 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160105 13:01:03 InnoDB: Compressed tables use zlib 1.2.8
160105 13:01:03 InnoDB: Using Linux native AIO
160105 13:02:11 InnoDB: Initializing buffer pool, size = 128.0M
160105 16:05:18 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
160105 16:05:19 [Note] Plugin 'FEDERATED' is disabled.
160105 16:05:19 InnoDB: The InnoDB memory heap is disabled
160105 16:05:19 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160105 16:05:19 InnoDB: Compressed tables use zlib 1.2.8
160105 16:05:19 InnoDB: Using Linux native AIO
160105 16:05:19 InnoDB: Initializing buffer pool, size = 128.0M
160105 16:05:19 InnoDB: Completed initialization of buffer pool
160105 16:05:19 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
160105 16:05:19  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...

在 var/log/apache2/error.log 這是我能看到的

[Mon Jan 04 13:10:12.538831 2016] [access_compat:error] [pid 18550] [client 178.170.253.10:61927] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:12:21.985186 2016] [access_compat:error] [pid 18550] [client 195.8.51.14:27348] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:12:44.698607 2016] [access_compat:error] [pid 20550] [client 176.124.168.83:52785] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:13:32.202567 2016] [access_compat:error] [pid 16906] [client 185.115.96.41:3342] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:13:52.323912 2016] [access_compat:error] [pid 19457] [client 176.51.88.244:4713] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:13:59.171594 2016] [access_compat:error] [pid 16906] [client 128.70.59.134:51542] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:15:01.406940 2016] [access_compat:error] [pid 19457] [client 178.136.213.198:57939] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:16:26.342924 2016] [access_compat:error] [pid 18550] [client 195.91.157.50:1994] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:17:40.552995 2016] [access_compat:error] [pid 22394] [client 84.18.126.78:6378] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:17:41.817137 2016] [access_compat:error] [pid 22393] [client 62.141.121.10:63297] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:18:18.672917 2016] [access_compat:error] [pid 22341] [client 178.140.252.61:62029] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:18:52.169060 2016] [access_compat:error] [pid 20550] [client 95.25.203.83:52487] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:19:27.421519 2016] [access_compat:error] [pid 22272] [client 95.32.218.30:2571] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 13:36:22.974166 2016] [evasive20:error] [pid 22341] [client 207.164.181.226:51490] client denied by server configuration: /var/www/images
[Mon Jan 04 13:36:22.996491 2016] [evasive20:error] [pid 22341] [client 207.164.181.226:51490] client denied by server configuration: /var/www/images
[Mon Jan 04 14:24:16.495532 2016] [access_compat:error] [pid 22343] [client 62.210.190.10:54167] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 14:24:16.542713 2016] [access_compat:error] [pid 22565] [client 62.210.190.10:62039] AH01797: client denied by server configuration: /var/www/wp-login.php
[Mon Jan 04 14:26:11.920278 2016] [:error] [pid 26081] [client 93.174.93.61:42308] WordPress database error Lost connection to MySQL server during query for query SELECT option_value FROM wp_options WHERE option_name = 'widget_calendar' LIMIT 1 made by include('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), call_user_func_array, wp_widgets_init, do_action('widgets_init'), call_user_func_array, WP_Widget_Factory->_register_widgets, WP_Widget->_register, WP_Widget->get_settings, get_option

我已經通過 IP(在 .htaccess 中)保護了對 wp-login 的訪問,以避免不必要的訪問。

在 /var/log/syslog 我可以看到

Jan  5 13:00:56 ssc2 kernel: [445243.554498] Out of memory: Kill process 17543 (apache2) score 8 or sacrifice child
Jan  5 13:00:56 ssc2 kernel: [445243.576303] Killed process 17543 (apache2) total-vm:256148kB, anon-rss:2400kB, file-rss:392kB
Jan  5 13:00:56 ssc2 kernel: [445244.608497] apache2 invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0

我在 /var/log/syslog 中也看到了多次重複:

Jan  5 12:48:48 ssc2 kernel: [444475.655836]  [<ffffffff81718e24>] dump_header+0x7f/0x1f1
Jan  5 12:48:48 ssc2 kernel: [444475.655841]  [<ffffffff81151ebe>] oom_kill_process+0x1ce/0x330
Jan  5 12:48:48 ssc2 kernel: [444475.655850]  [<ffffffff812d4815>] ? security_capable_noaudit+0x15/0x20
Jan  5 12:48:48 ssc2 kernel: [444475.655853]  [<ffffffff811525f4>] out_of_memory+0x414/0x450
Jan  5 12:48:48 ssc2 kernel: [444475.655857]  [<ffffffff8115896c>] __alloc_pages_nodemask+0xa5c/0xb80

我想我的交換記憶體快滿了,伺服器沒有響應,但在某些情況下它可以持續 7 個小時!!!

任何幫助,將不勝感激

您的伺服器正在耗盡您分配給它的記憶體。您將需要減少記憶體使用量(為 nginx 放棄 apache,將 MySQL 移動到不同的主機等)或向該伺服器添加更多 RAM。

引用自:https://serverfault.com/questions/746894