收集  归纳 整理

发现一个监控gearman状态的apache模块
载此tar文件
直接用apxs编译他
tar xvzf amir-mod_gearman_status.tar
apxs -c -i mod_gearman_status.c
为了可以用http://yourdomain.com/gearman_status的方式查看gearman状态,在apache的配置文件追加如下配置
LoadModule gearman_status_module modules/mod_gearman_status.so
<Location /gearman-status>
SetHandler gearman_status
</Location>
添加完以后,重启apache 就可以访问了,

apache的流量控制模块bw_mod进行带宽控制


 随着在线人数的不断增加,WDA的附件每天增量很多,流量越来越大,从MRTG监控到,忙时达到10M,导致空间商限制了WDA的流量。
       分析流量大的原因,主要是因为上传和下载附件占用了带宽,找了很多解决办法,终于用apache的bw_mod模块解决了。
       bw_mod是for apache2的,首先到
     下载最新的bw_mod模块,目前是bw_mod v0.6。
       然后运行apxs -i -a -c bw_mod-0.6.c,apxs请用绝对路径。此命令会自动安装bw_mod,并在apache配置文件httpd.conf自动加入
       LoadModule bw_module modules/bw_mod-0.6.so
       安装完成后,会在modules目录下生成bw_mod-0.6.so 文件。
       如果安装过程没有出错的话,就可以开始进行设置了。
       在httpd.conf中的LoadModule bw_module modules/bw_mod-0.6.so 下面加入以下设置指令:
     BandWidthModule On
       #启动bw_mod模块
     BandWidth all 0
     #总的带宽不用限制
     LargeFileLimit .rar 30 23000
      #限制所有大于30K的后缀名为.rar的文件的速率为23000字节/秒,即23K/秒
     LargeFileLimit .mp3 30 23000
     LargeFileLimit .wav 30 23000
     LargeFileLimit .jpg 10 27000
     LargeFileLimit .gif 5 27000
     LargeFileLimit .zip 50 30000
     LargeFileLimit .sis 50 30000
     LargeFileLimit .exe 50 30000
     安装完毕后,网站速度有明显好转。
    
     BandWidthModule On
     BandWidth all 16384
     LargeFileLimit * 500 4096
    
     LargeFileLimit * 100 1024
    
    
     This wont limit Directory / to 16384. The Directory wont "inherit" the
    settings from the vhost if you use some of the mod's directives.

性能监控模块
mod_status和mod_info to模块
在Apache服务器中的 mod_status 和 mod_info to 来告诉我们目前服务器的工作情况 
mod_status:
使 用 mod_status,允许我们使用URL:http://servername/server-status来通过mod_status生成并报告 服务器状态信息。我们可以知道谁在你的服务器上看些什么东西,以及有多少人连在Web 服务器上,每个子进程的运行状态等等信息

mod_info 和 mod_status 
这两个模块可以提供十分有用的信息,而且十分方便。 
mod_status 能准确地告诉你,你的服务器正在“想”什么。你可以知道有哪些人在浏览您的网站,有多少子进 程在运行,以及这些进程在干吗。系统自从上次启动以来已经运行了多少时间。
当然我们还可以得到更多的信息,修改http.conf
ExtendedStatus  on
我 们还可以得到一张每一 个子进程及其所作工作的列表。 对于每一个子进程而言,信息包括它的PID ,以及它占用的CPU 时间和已经运行的时间。对于服 务器而言,信息包括得到服务器启动以后的合计点击数,CPU的利用率以及每分钟点击数,还有传输给客户端的总计字节数。 

启用方式,修改httpd.conf文件,增加以下信息
SetHandler server-status 
Order deny,allow 
Deny from all 
Allow from .your_domain.com 
mod_info
启用mod_info,允许使用URL:http://servername/server-info来远程报告服务器配置信息,mpd-info 是一个分类的扩展模块,需要需要mod_info.c支持。

确认安装之后,修改httpd.conf,增加以下信息
SetHandler server-info 
Order deny,allow 
Deny from all 
Allow from .your-domain.com 
URL: http://servername/server-info显示的启示就是你编译到Apache 里面的东西的列表以及其他针对服务器的各种特性。如果 你输入:http://your.server/server-info/ 就可以看到服务器内置的模块列表或者通过DSO 加载的模块列表。 
这对于安装和配置特定的服务器来说是十分有用的。特别是用来对错误的配置文件查找问题时。 
结论以及目标
1:Apache运行过程时间的记录
通过修改http:.conf配置文件,
LogFormat "%h %l %u %t \"%r\" %>s %b" common(默认)
增加%D(毫秒级,仅对于Apache2适用),%T(秒级)参数,增加对每个请求的时间过程记录
LogFormat "%h %l %u %t \"%r\" %>s %b %D" common(默认)
2:加载mod_status和mod_info to模块
虽然加载mod_status和mod_info to模块会带来一定的性能损失,但是一个完善的监控机制还是有必要的,方便我们对Apache的参数调整后的检测,这要比查看单条的请求记录来得更直观和有效
3:进一步的希望
我们觉得以上的信息仍然不够,需要更加量化的信息,比如我们需要每个请求的数据接收,处理,日志的时间记录,我们可能需要去修改Apache的源代码,以达到以上的目标


Apache2使用Server-Status来查看实时状态

Apache2自己编译安装的时候,默认是将对server-status的支持编译进去httpd的。自己编译安装的 httpd.conf 里没有 server-status 相关的配置,需要自己额外添加,或者采用系统的 conf/extra/httpd-info.conf配置。
 
自己添加的方式:
我在 apache2/conf/conf.d 里添加了 server-status.conf 文件,在 httpd.conf 里把它包含进去,如下:
/////////////////  httpd.conf
...
Include conf/conf.d/server-status.conf
...
 
/////////////////  conf.d/server.status.conf
[root@pps conf]# cat conf.d/server-status.conf
# 不需要以下这一行
# LoadModule status_module modules/mod_status.so
<location /server-status>
    SetHandler server-status
    Order Deny,Allow
          Deny from all
          Allow from 127.0.0.1 192.168.32.1
</location>
ExtendedStatus   //看详细信息
 
【注意】ExtendedStatus .表示的是待会访问的时候能看到详细的请求信息,另外该设置仅能用于全局设置,不能在特定的虚拟主机中打开或关闭。启用扩展状态信息将会导致服务器运行效率降低。
 
采用conf/extra/httpd-info.conf里的配置:
/////////////////  httpd.conf
# Real-time info . requests and configuration
Include conf/extra/httpd-info.conf
/////////////////  httpd-info.conf
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.32.1
</Location>
ExtendedStatus .
 
//这里还有配置了server-info信息查看路径哦
//不过需要配置编译时加 --enable-info 来支持
<Location /server-info>
    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.32.1
</Location>
 
嘿嘿,我这里的配置,还做了访问限制,只有服务器本身和192.168.32.1机器可以访问server-status (server-info)
 
如果你的Apache配置文件httpd.conf或者extra/httpd-info.conf中有LoadModule status_module modules/mod_status.so话,说明你的Apache已经加载了此模块;或者编译的时候加上了–enable-module=so也表明 服务器支持server-status。如果是RHEL5自带的rpm安装包安装的apache2,在httpd.conf有相关的配置,并且需要用到模 块加载。
 
重启apache2,通过以下路径访问apache2的server-status:
[url]http://ip/server-status[/url]
或者
[url]http://ip/server-status?refresh=5[/url]
(自动每隔5秒刷新一次)
 
【附加】
在没有开启Apache Server Status的情况下,或者没有浏览器的情况下,可以通过以下方式来查看服务器状态:
1、用 ps 来看 httpd 进程数
# ps -ef | grep httpd | wc -l
用这个命令统计当前的httpd进程数,当然这结果包含 grep httpd 的进程输出,一般来说实际进程数比输出结果少1。Apache启动的时候,默认就起来几个进程,如果连接数多了,它就会生出更多的进程来处理请求。
2、用 netstat 来看当前的连接数
# netstat -ant | grep ":80 " | wc -l
连接数目并不等于httpd线程数目,当然连接数目越多,httpd进程数就有可能数会增多。上面的返回结果数目,有可能包括多种连接状态,比如 LISTEN、ESTABLISHED、TIME_WAIT等等,可以加入状态关键字进一步过滤,得到想要的结果。

apache认证


apache认证

有时候某些目录下的文件需要增加认证,Apache缺省的认证模块都是很完备的,以下就是一个通过.htaccess文件增加用户认证的例子。即使对于虚拟主机用户也可以通过上传一些文件来实现认证控制。

 

<VirtualHost *:52147>
 ServerAdmin webmaster@xxx.com.cn
 DocumentRoot /data/mrtgwww/
 ServerName mrtg.xxc.com.cn
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
     <Directory /data/mrtgwww/>
                Options Indexes FollowSymLinks
                AllowOverride AuthConfig
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

 

首先用htpasswd创建一个密码文件:比如文件名叫做my.passwd
/home/apache/bin/htpasswd -c -b my.passwd myusername mypassword
如果增加帐号:
/home/apache/bin/htpasswd -b my.passwd anotherusername anotherpassword

将my.passwd上传到一个非发布路径下。
比如你的物理WEB根目录的上一级
/home/apache/conf/my.passwd

创建 .htaccess
AuthName "My Authorization Directory"
AuthType Basic
AuthUserFile /home/apache/conf/my.passwd
Require valid-user

将这个文件上传到你需要进行用户认证的目录:
/home/apache/htdocs/admin/.htaccess

这样这个目录的访问就需要认证了。

-c 创建密码文件

[root@HOTRM-NJ1 bin]# ./htpasswd --help
Usage:
        htpasswd [-cmdpsD] passwordfile username
        htpasswd -b[cmdpsD] passwordfile username password

        htpasswd -n[mdps] username
        htpasswd -nb[mdps] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -m  Force MD5 encryption of the password.
 -d  Force CRYPT encryption of the password (default).
 -p  Do not encrypt the password (plaintext).
 -s  Force SHA encryption of the password.
 -b  Use the password from the command line rather than prompting for it.
 -D  Delete the specified user.

vi httpd.conf
Alias /ganglia "/Data/webapps/monitor.360quan.com/ganglia"
<Directory "/Data/webapps/monitor.360quan.com/ganglia">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Ganglia Access"
   AuthType Basic
   AuthUserFile /Data/apps/httpd-2.2.8/conf/my.passwd
   #AuthUserFile /Data/apps/nagios/etc/htpasswd.users
   Require valid-user
</Directory>