一: 需求: 最近工作中需要监测各个节点到IDC各节点的网络情况,来真实的反映出各网络节点的质量。我们采用的smokeping开源软件来完成这项工作。用Smokeping追查零星的网络问题是我最喜欢的诊断工具之一。 产品介绍: Smokeping是对IDC网络质量,稳定性等最好的检测工具,包括常规的 ping,dig,echoping,curl等,可以监视www服务器性能,监视dns查询性能,监视ssh性能等。Smokeping是rrdtool的作者Tobi Oetiker的作品,所以底层也是 rrdtool 做支持,在图形显示方面有很大优势。特点是主从分布式部署,master/slave方式工作情况下可以在多个节点收集同一个监测点的数据,实现自定义报警功能。
二: 安装: Smokeping是一个用perl写的程序,所以不需要安装。但是他需要使用一些工具以及perl的module,比如rrdtool、fping、echoping等,这些都需要预先安装好。(NGINX装完之后的基本配置这里就不贴了). Smokeping master/slave方式原理请参阅:http://oss.oetiker.ch/smokeping/doc/smokeping_master_slave.en.htmlslave 主从配置的时候slave端不需要config文件,每次slave提交完数据以后,会询问master端的配置文件是否有修改,如果有修改的话slave会进行更新。虽然slave安装完之后不需要配置,但是需要以salve方式启动,下面安装过程中会有详细介绍,以下我们先来做master端的安装配置过程。
1:系统是Debian,编辑sources.list,配置apt root@debian:~# vi /etc/apt/sources.list deb http://ftp.debian.org/debian/ squeeze main non-free contrib deb http://ftp.debian.org/debian/ squeeze-proposed-updates main non-free contrib deb http://ftp.us.debian.org/debian/ squeeze main non-free contrib deb http://ftp.us.debian.org/debian/ squeeze-proposed-updates main non-free contrib root@debian:~# apt-get update
update完之后安装所需要的软件: root@debian:~# aptitude install nginx rrdtool fping echoping libapache2-mod-speedycgi libwww-perl libsocket6-perl libnet-telnet-perl libnet-dns-perl libnet-ldap-perl libio-socket-ssl-perl libauthen-radius-perl libcgi-perl librrds-perl librrdp-perl spawn-fcgi smokeping libfcgi-perl libfcgi-procmanager-perl
2:安装完成,编辑/usr/share/smokeping/cgi-bin/smokeping.fcgi root@debian:~# vi /usr/share/smokeping/cgi-bin/smokeping.fcgi #!/usr/bin/perl -w # -*-perl-*- use FCGI; use FCGI::ProcManager; use lib qw(/usr/share/smokeping/lib); use CGI::Carp qw(fatalsToBrowser); use Smokeping 2.003006; my $proc_manager = FCGI::ProcManager->new( {n_processes => 5} ); my $request = FCGI::Request(); $proc_manager->pm_manage(); while($request->Accept() >= 0) { $proc_manager->pm_pre_dispatch(); Smokeping::cgi("/etc/smokeping/config"); $proc_manager->pm_post_dispatch(); exit(0); }
3:编辑/usr/bin/smokeping-fastcgi root@debian:~# vi /usr/bin/smokeping-fastcgi #!/bin/sh /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9007 \ -P /var/run/smokeping-fastcgi.pid -u www-data \ -f /usr/share/smokeping/cgi-bin/smokeping.fcgi
4:编辑/etc/init.d/smokeping-fastcgi root@debian:~# vi /etc/init.d/smokeping-fastcgi #!/bin/bash FCGI_SCRIPT=/usr/bin/smokeping-fastcgi FASTCGI_USER=www-data PIDFILE=/var/run/smokeping-fastcgi.pid RETVAL=0 case "$1" in start) $FCGI_SCRIPT RETVAL=$? ;; stop) PID=`cat $PIDFILE` kill -9 $PID $(pgrep -P $PID) RETVAL=$? ;; restart) PID=`cat $PIDFILE` kill -9 $PID $(pgrep -P $PID) $FCGI_SCRIPT RETVAL=$? ;; *) echo "Usage: smokeping-fastcgi {start|stop|restart}" exit 1 ;; esac exit $RETVAL 5:注意权限: Smokeping目录所属组,所属主和nginx必须是同一个用户! /usr/share/smokeping/cgi-bin/smokeping.fcgi /usr/bin/smokeping-fastcgi /etc/init.d/smokeping-fastcgi 注意可执行权限! 6:启用并启动init的脚本: update-rc.d smokeping-fastcgi defaults update-rc.d smokeping-fastcgi enable service smokeping-fastcgi start
7:Nginx.conf的相应配置:(NGINX如果没配置好,Smokeping页面出不了图,注意路径配置) server { listen 80; server_name 10.0.0.1; location / { root /usr/share/smokeping/www; index index.html index.htm index.php index.cgi; } location ~ .*\.fcgi$ { root /usr/share/smokeping/www/; fastcgi_pass 127.0.0.1:9007;(这里端口注意!) include /etc/nginx/fastcgi_params; } }
8:启动smokeping root@debian:~# /etc/init.d/smokeping start
访问页面http://10.0.0.1:80/smokeping.fcgi
三:配置 1,配置smokpeing General是基本配置。(imgcache和imgurl两个参数,和NGINX配置相关联,如果没有配置好, smokeping web页面图片显示不出来。) root@debian:/etc/smokeping/config.d# vi /etc/smokeping/config.d/General *** General *** # Please edit this to suit your installation owner = rui.tong@wushen.com (联系邮箱) contact = rui.tong@wushen.com cgiurl = http://10.0.0.1:50032/smokeping.fcgi imgcache = /usr/share/smokeping/www/cache (手动自己创建smokpeing缓存目录) imgurl = cache datadir = /usr/share/smokeping/www/var (手动自己创建) piddir = /usr/share/smokeping/www/var (手动自己创建) mailhost = gls smokemail = /usr/share/smokeping/etc/smokemail.dist tmail = /usr/share/smokeping/etc/tmail.dist # # specify this to get syslog logging syslogfacility = local0 # # each probe is now run in its own process # # disable this to revert to the old behaviour # # concurrentprobes = no Alerts是报警配置,这个目前没有用到,所以没有测试。
Database是RRD数据库配置,Step和pings这两个参数要在启动smokeping之前配置好,如果在smokeping启动后再配置这两个参数,需要把原来的rrd文件都删除,然后再启动smokeping才可以。所以这个一定要先配置好。默认是step=300 pings=20 应该是每300s内执行20次ping的动作。这里默认配置就可以了。 *** Database *** step = 300 pings = 20 # consfn mrhb steps total AVERAGE 0.5 1 1008 AVERAGE 0.5 12 4320 MIN 0.5 12 4320 MAX 0.5 12 4320 AVERAGE 0.5 144 720 MAX 0.5 144 720 MIN 0.5 144 720 Presentation是网络状态的一些配置,默认就OK了。 Probes是指针的配置,我用的是Fping,确定一下路劲是否正确? *** Probes *** + FPing binary = /usr/bin/fping
Slaves是主从配置,很重要,这里我就简单配置两台、 # *** Slaves *** # ## make sure this is not world-readable! ## secrets=/etc/smokeping/slave-secrets # # display_name=slave_name # color=0000ff *** Slaves *** secrets=/usr/share/smokeping/etc/smokeping_secrets.dist (这个文件要手动创建) + 10.0.0.1 display_name = 10.0.0.1 color = 0000ff (color设置页面上监控rrdtool流量图的颜色,后面参数代码任意配置) + 10.0.0.2 display_name = 10.0.0.2 color = 00ff00 + 10.0.0.3 display_name = 10.0.0.3 color = ff0000
手动创建smokeping_secrets.dist文件,格式一定要如下!Slave端的IP,"root"是主从关联的密码,这个随意写。 vi /usr/share/smokeping/etc/smokeping_secrets.dist 10.0.0.1:root 10.0.0.2:root
Targets是目标的配置,从slave服务器上取值的配置在这里配置,如果不是做主从的话,单独配置几台服务器的监控情况也在这里配置。(这里跟slaves目标主机要对应起来!!) root@debian:/etc/smokeping/config.d# vi Targets *** Targets *** probe = FPing # You have to edit and uncomment all what you want below this. # # Please, refer to smokeping_config man page for more info # # The given adresses aren't real to avoid DoS. menu = Top title = Network Latency Grapher remark = 欢迎使用武神smokeping + Local + Slaves menu = 全国各数据中心 title = 运维Smokeping ++ beijing menu = 北京XX title = Host 北京XX Monitor From Slaves slaves = 10.0.0.2 host = 10.0.0.1 ++ nanjing menu = 杭州XX title = Host 杭州XX Monitor From Slaves slaves = 10.0.0.1 host = 10.0.0.2 相关的smokeping都配置完了 主/从 做分布式监控的时候有几点需要注意 1.主从服务器上面的密码文件权限必须为600 而且主服务器上面的密码文件的属主必须为NGINX的启动用户 2.从服务器上面的密码文件只需要一个密码就行,也就是主上面为它配置的那个密码。同样从服务器上面的密码文件的属主必须为smokeping的启动用户
2:启动smokeping root@debian:~# /etc/init.d/smokeping restart 3:配置从服务器 从服务器的配置参照上面主服务器的配置,NGINX不用配置,smokeping也不需要配置,因为slaves不需要config的配置! 手动创建smokeping_secrets.dist(密码!) root@debian:~# vi /usr/share/smokeping/etc/smokeping_secrets.dist root
Slave端以slave方式启动!前提是master端上的smokeping已经启动,这样slave启动是才能获取到master的数据,不然slave启动时会报错。 root@debian:~# /usr/sbin/smokeping --master-url=http://10.0.0.1:80/smokeping.fcgi --cache-dir=/usr/share/smokeping/www/cache --shared-secret=/usr/share/smokeping/etc/smokeping_secrets.dist --slave-name=10.0.0.2 (cache手动创建) 全部安装配置完,访问页面http://10.0.0.1:80/smokeping.fcgi (此图) 如果数据获取不到,在master端smokeping路径下cache和var下是否有文件生成,如果没有,查看smokeping目录下的权限是否正确,并结合smokeping debug log 和 NGINX error log 来排查问题!
(责任编辑:IT) |