Linux

CentOS 6 上的 Apache 無響應

  • April 1, 2015

今天早上兩次,今天早上的某個地方,然後在早上 8 點到 9 點左右,我們的 Apache 伺服器沒有響應,儘管服務顯示為正在執行。我們使用 service httpd restart 重置它,這似乎解決了問題。在此之前,我們的伺服器已經執行了大約三個月。

我閱讀了另一篇文章並將 MaxClients 和其他一些值從 256 更改為 512,因為有一個“

$$ error $$伺服器達到 MaxClients 設置,考慮提高 MaxClients 設置”顯示,但那是在今天上午 9:05。今天早上早些時候沒有顯示“崩潰”。 這是一些目前的error_log:

[Tue Mar 31 01:22:11 2015] [error] [client 192.187.126.162] script '/home/www/www.pixelark.com/www/wp-login.php' not found or unable to stat
[Tue Mar 31 02:09:13 2015] [error] [client 198.252.44.11] File does not exist: /home/www/www.pixelark.com/www/player.vimeo.com
[Tue Mar 31 02:09:13 2015] [error] [client 198.252.44.11] File does not exist: /home/www/www.pixelark.com/www/player.vimeo.com
[Tue Mar 31 02:32:59 2015] [error] [client 188.165.233.228] File does not exist: /home/www/www.pixelark.com/www/calvarycch
[Tue Mar 31 02:34:29 2015] [error] [client 27.104.199.92] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 02:37:19 2015] [error] [client 66.74.91.61] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon-precomposed.png
[Tue Mar 31 02:37:19 2015] [error] [client 66.74.91.61] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 02:57:31 2015] [error] [client 173.184.225.8] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 07:36:29 2015] [notice] caught SIGTERM, shutting down
[Tue Mar 31 07:36:29 2015] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Tue Mar 31 07:36:29 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Mar 31 07:36:29 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 07:36:29 2015] [notice] Digest: generating secret for digest authentication ...
[Tue Mar 31 07:36:29 2015] [notice] Digest: done
[Tue Mar 31 07:36:30 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 07:36:30 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Tue Mar 31 07:44:21 2015] [error] [client 68.6.150.73] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon-120x120-precomposed.png


[Tue Mar 31 08:23:02 2015] [error] [client 172.56.0.75] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon-precomposed.png
[Tue Mar 31 08:23:02 2015] [error] [client 172.56.0.75] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 08:45:35 2015] [error] [client 173.208.203.138] File does not exist: /home/www/www.pixelark.com/www/readme.asp
[Tue Mar 31 08:56:53 2015] [error] [client 184.176.137.140] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon-precomposed.png
[Tue Mar 31 08:56:53 2015] [error] [client 184.176.137.140] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 09:05:13 2015] [error] server reached MaxClients setting, consider raising the MaxClients setting
[Tue Mar 31 09:11:54 2015] [notice] caught SIGTERM, shutting down
[Tue Mar 31 09:11:55 2015] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Tue Mar 31 09:11:55 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Mar 31 09:11:55 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:11:55 2015] [notice] Digest: generating secret for digest authentication ...
[Tue Mar 31 09:11:55 2015] [notice] Digest: done
[Tue Mar 31 09:11:55 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:11:55 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Tue Mar 31 09:17:13 2015] [notice] caught SIGTERM, shutting down
[Tue Mar 31 09:17:13 2015] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Tue Mar 31 09:17:13 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Mar 31 09:17:14 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:17:14 2015] [notice] Digest: generating secret for digest authentication ...
[Tue Mar 31 09:17:14 2015] [notice] Digest: done
[Tue Mar 31 09:17:14 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:17:14 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Tue Mar 31 09:20:04 2015] [error] [client 107.143.147.89] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon-precomposed.png
[Tue Mar 31 09:20:05 2015] [error] [client 107.143.147.89] File does not exist: /home/www/www.pixelark.com/www/apple-touch-icon.png
[Tue Mar 31 09:23:15 2015] [notice] caught SIGTERM, shutting down
[Tue Mar 31 09:21:07 2015] [notice] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Tue Mar 31 09:21:07 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Mar 31 09:21:08 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:21:08 2015] [notice] Digest: generating secret for digest authentication ...
[Tue Mar 31 09:21:08 2015] [notice] Digest: done
[Tue Mar 31 09:21:09 2015] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Tue Mar 31 09:21:09 2015] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Tue Mar 31 09:21:12 2015] [error] [client 119.74.155.16] File does not exist: /home/www/www.pixelark.com/www/cscc, referer: http://pixelark.com/cscc/recent/mobile/mobile
[Tue Mar 31 09:24:18 2015] [error] [client 119.74.155.16] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/www/www.pixelark.com/db.php on line 9
[Tue Mar 31 09:24:18 2015] [error] [client 119.74.155.16] PHP Warning:  mysql_select_db() expects parameter 2 to be resource, boolean given in /home/www/www.pixelark.com/db.php on line 10
[Tue Mar 31 09:24:18 2015] [error] [client 119.74.155.16] PHP Warning:  mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/www/www.pixelark.com/www/mobile_controller/index.php on line 23
[Tue Mar 31 09:24:18 2015] [error] [client 119.74.155.16] PHP Warning:  mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /home/www/www.pixelark.com/www/mobile_controller/index.php on line 23
[Tue Mar 31 09:24:18 2015] [error] [client 119.74.155.16] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/www/www.pixelark.com/www/mobile_controller/index.php on line 29

您將需要更多資訊來調試它,例如當時連接的客戶端數量以及凍結時正在使用哪些頁面。

通常,只有在應用程序端的錯誤出現問題時才會達到 MaxClients——客戶端會請求一個頁面,而應用程序需要很長時間才能響應客戶端。根據我的經驗,當最近的程式碼更改引入了錯誤,或者當應用程式碼依賴於數據庫或文件系統,並且該數據庫或文件系統很慢或不可用等時,這個問題就會蔓延。這在 Apache 中很少出現問題本身。有許多可能的應用程序端原因。

如果瓶頸是文件系統或數據庫,您可能通過將 MaxClients 從 256 提高到 512 使問題變得更糟,因為現在您有兩倍的客戶端連接到有問題的資源。

從 Apache 的角度提供對問題的更多可見性:

  1. 查看 Apache 訪問日誌以確定哪些頁面最受歡迎。
  2. 啟用mod_status將列印伺服器性能資訊,並將列印有關所有目前會話的資訊。啟用,如使用伺服器狀態進行故障排除ExtendedStatus部分所建議的那樣。出於安全原因,請限制對一組安全 IP 地址的訪問。
  3. 在http://your.server.name/server-status?auto監控狀態頁面。您可以通過瀏覽器執行此操作,或使用類似命令從命令行執行此操作service httpd fullstatus(參見https://www.liquidweb.com/kb/use-httpd-fullstatus-to-monitor-apache-status/範例)。您還可以使用類似service httpd fullstatus > /var/log/httpd.status.logor的命令將此資訊擷取到日誌文件中service httpd fullstatus | logger -t httpd-status,然後將其放入 cron 中,或者使用 Cacti、Splunk 或其他程序進行日誌記錄。

這應該為您提供更多關於導致凍結時間的系統狀態的資訊。

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