目录
文章目录
- 目录
-
-
- smokeping概述
- 机器准备
-
-
- 同步时间
- 关闭selinux
-
- 下载相关安装包
- 安装各依赖软件
- 解压fping并编译安装
- 解压echoping并编译安装
- 解压smokeping并编译安装
- 配置smokeping
-
-
- smokeping配置文件组成
- smokeping各配置文件所在路径
- 新建smokeping需要的目录
- 修改smokeping配置文件和上面新建目录一致(General模块)
- 编辑修改apache配置文件(将其与smokeping关联)
- 再次编辑smokeping配置文件(General+Database 模块)
- 设置smokeping_secrets.dist权限为所属者只读
- 设置web页面中文支持
- 修改smokeping图形大小以及历史显示时间
- 设置fping二进制命令路径,和fping安装目录相关
-
- 启动apache服务
- 启动smokeping服务
- 设置环境变量和smokeping开机自启动
- 拓展(导入的配置文件编写---示例)
-
smokeping概述
smokeping是rrdtool的作者Tobi Oetiker的作品,用Perl语言写的,主要是监视网络性能,如:延时,丢包率,是否BGP多线等。它在图形显示方面有很大优势,也是一个很有特点的opensource工具。还有多种探测方式,包括fping、echoping、dig、curl等;监视dns、ssh性能,底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示,非常直观。同时也可以在多个节点收集同一个监测点的数据;很有特色的alert(告警)设置,不只是简单的设置一个阀值。
smokeping 需要多个包的支持(包括perl依赖,还有echoping、fping、smokeping等).
安装这些包可以通过yum和源码编译安装两种方式。(有内置yum包直接yum,没有内置yum包的下载源码包然后解压再进行编译安装)
apache主要提供web页面展示功能,其实也可以用其他web服务器,如nginx。但是apache在linux服务器上都是默认安装的,如果你的linux服务器上的apache应用没有被其他服务占用的话完全可以直接使用apache作web端页面展示的服务器。
机器准备
同步时间
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[[email protected] ~]# uname -r
2.6.32-431.el6.x86_64
[[email protected] ~]# /usr/sbin/ntpdate pool.ntp.org
27 Mar 10:50:24 ntpdate[65535]: step time server 95.216.74.37 offset 25.929951 sec
关闭selinux
[[email protected] ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[[email protected] ~]# getenforce
enforcing
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
[[email protected] ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
下载相关安装包
[[email protected] ~]# cd /home/tools/
[[email protected] tools]# wget http://www.fping.org/dist/fping-3.10.tar.gz
[[email protected] tools]# wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
[[email protected] tools]# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz
[[email protected] tools]# ll
总用量 62656
-rw-r--r--. 1 root root 1660983 3月 27 16:47 echoping-6.0.2.tar.gz
-rw-r--r--. 1 root root 157010 3月 27 16:47 fping-3.10.tar.gz
-rw-r--r--. 1 root root 427185 3月 27 16:47 smokeping-2.6.9.tar.gz
安装各依赖软件
[[email protected] ~]# yum install -y perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-IO-Socket-SSL perl-Socket6 perl-Time-HiRes perl-ExtUtils-MakeMaker
[[email protected] ~]# yum install -y curl httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel
[[email protected] ~]# yum install -y fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel popt popt-devel libidn libidn-devel
[[email protected] ~]# yum install -y rrdtool rrdtool-perl #一定要安装 否则后面编译安装smokeping会报错
解压fping并编译安装
[[email protected] tools]# tar xf fping-3.10.tar.gz
[[email protected] tools]# ll
总用量 62660
-rw-r--r--. 1 root root 1660983 3月 27 16:47 echoping-6.0.2.tar.gz
drwxrwxr-x. 4 1000 1000 4096 5月 5 2014 fping-3.10
-rw-r--r--. 1 root root 157010 3月 27 16:47 fping-3.10.tar.gz
-rw-r--r--. 1 root root 427185 3月 27 16:47 smokeping-2.6.9.tar.gz
[[email protected] tools]# cd fping-3.10
[[email protected] fping-3.10]# ./configure && echo $?
[[email protected] fping-3.10]# make && make install && echo $?
解压echoping并编译安装
[[email protected] tools]# tar xf echoping-6.0.2.tar.gz
[[email protected] tools]# ll
总用量 62664
drwxrwxrwx. 3 1000 1000 4096 4月 10 2007 echoping-6.0.2
-rw-r--r--. 1 root root 1660983 3月 27 16:47 echoping-6.0.2.tar.gz
drwxrwxr-x. 4 1000 1000 4096 3月 27 17:00 fping-3.10
-rw-r--r--. 1 root root 157010 3月 27 16:47 fping-3.10.tar.gz
-rw-r--r--. 1 root root 427185 3月 27 16:47 smokeping-2.6.9.tar.gz
[[email protected] tools]# cd echoping-6.0.2
[[email protected] tools]# ./configure && echo $?
[root@myhost tools]# make && make install && echo $?
解压smokeping并编译安装
[[email protected] tools]# tar xf smokeping-2.6.9.tar.gz
[[email protected] tools]# ll
总用量 62668
drwxrwxrwx. 5 1000 1000 4096 3月 27 17:07 echoping-6.0.2
-rw-r--r--. 1 root root 1660983 3月 27 16:47 echoping-6.0.2.tar.gz
drwxrwxr-x. 4 1000 1000 4096 3月 27 17:00 fping-3.10
-rw-r--r--. 1 root root 157010 3月 27 16:47 fping-3.10.tar.gz
drwxr-xr-x. 9 1003 1001 4096 3月 4 2013 smokeping-2.6.9
-rw-r--r--. 1 root root 427185 3月 27 16:47 smokeping-2.6.9.tar.gz
[[email protected] tools]# cd smokeping-2.6.9
[[email protected] smokeping-2.6.9]# ll
总用量 356
-rw-r--r--. 1 1003 1001 38485 3月 4 2013 aclocal.m4
drwxr-xr-x. 2 1003 1001 4096 3月 4 2013 bin
-rw-r--r--. 1 1003 1001 40492 3月 4 2013 CHANGES
-rwxr-xr-x. 1 1003 1001 179895 3月 4 2013 configure
-rw-r--r--. 1 1003 1001 4210 3月 4 2013 configure.ac
drwxr-xr-x. 2 1003 1001 4096 3月 4 2013 conftools
-rw-r--r--. 1 1003 1001 305 10月 5 2011 CONTRIBUTORS
-rw-r--r--. 1 1003 1001 945 10月 5 2011 COPYRIGHT
drwxr-xr-x. 2 1003 1001 4096 3月 4 2013 doc
drwxr-xr-x. 2 1003 1001 4096 3月 4 2013 etc
drwxr-xr-x. 3 1003 1001 4096 3月 4 2013 htdocs
drwxr-xr-x. 3 1003 1001 4096 3月 4 2013 lib
-rw-r--r--. 1 1003 1001 17976 10月 8 2011 LICENSE
-rw-r--r--. 1 1003 1001 1208 11月 12 2011 Makefile.am
-rw-r--r--. 1 1003 1001 24002 3月 4 2013 Makefile.in
-rw-r--r--. 1 1003 1001 1184 10月 5 2011 README
drwxr-xr-x. 2 1003 1001 4096 3月 4 2013 setup #《==
-rw-r--r--. 1 1003 1001 1910 10月 5 2011 TODO
[[email protected] smokeping-2.6.9]# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty && echo $? #这个安装时间稍稍有点长
[[email protected] tools]# ./configure --prefix=/usr/local/smokeping && echo $?
#这里报错了,错误内容如下:
** Aborting Configure ******************************
If you know where perl can find the missing modules, set
the PERL5LIB environment variable accordingly.
FIRST though, make sure that 'perl' starts the perl
binary you want to use for SmokePing.
Now you can install local copies of the missing modules
by running
./setup/build-perl-modules.sh /usr/smokeping/thirdparty
The RRDs perl module is part of RRDtool. Either use the rrdtool
package provided by your OS or install rrdtool from source.
If you install from source, the RRDs module is located
PREFIX/lib/perl
[roo[email protected] ~]# yum install -y rrdtool rrdtool-perl #再次安装,问题解决。
我之前已经安装了rrdtool rrdtool-perl 并且通过命令 ./setup/build-perl-modules.sh /usr/smokeping/thirdparty 检测rrdtool也是安装成功的,可就是报上面的错误,最后重新yum安装了一遍就好了。┭┮﹏┭┮
##编译安装继续进行
[[email protected] tools]# ./configure --prefix=/usr/local/smokeping && echo $?
[[email protected] tools]# /usr/bin/gmake install && echo $?
到此,所有跟smokeping相关的软件安装工作就完成了。接下来就是各种配置了~
配置smokeping
smokeping配置文件组成
smokeping配置文件主要由以下几个模块组成,不同配置应该放在相应模块的下方。
[[email protected] etc]# cat /usr/local/smokeping/etc/config |grep '\*'
*** General ***
*** Alerts ***
*** Database ***
*** Presentation ***
*** Probes ***
*** Slaves ***
*** Targets ***
smokeping各配置文件所在路径
[[email protected] smokeping-2.6.9]# cd /usr/local/smokeping/
[[email protected] smokeping]# ll
总用量 24
drwxr-xr-x. 2 root root 4096 3月 27 17:39 bin
drwxr-xr-x. 3 root root 4096 3月 27 17:39 etc #smokeping主要配置文件所在路径
drwxr-xr-x. 3 root root 4096 3月 27 17:39 htdocs
drwxr-xr-x. 3 root root 4096 3月 27 17:39 lib
drwxr-xr-x. 3 root root 4096 3月 27 17:39 share
drwxr-xr-x. 6 root root 4096 3月 27 17:35 thirdparty
[[email protected] smokeping]# cd etc/
[[email protected] etc]# ll
总用量 52
-rw-r--r--. 1 apache apache 2041 3月 27 17:39 basepage.html.dist
-rw-r--r--. 1 apache apache 2672 3月 27 17:39 config.dist
drwxr-xr-x. 2 apache apache 4096 3月 27 17:39 examples
-rw-r--r--. 1 apache apache 1563 3月 27 17:39 smokemail.dist
-rw-------. 1 apache apache 59 3月 27 17:39 smokeping_secrets.dist
-rw-r--r--. 1 apache apache 3815 3月 27 17:39 tmail.dist
#带有dist后缀的都是配置文件的模板,使用时需要去掉后缀方能读取。
[[email protected] etc]# cp config.dist config
新建smokeping需要的目录
[[email protected] smokeping]# mkdir cache data var log location
[[email protected] smokeping]# touch /usr/local/smokeping/log/smokeping.log
[[email protected] smokeping]# chown -R apache:apache /usr/local/smokeping
[[email protected] smokeping]# ll
总用量 40
drwxr-xr-x. 2 apache apache 4096 3月 27 17:39 bin
drwxr-xr-x. 2 apache apache 4096 3月 27 17:41 cache #各种缓存路径
drwxr-xr-x. 2 apache apache 4096 3月 27 17:41 data #各种数据图片路径
drwxr-xr-x. 3 apache apache 4096 3月 27 17:39 etc
drwxr-xr-x. 3 apache apache 4096 3月 27 17:39 htdocs
drwxr-xr-x. 3 apache apache 4096 3月 27 17:39 lib
drwxr-xr-x. 2 apache apache 4096 3月 27 17:42 location #详细配置文件的路径
drwxr-xr-x. 2 apache apache 4096 3月 27 17:42 log #日志路径
drwxr-xr-x. 3 apache apache 4096 3月 27 17:39 share
drwxr-xr-x. 6 apache apache 4096 3月 27 17:35 thirdparty
drwxr-xr-x. 2 apache apache 4096 3月 27 17:41 var #pid路径
修改smokeping配置文件和上面新建目录一致(General模块)
*** General ***
owner = Peter Random
contact = [email protected]
mailhost = my.mail.host
sendmail = /usr/sbin/sendmail
# NOTE: do not put the Image Cache below cgi-bin
# since all files under cgi-bin will be executed ... this is not
# good for images.
imgcache = /usr/local/smokeping/cache
imgurl = cache
datadir = /usr/local/smokeping/data
piddir = /usr/local/smokeping/var
cgiurl = http://some.url/smokeping.cgi
smokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/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
一直没有搞明白smokeping为啥在配置文件里面没有指其日志存放路径,于是我就参照其他路径自己在里面添加了:logfile = /usr/local/smokeping/log/smokeping.log 或 logdir = /usr/local/smokeping/log
[[email protected] etc]# /usr/local/smokeping/bin/smokeping --check
ERROR: /usr/local/smokeping/bin/../etc/config, line 14: unknown variable 'logfile'
[[email protected] etc]# /usr/local/smokeping/bin/smokeping --check
ERROR: /usr/local/smokeping/bin/../etc/config, line 14: unknown variable 'logdir'
哎真是个麻烦事儿,所以想要指定smokeping日志路径,需要在启动smokeping的时候指定,eg: /usr/local/smokeping/bin/smokeping --logfile=/usr/local/smokeping/log/smokeping.log
编辑修改apache配置文件(将其与smokeping关联)
[[email protected] etc]# vim /etc/httpd/conf/httpd.conf
最后边添加如下:
Alias /cache "/usr/local/smokeping/cache/"
Alias /cropper "/usr/local/smokeping/htdocs/cropper/"
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
Order allow,deny
Allow from all
DirectoryIndex smokeping.fcgi
</Directory>
如果linux服务器上的80端口被其他服务占用,则还有修改其监听端口。
[[email protected] etc]# vim /etc/httpd/conf/httpd.conf (搜索Listen)
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80
再次编辑smokeping配置文件(General+Database 模块)
-
General模块中:
把cgiurl = http://some.url/smokeping.cgi 中的"some.url" 改成"smokeping服务端IP:http_port" 或"相应的域名"。
-
Database模块中:
把step(监测时间)和pings(ping次数)的值改成自己设定的值。(如果steps=300s,pings=60则表示300秒ping60次)
设置smokeping_secrets.dist权限为所属者只读
[[email protected] etc]# chmod 400 /usr/local/smokeping/etc/smokeping_secrets.dist
[[email protected] etc]# ll /usr/local/smokeping/etc/smokeping_secrets.dist
-r--------. 1 apache apache 59 3月 27 17:39 /usr/local/smokeping/etc/smokeping_secrets.dist
设置web页面中文支持
- 先安装:wqy-zenhei-fonts.noarch
[[email protected] etc]# yum -y install wqy-zenhei-fonts.noarch
-
编辑smokeping配置文件(Presentation模块)
Presentation模块下,大概50行左右添加:
charset = utf-8
- 编辑库文件Graphs.pm
[[email protected] etc]# find / -name Graphs.pm
/home/tools/smokeping-2.6.9/lib/Smokeping/Graphs.pm
/usr/local/smokeping/lib/Smokeping/Graphs.pm
[[email protected] etc]# vi /usr/local/smokeping/lib/Smokeping/Graphs.pm
'--font TITLE:20:"WenQuanYi Zen Hei Mono"', #第147行下边添加
修改smokeping图形大小以及历史显示时间
再次编辑smokeping配置文件(Presentation模块),先注释默认配置,再添加下列内容:
+ charts
menu = 排行榜
title = 排行榜
++ stddev
sorter = StdDev(entries=>4)
title = 综合指数排行
menu = 综合指数排行
format = 综合指数 %f
++ max
sorter = Max(entries=>5)
title = 最大延迟排行
menu = 最大延迟排行
format = 最大延迟时间 %f 秒
++ loss
sorter = Loss(entries=>5)
title = 丢包率排行
menu = 丢包率排行
format = 丢包 %f
++ median
sorter = Median(entries=>5)
title = 平均延迟排行
menu = 平均延迟排行
format = 平均延迟 %f 秒
+ overview
width = 600
height = 50
range = 10h
+ detail
width = 600
height = 200
unison_tolerance = 2
#"Last 3 Hours" 3h
#"Last 30 Hours" 30h
#"Last 10 Days" 10d
#"Last 400 Days" 400d
"Last 10 Minutes" 10m
"Last 30 Minutes" 30m
"Last 4 Hours" 4h
"Last 12 Hours" 12h
"Last 1 Days" 24h
"Last 3 Days" 3d
"Last 1 Weeks" 7d
"Last 1 Mouths" 30d
"Last Half years" 180d
"Last 1 years" 365d
#+ hierarchies
#++ owner
#title = Host Owner
#++ location
#title = Location
设置fping二进制命令路径,和fping安装目录相关
[[email protected] etc]# find / -name fping
/home/tools/fping-3.10/src/fping
/usr/local/src/fping-3.10/src/fping
/usr/local/sbin/fping #fping二进制命令路径
再次编辑smokeping配置文件(Probes模块)
*** Probes ***
+ FPing
binary = /usr/local/sbin/fping
最后编辑smokeping配置文件(Targets 模块)
*** Targets ***
probe = FPing
menu = Top
title = IDC网络节点质量监控
remark = 欢迎来到xxxxxxx公司网络监控平台.
#为了提高配置文件的可读性,我们采取导入自定义的配置文件。
#我这里是监控到全国各省的3个运行商网络各是什麽情况。
@include /usr/local/smokeping/etc/location/telcom
@include /usr/local/smokeping/etc/location/unicom
@include /usr/local/smokeping/etc/location/cmcc
@include /usr/local/smokeping/etc/location/tencent
启动apache服务
[[email protected] ~]# /etc/init.d/httpd start
正在启动 httpd:
[[email protected] etc]# ps -ef |grep apache && lsof -i:80
启动smokeping服务
[[email protected] ~]# /usr/local/smokeping/bin/smokeping
Note: logging to syslog as local0/info.
Daemonizing /usr/local/smokeping/bin/smokeping ...
#出现以上两行则表示smokeping服务启动成功
#如果要指定其日志文件,则用 /usr/local/smokeping/bin/smokeping --logfile=/usr/local/smokeping/log/smokeping.log
[[email protected] ~]#ps -ef |grep smokeping
root 13297 1 0 Mar28 ? 00:00:27 /usr/local/smokeping/bin/smokeping [FPing]
root 15179 61107 0 11:41 pts/4 00:00:00 grep smokeping
设置环境变量和smokeping开机自启动
[[email protected] ~]# echo 'export PATH=/usr/local/smokeping/bin/:$PATH' >> /etc/profile
[[email protected] ~]# echo "/usr/local/smokeping/bin/smokeping --logfile=/usr/local/smokeping/log/smokeping.log" & >> /etc/rc.d/rc.local
[[email protected] ~]# tail -1 /etc/rc.d/rc.local
/usr/local/smokeping/bin/smokeping --logfile=/usr/local/smokeping/log/smokeping.log
拓展(导入的配置文件编写—示例)
[email protected] ~]# /usr/local/smokeping/etc/location/unicom
+ UNICOM
menu = 联通
title = 联通
++ beijing
menu = 北京
title = 北京联通
host = 61.135.169.125
++ tianjin
menu = 天津
title = 天津联通
host = 202.99.96.38
++ hebei
menu = 河北
title = 河北联通
host = 60.8.10.39
++ neimenggu
menu = 内蒙古
title = 内蒙古联通
host = 1.24.200.1
++ liaoning
menu = 辽宁
title = 辽宁联通
host = 218.60.54.164
++ heilongjiang
menu = 黑龙江
title = 黑龙江联通
host = 1.62.111.1
++ jilin
menu = 吉林
title = 吉林联通
host = 125.32.127.2
++ shandong
menu = 山东
title = 山东联通
host = 27.211.0.1
++ shanxi
menu = 山西
title = 山西联通
host = 218.26.171.2
++ shanghai
menu = 上海
title = 上海联通
host = 58.39.117.1
++ zhejiang
menu = 浙江
title = 浙江联通
host = 43.240.204.1
++ jiangsu
menu = 江苏
title = 江苏联通
host = 112.80.248.75
++ anhui
menu = 安徽
title = 安徽联通
host = 36.32.0.1
++ jiangxi
menu = 江西
title = 江西联通
host = 118.212.189.129
++ fujian
menu = 福建
title = 福建联通
host = 202.101.98.55
++ henan
menu = 河南
title = 河南联通
host = 61.54.42.250
++ hubei
menu = 湖北
title = 湖北联通
host = 218.106.115.1
++ hunan
menu = 湖南
title = 湖南联通
host = 42.48.0.1
++ guangdong
menu = 广东
title = 广东联通
host = 163.177.151.110
++ guangxi
menu = 广西
title = 广西联通
host = 110.72.232.1
++ shenzhen
menu = 深圳
title = 深圳联通
host = 58.250.0.1
++ hainan
menu = 海南
title = 海南联通
host = 124.66.0.1
++ sichuan
menu = 四川
title = 四川联通
host = 112.193.58.1
++ chongqing
menu = 重庆
title = 重庆联通
host = 27.9.99.1
++ guizhou
menu = 贵州
title = 贵州联通
host = 58.16.244.1
++ yunnan
menu = 云南
title = 云南联通
host = 14.204.208.1
++ xizang
menu = 西藏
title = 西藏联通
host = 27.98.236.1
++ shaanxi
menu = 陕西
title = 陕西联通
host = 123.139.196.1
++ ningxia
menu = 宁夏
title = 宁夏联通
host = 211.93.0.1
++ gansu
menu = 甘肃
title = 甘肃联通
host = 60.13.0.1
++ qinghai
menu = 青海
title = 青海联通
host = 175.184.184.1
++ xinjiang
menu = 新疆
title = 新疆联通
host = 60.13.194.1