1. smokeping简介
smokeping是一款监控网络状态和稳定性的开源软件(它是rrdtool的作者开发的),通过它可以监控到公司IDC的网络状况,如延时,丢包率,是否BGP多线等;
smokeping会向目标设备和系统发送各种类型的测试数据包,测量、记录,并通过rrdtool制图方式,图形化地展示网络的时延情况,进而能够清楚的判断出网络的即时通信情况;通过smokeping来监控IDC机房网络质量情况,可以从监控图上的延时与丢包情况分辨出机房的网络是否稳定,是否为多线,是否为BGP机房以及到各城市的三个运行商网络各是什么情况。如果出现问题,可以有针对性的去处理;如果选择新机房的时候,还可以根据smokeping的监控结果来判断这个机房是否适合。
需要注意的是:smokeping监控的是网络稳定性,而cacti或zabbix监控的是带宽使用情况(即进出口流量)
2. 部署smokeping
2.1. 环境准备
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@linux-node1 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@linux-node1 ~]# getenforce
Disabled
2.2. 安装rrdtool与依赖库
[root@linux-node1 ~]# yum install -y fping perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-CGI-SpeedCGI perl-Time-HiRes perl-ExtUtils-MakeMaker perl-RRD-Simple rrdtool rrdtool-perl curl fping echoping httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fastcgi
2.3. 下载与安装smokeping
[root@linux-node1 ~]# cd /usr/local/src/
[root@linux-node1 src]# wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz
[root@linux-node1 src]# tar xf smokeping-2.6.11.tar.gz
[root@linux-node1 src]# cd smokeping-2.6.11
[root@linux-node1 smokeping-2.6.11]# ./configure --prefix=/usr/local/smokeping
# 如果是第一次安装smokeping程序,一般会出现报错,说没有perl模块支持,需要安装模块后在执行安装程序
** 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/local/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
2.4. 安装依赖的Perl模块
[root@linux-node1 smokeping-2.6.11]# cat PERL_MODULES
FCGI
CGI
CGI::Fast
Config::Grammar
Digest::HMAC_MD5
Net::Telnet
Net::OpenSSH
Net::SNMP
Net::LDAP
Net::DNS
IO::Pty
LWP
# 指定perl源安装perl模块
[root@linux-node1 smokeping-2.6.11]# vim ./setup/sdbs.inc
………………省略内容………………
function perlmodule (){
path=$1;shift
pack=${1:-""}
[ -e $PREFIX/bin/cpanm ] || wget --no-check-certificate -O $PREFIX/bin/cpanm cpanmin.us && chmod 755 $PREFIX/bin/cpanm
cpanm --mirror http://mirrors.aliyun.com/CPAN/ "$path$pack"
[ "$KEEP" = "YES" ] || rm -rf $PREFIX/work $PREFIX/latest-build
}
[root@linux-node1 smokeping-2.6.11]# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
[root@linux-node1 smokeping-2.6.11]# ./configure --prefix=/usr/local/smokeping
………………省略内容………………
** Ready to install Smokeping ******************************
Settings:
PERL5LIB = not set
PERL = /usr/bin/perl
The Smokeping Makefiles use GNU make functionality.
Continue installation with
/usr/bin/gmake install
[root@linux-node1 smokeping-2.6.11]# /usr/bin/gmake install
报错处理:
报错1:
Can't locate Sys/Syslog.pm in @INC (@INC contains: /usr/local/smokeping/thirdparty/lib/perl5/x86_64-linux-thread-multi /usr/local/smokeping/thirdparty/lib/perl5 ../lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ../lib/Smokeping.pm line
解决:yum install -y perl-Sys-Syslog
报错2:smokeping_config.pod around line 81: alternative text 'the master/slave mode' contains non-escaped | or /
POD document had syntax errors at /bin/pod2man line 69.
https://github.com/oetiker/SmokePing/issues/23
3. 配置smokeping
3.1. 创建相关目录
[root@linux-node1 smokeping-2.6.11]# cd /usr/local/smokeping
[root@linux-node1 smokeping]# mkdir cache data var
3.2. 创建日志文件
[root@linux-node1 smokeping-2.6.11]# touch /var/log/smokeping.log
3.3. 目录文件授权
[root@linux-node1 smokeping-2.6.11]# chown apache:apache cache data var
[root@linux-node1 smokeping-2.6.11]# chown apache:apache /var/log/smokeping.log
3.4. 修改配置文件
[root@linux-node1 smokeping]# cd /usr/local/smokeping/htdocs/
[root@linux-node1 htdocs]# mv smokeping.fcgi.dist smokeping.fcgi
[root@linux-node1 htdocs]# cd /usr/local/smokeping/etc
[root@linux-node1 etc]# mv config.dist config
[root@linux-node1 etc]# cp config config.bak
# 修改cgiurl,修改为本机的IP地址或者是域名
[root@linux-node1 etc]# sed -i 's#some.url#smokeping.cainaio.com#' /usr/local/smokeping/etc/config
# 默认检测时间 300 秒修改 60 秒
[root@linux-node1 etc]# sed -i 's#300#60#g' /usr/local/smokeping/etc/config
# 默认 60 秒 ping 20 次,修改为 60 秒 ping 60 次
[root@linux-node1 etc]# sed -i 's#pings = 20#pings = 60#' /usr/local/smokeping/etc/config
# 图像浏览界面的中文支持
[root@linux-node1 etc]# yum -y install wqy-zenhei-fonts.noarch
[root@linux-node1 etc]# vim /usr/local/smokeping/etc/config
charset = utf-8 //第50行下面添加此行内容
# 编辑Graphs.pm
[root@linux-node1 etc]# vim /usr/local/smokeping/lib/Smokeping/Graphs.pm
'--font TITLE:20:"WenQuanYi Zen Hei Mono"', //第147行下面插入边一行内容
# 配置完成之后修改密码文件权限
[root@linux-node1 etc]# chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
3.5. 修改apache的配置
[root@linux-node1 etc]# vim /etc/httpd/conf.d/smokeping.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 all
Options -Indexes +FollowSymlinks
AddHandler cgi-script .fcgi .cgi
Require all granted
DirectoryIndex smokeping.fcgi
</Directory>
3.6. 添加测试数据
接着进行测试数据的自定义(可以将smokeping部署在公司网络下,然后自定义监控各个IDC的网络情况,监控设置如下定义)
[root@linux-node1 etc]# vim /usr/local/smokeping/etc/config # 在最后面添加
+ Other
menu = 三大网络监控
title = 监控统计
++ dianxin
menu = 电信网络监控
title = 电信网络监控列表
host = /Other/dianxin/dianxin-bj /Other/dianxin/dianxin-hlj /Other/dianxin/dianxin-tj /Other/dianxin/dianxin-sc /Other/dianxin/dianxin-sh /Other/dianxin/dianxin-gz
+++ dianxin-bj
menu = 北京电信
title = 北京电信
alerts = someloss
host = 202.96.199.133
+++ dianxin-hlj
menu = 黑龙江电信
title = 黑龙江电信
alerts = someloss
host = 219.147.198.242
+++ dianxin-tj
menu = 天津电信
title = 天津电信
alerts = someloss
host = 219.150.32.132
+++ dianxin-sc
menu = 四川电信
title = 四川电信
alerts = someloss
host = 61.139.2.69
+++ dianxin-sh
menu = 上海电信
title = 上海电信
alerts = someloss
host = 116.228.111.118
+++ dianxin-gz
menu = 广东电信
title = 广东电信
alerts = someloss
host = 113.111.211.22
++ liantong
menu = 联通网络监控
title = 联通网络监控列表
host = /Other/liantong/liantong-bj /Other/liantong/liantong-hlj /Other/liantong/liantong-tj /Other/liantong/liantong-sc /Other/liantong/liantong-sh /Other/liantong/liantong-gz
+++ liantong-bj
menu = 北京联通
title = 北京联通
alerts = someloss
host = 61.135.169.121
+++ liantong-hlj
menu = 黑龙江联通
title = 黑龙江联通
alerts = someloss
host = 202.97.224.69
+++ liantong-tj
menu = 天津联通
title = 天津联通
alerts = someloss
host = 202.99.96.68
+++ liantong-sc
menu = 四川联通
title = 四川联通
alerts = someloss
host = 119.6.6.6
+++ liantong-sh
menu = 上海联通
title = 上海联通
alerts = someloss
host = 210.22.84.3
+++ liantong-gz
menu = 广东联通
title = 广东联通
alerts = someloss
host = 221.5.88.88
++ yidong
menu = 移动网络监控
title = 移动网络监控列表
host = /Other/yidong/yidong-bj /Other/yidong/yidong-hlj /Other/yidong/yidong-tj /Other/yidong/yidong-sc /Other/yidong/yidong-sh /Other/yidong/yidong-gz
+++ yidong-bj
menu = 北京移动
title = 北京移动
alerts = someloss
host = 221.130.33.52
+++ yidong-hlj
menu = 黑龙江移动
title = 黑龙江移动
alerts = someloss
host = 211.137.241.35
+++ yidong-tj
menu = 天津移动
title = 天津移动
alerts = someloss
host = 211.137.160.5
+++ yidong-sc
menu = 四川移动
title = 四川移动
alerts = someloss
host = 218.201.4.3
+++ yidong-sh
menu = 上海移动
title = 上海移动
alerts = someloss
host = 117.131.19.23
+++ yidong-gz
menu = 广东移动
title = 广东移动
alerts = someloss
host = 211.136.192.6
- 修改fping位置
修改smokeping的config配置文件中fping路径
[root@linux-node1 etc]# which fping
/sbin/fping
[root@linux-node1 etc]# vim /usr/local/smokeping/etc/config
binary = /sbin/fping
4. 启动smokeping
启动httpd和smokeping服务
# 最好将httpd.conf中的ServerName www.example.com:80这一行的注释打开
[root@linux-node1 ~]# systemctl start httpd.service
[root@linux-node1 ~]# /usr/local/smokeping/bin/smokeping
设置smokeping开机启动
[root@linux-node1 ~]# echo "/usr/local/smokeping/bin/smokeping" >> /etc/rc.local
设置smokeping环境变量
[root@linux-node1 ~]# echo 'export PATH=/usr/local/smokeping/bin/:$PATH' >> /etc/profile
5. 访问smokeping
本地hosts绑定smokeping.cainaio.com,然后访问上面部署的smokeping界面:
http://smokeping.cainaio.com/smokeping (首次访问,采集数据需要一段时间,等一会就会有数据图形展示)
以上为实验环境,可根据自己实际的网络情况进行监控配置的修改。如果按照上面操作后,直接在网上访问是十分的不安全,需要加入安全访问控制
修改apache的smokeping.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 all
Options All
AddHandler cgi-script .fcgi .cgi
Options -Indexes +FollowSymlinks
DirectoryIndex smokeping.fcgi
AuthName "Smokeping"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/htpasswd
Require valid-user
</Directory>
设置访问的用户名和密码(比如admin/admin)
[root@linux-node1 ~]# htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin
New password:
Re-type new password:
Adding password for user admin
重启apache
[root@linux-node1 ~]# systemctl restart httpd.service
再次访问smokeping界面