我有一台 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 保护了对 wp-login 的访问(在 .htaccess 中),以避免不良访问。
在 /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 个小时!!!
任何帮助,将不胜感激
答案1
您的服务器正在耗尽您为其分配的内存。您需要减少内存使用量(放弃 apache 转而使用 nginx、将 MySQL 移至其他主机等)或为此服务器添加更多 RAM。