5.3监控apache nginx
5.3.1准备工作
1.网络规划:
cacti:10.10.54.50
##在同一台机器上nginx和apache不能同时开启,因为都为80端口。
nginx && apche:10.10.54.54
2.软件下载
服务器器端:
wget http://ftqzy-it-code.googlecode.com/files/ApacheStats_0.8.2.zip
wget http://autosetup1.googlecode.com/files/cacti-nginx.tar.gz
yum -y install perl-libwww-perl
yum install cacti
客户端:
yum install -y snmpd
wget http://nginx.org/download/nginx-1.4.5.tar.gz
yum install -y httpd
3.修改配置文件
在做监控apache和nginx服务之前,需要能够实现对远程主机的监控
[root@xiao54 ~]# vim /etc/snmp/snmpd.conf
===============================================
# sec.name source community
com2sec notConfigUser 10.10.54.50 public
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact all none none
## incl/excl subtree mask
view all included .1 80
proc mountd
proc ntalkd 4
proc sendmail 10 1
disk / 10000
load 12 14 14
=======================================================
简要说明:
ExtendedStatus On表示的是访问时能看到详细的请求信息,
注意:该设置仅能用于全局设置,不能在特定的虚拟主机中打开或关闭。
启用扩展状态信息将会导致服务器运行效率降低。
Deny from表示禁止访问的地址;
Allow from表示允许访问的地址;
4.重启服务
/etc/init.d/snmpd restart
5.3.2监控apache
//客户端:
1.安装http
yum install -y httpd
2.修改配置文件
[root@xiao54 ~]# vim /etc/httpd/conf/httpd.conf
============================================
LoadModule status_module modules/mod_status.so
ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 10.10.54.0/255.255.255.0
</Location>
===========================================
3.重启服务
[root@xiao54 ~]# /etc/init.d/httpd stop
[root@xiao54 ~]# /etc/init.d/httpd start
4.测试页面
//服务器端
1.解压插件包
[root@xiao50 softs]# tar xvf ApacheStats_0.8.2.zip
2.复制解压插件到脚本目录
[root@xiao50 ApacheStats_0.8.2]# cp ss_apache_stats.php /web/vhosts/cacti/scripts/
3.更改目录权限
[root@xiao50 ~]# chmod 755 /web/vhosts/cacti/scripts/
//cacti管理界面
1.导入模板
2.新建apache主机
点击create.
2.添加监控选项
5.3.3监控nginx
//客户端
1.安装nginx
1)解压
[root@xiao54 softs]# tar xvf nginx-1.4.5.tar.gz
2)编译
[root@xiao54 nginx-1.4.5]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module \
--with-http_gzip_static_module --with-http_ssl_module
make
make install
3)启动服务
[root@xiao54 ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
2.修改配置文件
[root@xiao54 ~]# vim /usr/local/nginx/conf/nginx.conf
==================================================
user nginx nginx;
worker_processes 2;
error_log logs/error.log info;
pid logs/nginx.pid
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log logs/access.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /NginxStatus {
stub_status on; --启用状态监测
access_log off; --关闭访问日志
}
===============================================
killall -s HUP nginx (令Nginx配置生效)
3.测试
浏览器输入:http://10.10.54.54/NginxStatus
显示Nginx的运行状态页面
Active connections: 2
server accepts handled requests
2 2 1
Reading: 0 Writing: 1 Waiting: 1
对上面显示结果的分析:
active connection--所有打开的连接,包括连接到后端的服务器的。
server accepts handled requests--nginx已经接受2个连接(第一个位置),处理了2个连接(第二个位置),请求的数量(1个连接对应着1个请求)
reading--读取的请求头
writing--读取的请求主体,处理的请求或者写入的应该。
waiting--keepalive连接数,等于active-(reading+writing)。
//服务器端
1.解压插件包
[root@xiao50 softs]# tar xvf cacti-nginx.tar.gz
2.复制解压插件到脚本目录
[root@xiao50 cacti-nginx]# cp get_nginx_clients_status.pl /web/vhosts/cacti/scripts/
[root@xiao50 cacti-nginx]# cp get_nginx_socket_status.pl /web/vhosts/cacti/scripts/
3.更改目录权限
[root@xiao50 ~]# chmod 755 /web/vhosts/cacti/scripts/
4. 验证
[root@xiao50 ~]# /web/vhosts/cacti/scripts/get_nginx_clients_status.pl http://10.10.54.54/NginxStatus
##error
no (LWP::UserAgent not found)
solution:
yum -y install perl-libwww-perl
再次验证:
[root@xiao50 ~]# /web/vhosts/cacti/scripts/get_nginx_clients_status.pl http://10.10.54.54/NginxStatus
nginx_active:1 nginx_reading:0 nginx_writing:1 nginx_waiting:0
[root@xiao50 ~]# /web/vhosts/cacti/scripts/get_nginx_socket_status.pl http://10.10.54.54/NginxStatus
nginx_accepts:4 nginx_handled:4 nginx_requests:4
//cacti管理界面
1.导入模板
Console -> Import Templates
从本机选取:
cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml
->Import
-----待完善-----