发现一个监控gearman状态的apache模块
tar xvzf amir-mod_gearman_status.tarapxs -c -i mod_gearman_status.c
LoadModule gearman_status_module modules/mod_gearman_status.so<Location /gearman-status>SetHandler gearman_status</Location>
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的源代码,以达到以上的目标
...
Include conf/conf.d/server-status.conf
...
[root@pps conf]# cat conf.d/server-status.conf
# 不需要以下这一行
# LoadModule status_module modules/mod_status.so
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 192.168.32.1
</location>
Include conf/extra/httpd-info.conf
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.32.1
</Location>
ExtendedStatus .
SetHandler server-info
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.32.1
</Location>
[url]http://ip/server-status[/url]
或者
[url]http://ip/server-status?refresh=5[/url]
(自动每隔5秒刷新一次)
# ps -ef | grep httpd | wc -l
# netstat -ant | grep ":80 " | wc -l
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>