一、开启相应监控模块(加载mod_status.so,mod_info.so,mod_proxy_balancer.so模块)
1、打开conf/httpd.conf
2、分别去掉#LoadModule status_module modules/mod_status.so,mod_info.so,mod_proxy_balancer.so前面的#号
二、监控请求配置
1、打开conf/httpd.conf
2、去掉#Include conf/extra/httpd-info.conf前面的#号,该文件里对应有server-status(mod_status.so)、server-info(mod_info.so)的配置信息。
3、按照上一步server-status/server-info的内容格式,在httpd-info.conf中新增一段balancer-manager的内容。
三、其他调整
1、若http://servername/server-status访问不到。因与tomcat做负载均衡/反向代理,对于server-status等请求无需反向代理,需要在你httpd-vhost.conf原有的配置中加入如下代码
#apache监控
#过滤server-stauts页面
ProxyPass /server-status !
#过滤server-info页面
ProxyPass /server-info !
#过滤balancer-manager页面
ProxyPass /balancer-manager !
<VirtualHost *:80>
ServerAdmin admin@domain.com
ServerName localhost
ServerAlias localhost
ErrorLog "logs/cdthgk-exam-error.log"
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" common
CustomLog "logs/pro-access.log" common
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
ProxyRequests Off
ProxyPreserveHost on
#apache监控
#过滤server-stauts页面
ProxyPass /server-status !
#过滤server-info页面
ProxyPass /server-info !
#过滤balancer-manager页面
ProxyPass /balancer-manager !
ProxyPass / balancer://tomcat-cluster/ stickysession=ROUTEID
#ProxyPass / balancer://tomcat-cluster/ stickysession=JSESSIONID|jsessionid nofailover=Off
ProxyPassReverse / balancer://tomcat-cluster/
<Proxy balancer://tomcat-cluster/>
BalancerMember ajp://localhost:18009 loadfactor=1 route=JVMa
BalancerMember ajp://localhost:28009 loadfactor=1 route=JVMb
ProxySet lbmethod=bybusyness
</Proxy>
</VirtualHost>
2、若出现You don't have permission to access /server-status on this server.可能是你的httpd-info.conf配置存在问题
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all#拒绝
Allow from localhost#同意
</Location>
四、备注
1、Apache的ProxyPass指令:
描述:将远程服务器映射到本地服务器的URL空间
语法:ProxyPass [路径] !|url [键=值 键=值 ...]] [nocanon]
上下文: server config, virtual host, directory
模 块:mod_proxy
该指令可以将远程服务器映射到本地服务器的URL空间;本地的服务器并不是扮演传统意义上的代理服务器的角色,而是表现为远程服务器的一个镜像。此 本地服务器常被成为反向代理(reversed proxy)或者是网关(gateway)。路 径是指本地虚拟路径的名字;url指远程服务器的一个部分URL,不能包含查询字符串。
注意:在使用ProxyPass
指令的时候,ProxyRequests
指令通常都应该是关闭的。
假设本地服务器的地址是 http://example.com/
, 那么
ProxyPass /mirror/foo/ http://backend.example.com/
将会把对http://example.com/mirror/foo/bar
的 本地请求内部转换成到http://backend.example.com/bar
的 代理请求。
其中,!
指令当你不想对某个子目录进行反向代理的时候就有用 了,例如:
ProxyPass /mirror/foo/i !
2、Apache的Allow和Deny的判断规则:order语句中allow、deny的先后顺序; allow、deny语句中各自包含的范围。