lvs_rrd生成监控图形
Update: 2012-12-24
net-snmp-lvs-module
利用net-snmp-lvs-module 给net-snmp加个模块,然后配合cacti的相关模板来实现监控。由于针对64位系统的net-snmp-lvs-module只支持到rhel4因此放弃使用。
相关网址:net-snmp-lvs-module-0.0.4.tar.gz: http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/files/net-snmp-lvs-module-0.0.4.tar.gz
lvs_rrd工具生成图形
lvs_rrd[ http://www.tepedino.org/lvs-rrd/ ]工具实现了网页的形式来查看lvs状态图功能。其主要有两个脚本组成:信息收集脚本和图像绘制脚本。信息收集脚本是将lvs的信息生成rrd格式的数据文件,然后利用图像绘制脚本生成图像,并生成一个php页面,这个页面中引用其所生成的图像,这样我们可以通过web页面的形式查看生成的php页面,就可以时时的查看lvs的状态信息了。
lvs_rrd需要部署在LVS-Master和LVS-Backup上,更准确的说lvs_rrd中的信息收集脚本一定要在LVS director 上运行。通过配置图像生成脚本和图像的生成目录,我们可以将他们时时的复制到其他的服务器中。这里为了方便起见我将它们部署到了LVS director上。
下面简单的介绍部署的步骤
安装rrdtool
yum install rrdtool bc
- 开启LVS director 的apache,配置相关参数,注意端口一定不能为80,我这里修改为9160。指定DocumentRoot 为 "/data/web"
-
下载lvs_rrd软件。
mkdir -p /data/www && cd /data/www wget http://www.tepedino.org/lvs-rrd/lvs-rrd-v0.7.tar.gz
- 将lvs-rrd-v0.7.tar.gz解压后将文件夹复制到/data/www/目录下并更名为lvs
-
配置lvs.rrd.update文件
RRDTOOL="/usr/bin/rrdtool" IPVSADM="/sbin/ipvsadm" WORKDIR="/data/www/lvs/rrd"
-
配置graph-lvs.sh
WORKDIR="/data/www/lvs/rrd" RRDTOOL="/usr/bin/rrdtool" #GRAPHS="$WORKDIR/graphs" GRAPHS="/data/www/lvs/graphs" WEBPATH=""
这两个文件根据自己的情况设置一下就可以了。
-
将/data/www/lvs/graphs目录修改为web用户可读可写。
mkdir -p /data/www/lvs/rrd chown nginx:nginx /data/www/lvs/graphs -R
设置采集
将收集信息的脚本添加到计划任务中
#/etc/crontab * * * * * root /data/www/lvs/lvs.rrd.update 2> /dev/null > /dev/null # 不安装php环境,每5分钟生成一次图表 */5 * * * * root /data/www/lvs/graph-lvs.sh -H 2> /dev/null > /data/www/lvs/graphs/index.html
生成图形参数
graph-lvs.sh [-lH] [-I VIP] [-P port] [-i IP] [-p port]
-l Lazy (Generate graphs at most once per 5 minutes)
-H Output an HTML page.
-I VIP Graph only servers in this virtual server
-P port Graph only VIPs on this port
-i IP Graph only this real server IP
-p port Graph only this real server port
-r Reverse (flip) active and inactive (positive to negative)
-s Separate Active/Inactive graphs (nullifies -r)
- 等1分钟后,看lvs目录中是否生成了以rrd为扩展名的文件。如果有的话就可以启动apache通过http://ipaddress:9160/lvs/ 查看lvs的状态了。如图:
为各services生成图表
#!/bin/sh
# graphs.sh
# add to /etc/crontab
# */5 * * * * root /data/www/lvs/graphs.sh >> /data/www/lvs/graphs/log_`date +\%Y\%m`.txt 2>&1
#name:vip:port
PROD_services="
ALL:ALL:ALL
MGW:172.16.16.151:80
VTGW:172.16.16.152:80
CCGW:172.16.16.153:8080
Portal:172.16.16.154:80
DC:172.16.16.158:80
FGW:172.16.16.159:8080"
pre_PROD_services="
ALL:ALL:ALL
preMGW:172.16.16.102:80
preVTGW:172.16.16.103:80
preCCGW:172.16.16.104:8080
prePortal:172.16.16.105:80
preFGW:172.16.16.108:8080
preDC:172.16.16.106:80"
services=$PROD_services
#services=$pre_PROD_services
IPVSADM="/sbin/ipvsadm"
OUT="/data/www/lvs/graphs"
GRAPH_LVS="/data/www/lvs/graph-lvs.sh"
start_time=`date +'%Y-%m-%d %H:%M:%S'`
Index_Body=""
for s in `echo "$services"|grep -v ^$|grep -v ^#`
do
name=`echo $s|cut -d\: -f 1`
vip=`echo $s|cut -d\: -f 2`
port=`echo $s|cut -d\: -f 3`
if [ "$name" = "ALL" ];then
$GRAPH_LVS -H > ${OUT}/${name}.html
else
$GRAPH_LVS -H -I "$vip" -P "$port" > ${OUT}/${name}.html
fi
Index_Body="${Index_Body}\n<tr><td>$name</td><td><a href="${name}.html">${vip}:${port}</a></td></tr>"
done
echo -e "<html>
<head>
<title>Linux Virtual Server</title>
<meta HTTP-EQUIV="Refresh" CONTENT="320">
</head>
<body bgcolor='E3E3E3'>
<table border=1>
$Index_Body
</table>
<br>
Last update: $start_time - `date +'%Y-%m-%d %H:%M:%S'`
<br>
<pre>
$($IPVSADM -Ln)
</pre>
</body>
</html>" > ${OUT}/index.html
exit 0
nginx图表查看站点
#nginx.conf
#user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log;
#pid /var/run/nginx.pid;
worker_rlimit_nofile 10240;
events {
use epoll;
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio" "$connection" "$request_time"';
#server_names_hash_bucket_size 64
proxy_read_timeout 200;
keepalive_timeout 65;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_min_length 1k;
#gzip_proxied any;
gzip_buffers 4 32k;
#gzip_types text/plain text/css text/xml application/xml application/atom+xml;
gzip_types text/plain text/css text/xml;
gzip_disable "MSIE [1-6]\.";
ignore_invalid_headers on;
client_header_buffer_size 32k;
large_client_header_buffers 4 128k;
include sites-enabled/*.conf;
server {
#backends
listen 80 default;
#server_name 127.0.0.1;
charset utf-8;
# Allow file uploads
client_max_body_size 20M;
#index index.html index.htm;
#autoindex on;
#autoindex_exact_size off;
#autoindex_localtime on;
#access_log off;
access_log /var/log/nginx/lvs.access.log main;
error_log /var/log/nginx/lvs.error.log warn;
root /data/www/lvs/graphs;
} #End server
} #end http
Other
- ipvsman - more than a GUI for ipvs : http://sourceforge.net/projects/ipvsman/
- Piranha : http://www.linux-vs.org/docs/ha/piranha.html