linux下安装smokeping
一. Smokeping 简介1.1 Smokeping简介:
Smokeping 是rrdtool 的作者Tobi Oetiker 的作品,是用Perl 写的,主要是监视网络性能,包括常规的ping,用echoping监控www 服务器性能,监视dns 查询性能,监视ssh 性能等。底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示。
1.2 Smokeping 架构组件
Smokeping 有以下组件组成:RRDtool、Fping、Echoping、Curl、Dig、SSh、Perl 模块,Perl、SpeedyCGI、Apache 等。
master/slave 的工作方式,可以在多个节点收集同一个监测点的数据;
1.3 Smokeping 相关资源
1> Smokeping 官方网站:http://oss.oetiker.ch/smokeping
2> Smokeiping 相关软件下载地址:
http://pan.baidu.com/share/link?shareid=62130&uk=2298629948
二.Smokeping 安装
2.1 准备工作
# uname -a
Linux smokeping.www.yunvn.com 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
# cat /etc/RedHat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
# perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi
….
先暂时关闭iptables以及selinux刨除其他影响
构建本地yum数据库
# cat /etc/yum.repos.d/server.repo
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
name=Red Hat Enterprise Linux vt
baseurl=file:///mnt/cdrom/VT/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
name=Red Hat Enterprise Linux clusterstorage
baseurl=file:///mnt/cdrom/ClusterStorage/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
#
# mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
# yum list all
2.2 安装rrdtool
RRDTool 是由Tobias Oetiker 开发的开源软件,它使用RRD(Round Rebin Databases)作为存储格式,Round robin 是一种处理定量数据以及当前元素指针的技术,RRDTool 主要用来跟踪对象的变化情况,生成改对象变化的趋势图。
# cd /root/smokeping/
# ls
cgilib-0.5.tar.gz
CGI-SpeedyCGI-2.22.tar.gz
echoping-6.0.2.tar.gz
fping.tar.gz
rrdtool-1.4.4.tar.gz
smokeping-2.4.2.tar.gz
# 安装依赖的软件包:
# yum -y install freetype freetype-devel libpng libpng-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel pango pango-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart* gettext gettext-devel libjpeg libjpeg-devel perl-XML-Simple.noarch perl-Crypt-SSLeay perl-Digest-HMAC
使rrdtool支持中文
# cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"
# export LANG="zh_CN.UTF-8"
# yum -y install fonts-chinese
安装rrdtool
# tar -zxvf rrdtool-1.4.4.tar.gz -C /usr/local/src/
# cd /usr/local/src/rrdtool-1.4.4/
# ls
# sed -i 's/setlocale(LC_NUMERIC, "C")/setlocale(LC_ALL, "zh_CN.UTF-8")/g' src/rrd_graph.c
# sed -i 's/setlocale(LC_NUMERIC, old_locale)/setlocale(LC_ALL, old_locale)/g' src/rrd_graph.c
# ./configure --prefix=/usr/local/rrdtool # make && make install
执行rrdtool 命令,如果出现以下输出,表示安装成功,并列出了该命令的使用帮助。
# cd /usr/local/rrdtool/bin/
# ll
total 400
-rwxr-xr-x 1 root root95492 Jun 17 09:50 rrdcached
-rwxr-xr-x 1 root root46362 Jun 17 09:50 rrdcgi
-rwxr-xr-x 1 root root41520 Jun 17 09:50 rrdtool
-rwxr-xr-x 1 root root 207192 Jun 17 09:50 rrdupdate
# ./rrdtool
RRDtool 1.4.4Copyright 1997-2010 by Tobias Oetiker
Compiled Jun 17 2012 09:50:49
Usage: rrdtool command command_options
Valid commands: create, update, updatev, graph, graphv,dump, restore,
last, lastupdate, first, info, fetch, tune,
resize, xport, flushcached
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)
For more information read the RRD manpages
#
.3安装Fping和Echoping
# cd /root/smokeping/
# tar -zxvf fping.tar.gz -C /usr/local/src/
# cd /usr/local/src/fping-2.4b2_to/
# ./configure
# make && make install
# ln -s /usr/local/fping/sbin/fping /usr/sbin/fping
#cd /root/smokeping/
#tar -zxvf echoping-6.0.2.tar.gz -C /usr/local/src/
#cd /usr/local/src/echoping-6.0.2
# ./configure
# make && make install
2.4 安装cgilib和SpeedyCGI
# cd /root/smokeping/
# tar -zxvf cgilib-0.5.tar.gz -C /usr/local/src/
# cd /usr/local/src/cgilib-0.5/
# ls
cgi.5 cgiGetCookies.3 cgiRedirect.3 cookies.txt
cgi.c cgiGetValue.3 cgiSetHeader.3CREDITS
cgiDebug.3 cgiGetVariables.3cgiSetType.3 jumpto.c
cgiFree.3 cgi.h cgitest.c Makefile
cgiFreeList.3 cgiHeader.3 CHANGES readme
cgiGetCookie.3cgiInit.3 cookies.c
#
# make
# cp libcgi.a /usr/local/lib
# cp cgi.h /usr/include/
# cd /root/smokeping/
# tar -zxvf CGI-SpeedyCGI-2.22.tar.gz -C /usr/local/src/
# cd /usr/local/src/CGI-SpeedyCGI-2.22/
# ls
COPYING Makefile.PLcontribmod_speedycgi speedy_backendutil
Changes README docs mod_speedycgi2speedy_dump
MANIFESTREADME.htmllib speedy src
# perl Makefile.PL
# make
# make install
2.5 安装Perl模块
以下全是Smokeping 需要的perl 模块。
# cd
# yum install -y perl-libwww-perl perl-IO-Socket-SSL perl-Net-Telnet perl-Socket6 perl-Net-DNS perl-LDAP perl-libwww-perl perl-IO-Socket-SSL
2.6 安装Smokeping
# cd /root/smokeping/
# tar -zxvf smokeping-2.4.2.tar.gz -C /usr/local/src/
#mv /usr/local/src/smokeping-2.4.2/ /usr/local/smokeping
三. Smokeping 初始化配置
3.1修改smokeping相关文件名
在smokeping的子目录中会发现很多“*.dist”命名的文件,这些文件使用的时候请将其改名为“*”并进行配置
# cd /usr/local/smokeping/
# ls
# cp -a bin/smokeping.dist bin/smokeping
# cp -a htdocs/smokeping.cgi.dist htdocs/smokeping.cgi
# cp -a etc/config.dist etc/config
3.2建立相关目录
接着建立三个目录用于保存smokeping的数据等,如下所示:
# mkdir /usr/local/smokeping/data
# mkdir /usr/local/smokeping/var
# mkdir /usr/local/smokeping/cache
# yum install -y httpd
# chown -R apache.apache /usr/local/smokeping
3.3修改配置文件
(1)/usr/local/smokeping/etc/config (somkeping配置基本都在这个文件上)
*** General ***
owner = xjzhujunjie
contact= xjzhujunjie@www.yunvn.com
mailhost = my.mail.host
sendmail = /usr/lib/sendmail
…
imgcache = /usr/local/smokeping/cache
imgurl = cache
datadir= /usr/local/smokeping/data
piddir= /usr/local/smokeping/var
cgiurl = http://192.168.101.81/smokeping/smokeping.cgismokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/smokeping/etc/tmail.dist
*** Presentation ***
template = /usr/local/smokeping/etc/basepage.html.dist
+ charts
+ FPing
binary = /usr/sbin/fping##修改为实际路径
binary = /usr/local/sbin/fping
把#*** Slaves ***下的所有东西注释掉,这里暂时不采用master/slave模式。
#*** Slaves ***
#secrets=/home/oetiker/checkouts/smokeping/trunk/software/etc/smokeping_secrets.dist
#+boomer
#display_name=boomer
#color=0000ff
#+slave2
#display_name=another
#color=00ff00
在Targets下添加监控节点,其中Multi也就是在一张图里画多个监测点的数值:
+ Telecom
menu= TeleCom
title = 21ViaNet(China)Telecom
++ xjzhujunjie
menu = xjzhujunjie
title = xjzhujunjie-server
host = 192.168.101.82
++ JiLin
menu = JiLin
title = JiLin_219.149.194.1
host = 219.149.194.1
++ TeleComMulti
menu = TeleMulti
title = 21ViaNet(China) Telecom Network
host = /Telecom/HeiLJ /Telecom/JiLin
(2)/usr/local/smokeping/htdocs/smokeping.cgi注意修改如下内容即可
# vim /usr/local/smokeping/htdocs/smokeping.cgi
use lib qw(/usr/local/rrdtool/lib/perl);
use lib qw(/usr/local/smokeping/lib);
…
Smokeping::cgi("/usr/local/smokeping/etc/config");
(3)/usr/local/smokeping/bin/smokeping注意修改如下内容即可:
use lib qw(/usr/local/rrdtool/lib/perl);
use lib qw(/usr/local/smokeping/lib);
…
Smokeping::main("/usr/local/smokeping/etc/config");
3.4启动smokeping
(1)编写smokeping启动脚本: 赋予可执行权限,并放在/etc/init.d目录下
# vim /etc/init.d/smokeping
#!/bin/bash
PIDFILE=/usr/local/smokeping/var/smokeping.pid
SMOKEPING=/usr/local/smokeping/bin/smokeping
ERROR=0
RUNNING=0
ARGV="$@"
if [ "x$ARGV" = "x" ] ; then
ARGS=help
fi
for ARG in $@ $ARGS
do
if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`
if kill -0 $PID 2>/dev/null ; then
# smokeping is running
RUNNING=1
else
# smokeping not running but PID file exists => delete PID file
rm -f $PIDFILE
RUNNING=0
fi
else
# smokeping (no pid file) not running
RUNNING=0
fi
case $ARG in
start)
if [ $RUNNING -eq 0 ] ; then
if $SMOKEPING > /dev/null; then
echo "$0 $ARG: smokeping started"
else
echo "$0 $ARG: smokeping could not be started"
ERROR=1
fi
else
echo "$0 $ARG: smokeping is running with PID $PID"
ERROR=2
fi
;;
stop)
if [ $RUNNING -eq 1 ] ; then
if kill $PID ; then
echo "$0 $ARG: smokeping ($PID) stopped"
rm $PIDFILE
else
echo "$0 $ARG: smokeping could not be stopped"
ERROR=3
fi
else
echo "$0 $ARG: smokeping not running"
ERROR=4
fi
;;
restart)
if [ $RUNNING -eq 1 ] ; then
if $SMOKEPING --restart > /dev/null; then
echo "$0 $ARG: smokeping restarted"
else
echo "$0 $ARG: smokeping could not be started"
ERROR=5
fi
else
$0 start
fi
;;
strace_debug)
rm -f /tmp/strace_smokeping
if [ $RUNNING -eq 1 ] ; then
if strace -o/tmp/strace_smokeping $SMOKEPING --restart >/dev/null; then
echo "$0 $ARG: smokeping restarted with strace debug in /tmp/strace_smokeping"
else
echo "$0 $ARG: smokeping strace debug could not be started"
ERROR=6
fi
else
if strace -o/tmp/strace_smokeping $SMOKEPING >/dev/null; then
echo "$0 $ARG: smokeping started with strace debug in /tmp/strace_smokeping"
else
echo "$0 $ARG: smokeping strace debug could not be started"
ERROR=7
fi
fi
;;
status)
if [ $RUNNING -eq 1 ] ; then
echo "$0 $ARG: smokeping is running with PID ($PID)"
else
echo "$0 $ARG: smokeping is not running"
fi
;;
*)
echo "usage: $0 (start|stop|restart|status|strace_debug|help)"
cat
start - start smokeping
stop - stop smokeping
restart - restart smokeping if running or start if not running
status - show status if smokeping is running or not
help - this screen
EOF
;;
esac
done
exit $ERROR
# chmod +x /etc/init.d/smokeping
# ll /etc/init.d/smokeping
-rwxr-xr-x 1 root root 2109 Jun 16 16:52 /etc/init.d/smokeping
(2)检查smokeping配置文件:
# /usr/local/smokeping/bin/smokeping --check
Configuration file '/usr/local/smokeping/etc/config' syntax OK.
(3)启动smokeping:(无法启动)
# service smokeping start
ERROR: slave 'boomer' is not defined in the '*** Slaves ***' section!
/etc/init.d/smokeping start: smokeping could not be started
出现错误à将在后面解决…
(4)配置apache/conf/httpd.conf
# vim /etc/httpd/conf/httpd.conf
Alias /smokeping/ "/usr/local/smokeping/htdocs/"
Alias /cache/ "/usr/local/smokeping/cache/"
Options FollowSymLinks ExecCGI
AllowOverride None
AddHandler cgi-script cgi
Order allow,deny
Allow from all
# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for smokeping.www.iyunv.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
#
(5)测试。修改完后重启apache,在浏览器输入http://192.168.101.81/smokeping/smokeping.cgi
3.5 错误排查与测试:
出现错误à将在后面解决…
# vim /usr/local/smokeping/etc/config
+ FPing
binary = /usr/local/sbin/fping
sourceaddress = 0.0.0.0
*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+192.168.101.82
display_name=192.168.101.82
location=junjie
color=0000ff
++override
Probes.FPing.binary = /usr/local/sbin/fping
Probes.FPing.sourceaddress = 192.168.101.82
# service smokeping restart
ERROR: /usr/local/smokeping/etc/config, line 111: File '/usr/local/smokeping/etc/smokeping_secrets.dist' is world-readable or writable, refusing it
/etc/init.d/smokeping start: smokeping could not be started
# ll /usr/local/smokeping/etc/smokeping_secrets.dist
-rw-r--r-- 1 apache apache 59 Aug 212007 /usr/local/smokeping/etc/smokeping_secrets.dist
# chmod 400 /usr/local/smokeping/etc/smokeping_secrets.dist
# ll /usr/local/smokeping/etc/smokeping_secrets.dist
-r-------- 1 apache apache 59 Aug 212007 /usr/local/smokeping/etc/smokeping_secrets.dist
#
# service smokeping restart
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
ERROR: slave 'boomer' is not defined in the '*** Slaves ***' section!
/etc/init.d/smokeping start: smokeping could not be started
*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+boomer
display_name=boomer
location=junjie
color=00ffff
+192.168.101.82
display_name=192.168.101.82
location=junjie
color=0000ff
++override
Probes.FPing.binary = /usr/local/sbin/fping
Probes.FPing.sourceaddress = 192.168.101.82
+slave2
display_name=another
color=00ff00
# service smokeping restart
/etc/init.d/smokeping start: smokeping started
#
# service httpd restart
Stopping httpd:
Starting httpd: httpd: apr_sockaddr_info_get() failed for smokeping.www.iyunv.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
出现错误à成功解决
四. Smokeping 的其它配置
4.1 监控节点的增加
# vim /usr/local/smokeping/etc/config
+ xjzhujunjie
menu = xjzhujunjie
title = xjzhujunjie-server
################web server###############
++ junjie-web
menu = junjie-web
title = xjzhujunjie 网站 192.168.101.82
host = 192.168.101.82
# service smokeping stop
/etc/init.d/smokeping: line 14: gt: command not found
/etc/init.d/smokeping: line 14: /dev/null: Permission denied
/etc/init.d/smokeping stop: smokeping not running
# service smokeping start
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
/etc/init.d/smokeping start: smokeping started
4.2 报警设置
smokeping的alert设置有点复杂,但是却很好用,设置很灵活,考虑得很周全。它可以使用邮件进行alert,也可以直接调用外部程序进行IM的报警。在我们的监控中主要是采用邮件报警。报警参数设置如下,哪个节点需要报警增加alerts = manyloss即可
# vim /usr/local/smokeping/etc/config
*** Alerts ***
to = xjzhujunjie@www.yunvn.com
from = xjzhujunjie@www.yunvn.com
+someloss
type = loss
pattern = >0%,*30*,>0%,*30*,>0% # in percent
comment = loss 1 packages in 30 continuous 3 times.
+manyloss
type = loss
pattern = >15%,*30*,>15%,*30*,>15% # in percent
comment = loss 5 packages in 30 continuous 3 times.
+rttbad
type = rtt
pattern = ==S,>50,>50 # in milliseconds
comment = For more than two consecutive 50-millisecond delay.
# service smokeping stop
/etc/init.d/smokeping: line 14: gt: command not found
/etc/init.d/smokeping: line 14: /dev/null: Permission denied
/etc/init.d/smokeping stop: smokeping not running
# service smokeping start
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
/etc/init.d/smokeping start: smokeping started
(1)to 表示接受所有报警的邮箱,如果需要在特定的节点报警发送到特定的邮箱则在该节点上增加alertee = xjzhujunjie@www.yunvn.com 即可。
(2)manyloss 表示30个包丢15%的情况 连续出现3次就发报警。
(3)someloss 表示30个包丢1个,连续出现3次就发送报警;rttbad表示连续两个包延迟超过50ms就发送报警。
4.3 画图设置
Smokeping默认设置中是每5分钟画一次图,每5分钟发送20个ping包。网络工程师认为5分钟发送20个ping包太少,建议改为5分钟100个。画图的颜色等也要进行相应的更改: 在Database中,step =300 pings =20 改为 step = 300 pings =100
从图上可以看到,slave主机会自己去检查监测点的情况(loss and rtt),并将数值提交给master主机(通过smokeping.cgi)。值得注意的是,slave并不需要config文件,每次slave提交完数据以后,会询问master它自己的配置文件是否有修改,如果有修改的话slave会进行更新。
其它关于smokeping的使用,待续…….
{:6_387:}{:6_387:} 楼主太有才了,膜拜中…… 商女不知亡国恨、妓女不懂婚外情。 路过,支持一下啦 不要在一棵树上吊死,在附近几棵树上多试试死几次~ 写的真的很不错
页:
[1]