【问题标题】:Linux + Apache to detect the Connection Counts of each Vhosts?Linux + Apache 检测每个 Vhosts 的连接数?
【发布时间】:2014-06-06 05:31:09
【问题描述】:

使用 RHEL 和 Apache (httpd),有没有办法:

  • 检测哪个 v.host(域)获得了多少传入连接?

因为这几天,我在服务器上收到了很多传入连接,通过使用:

  • ps 辅助 | grep httpd -c
    734

这意味着我有 734 传入连接当前由 Apache 处理,但问题是我有(比如说)10 个虚拟主机(域)。

  • 那么,哪个域的负载高?

请提供任何尖锐的解决方案。

【问题讨论】:

    标签: linux apache connection vhosts


    【解决方案1】:

    假设你有一个像 /etc/apache2/sites-enabled/000-example.com 这样的文件

    你可能会看到这样的行:

    <VirtualHost *:80>
        ServerName www.example.com
        ServerAlias example.com 
        DocumentRoot /www/example.com
    

    再往下,如果需要,您可以通过更改行为每个 VirtualHost 创建日志文件

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    太:

        ErrorLog ${APACHE_LOG_DIR}/example_com.error.log
        CustomLog ${APACHE_LOG_DIR}/example_com.access.log combined
    

    否则,如果您不想为每个VirtualHost创建日志文件,那么您可以创建自己的自定义日志格式http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats

    例如:

        LogFormat "%v %h %l %u %t \"%r\" %>s %b" common
        CustomLog ${APACHE_LOG_DIR}/access.log common
    

    当您决定如何记录后,您可以编写各种脚本来检查或比较您的日志。如果您为每个虚拟主机使用单独的日志文件会容易得多,因为您可以试试这个。

     wc -l /var/log/apache2/*access.log
    

    【讨论】:

    • 问题不是每个虚拟主机的日志记录,而是每个虚拟主机的活动连接计数
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 2014-05-17
    • 1970-01-01
    • 2017-10-31
    • 2020-05-04
    • 2013-06-06
    • 1970-01-01
    相关资源
    最近更新 更多