Linux下smokeping網路監控環境部署記錄

散盡浮華發表於2016-06-08

 

smokeping是一款監控網路狀態和穩定性的開源軟體(它是rrdtool的作者開發的),通過它可以監控到公司IDC的網路狀況,如延時,丟包率,是否BGP多線等;
smokeping會向目標裝置和系統傳送各種型別的測試資料包,測量、記錄,並通過rrdtool製圖方式,圖形化地展示網路的時延情況,進而能夠清楚的判斷出網路的即時通訊情況;

通過smokeping來監控IDC機房網路質量情況,可以從監控圖上的延時與丟包情況分辨出機房的網路是否穩定,是否為多線,是否為BGP機房以及到各城市的三個執行商網路各是什麼情況。如果出現問題,可以有針對性的去處理;如果選擇新機房的時候,還可以根據smokeping的監控結果來判斷這個機房是否適合。
需要注意的是:smokeping監控的是網路穩定性,而cacti或zabbix監控的是頻寬使用情況(即進出口流量)

下面就smokeping網路監控環境部署過程做一記錄:
1)安裝相關源
下載地址:https://pan.baidu.com/s/1pKBtm11
提取密碼:erte
[root@bastion-IDC ~]# rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

2)安裝rrdtool與依賴庫
[root@bastion-IDC ~]# yum -y install 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

下載fping並編譯安裝
[root@bastion-IDC ~]# cd /usr/local/src/
[root@bastion-IDC src]# wget http://fping.org/dist/fping-3.10.tar.gz
[root@bastion-IDC src]# tar -zvxf fping-3.10.tar.gz
[root@bastion-IDC src]# cd fping-3.10
[root@bastion-IDC fping-3.10]# ./configure && make && make install

下載echoping並編譯安裝
[root@bastion-IDC ~]# cd /usr/local/src/
[root@bastion-IDC src]# wget http://down1.chinaunix.net/distfiles/echoping-5.2.0.tar.gz
[root@bastion-IDC src]# tar -zvxf echoping-5.2.0.tar.gz
[root@bastion-IDC src]# yum install -y popt libidn popt-devel libidn-devel          //安裝echoping依賴的包
[root@bastion-IDC src]# cd echoping-5.2.0
[root@bastion-IDC echoping-5.2.0]# ./configure && make && make install

3)下載與安裝smokeping
[root@bastion-IDC ~]# cd /usr/local/src/
[root@bastion-IDC src]# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz
[root@bastion-IDC src]# tar -zvxf smokeping-2.6.8.tar.gz
[root@bastion-IDC src]# cd smokeping-2.6.8
[root@bastion-IDC smokeping-2.6.8]# ./configure --prefix=/usr/local/smokeping
出現下面報錯資訊:
** 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

出現問題是因為需要安裝perl的模組,所以執行下面內容即可:
[root@bastion-IDC smokeping-2.6.8]# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
[root@bastion-IDC smokeping-2.6.8]# ./configure --prefix=/usr/local/smokeping
[root@bastion-IDC smokeping-2.6.8]# /usr/bin/gmake install

4)配置smokeping
建立cache、data、var目錄
[root@bastion-IDC yum.repos.d]# cd /usr/local/smokeping
[root@bastion-IDC smokeping]# mkdir cache data var

建立日誌
[root@bastion-IDC smokeping]# touch /var/log/smokeping.log

授權
[root@bastion-IDC smokeping]# chown apache:apache cache data var
[root@bastion-IDC smokeping]# chown apache:apache /var/log/smokeping.log

修改配置檔案
[root@bastion-IDC smokeping]# cd /usr/local/smokeping/htdocs/
[root@bastion-IDC htdocs]# mv smokeping.fcgi.dist smokeping.fcgi
[root@bastion-IDC htdocs]# cd /usr/local/smokeping/etc
[root@bastion-IDC etc]# mv config.dist config
[root@bastion-IDC etc]# cp config config.bak
[root@bastion-IDC etc]# vim config
........
cgiurl = http://smokeping.wangshibo.com/smokeping.cgi              //預設是cgiurl = http://some.url/smokeping.cgi,把some.url修改為你的ip或者域名

*** Database ***

step = 60                   //預設是300,這是檢測的時間

配置完成之後修改密碼檔案許可權
[root@bastion-IDC etc]# chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist

修改apache的配置
[root@bastion-IDC 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"       //smokeping訪問地址就是http://smokeping.wangshibo.com/smokeping
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
Order allow,deny
Allow from all
DirectoryIndex smokeping.fcgi
</Directory>

影象瀏覽介面的中文支援
[root@bastion-IDC etc]# yum -y install wqy-zenhei-fonts.noarch

編輯smokeping的配置檔案
[root@bastion-IDC etc]# vim /usr/local/smokeping/etc/config
charset = utf-8              //第50行下面新增此行內容

編輯Graphs.pm
[root@bastion-IDC etc]# vim /usr/local/smokeping/lib/Smokeping/Graphs.pm
'--font TITLE:20:"WenQuanYi Zen Hei Mono"',                  //第147行下面插入邊一行內容

接著進行測試資料的自定義(可以將smokeping部署在公司網路下,然後自定義監控各個IDC的網路情況,監控設定如下定義)
[root@bastion-IDC 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

修改smokeping的config配置檔案中fping路徑
[root@bastion-IDC etc]# which fping
/usr/local/sbin/fping
[root@bastion-IDC etc]# vim config
......
binary = /usr/local/sbin/fping                 //預設配置的是/usr/sbin/fping

啟動http
[root@bastion-IDC etc]# /etc/init.d/httpd start            //最好將httpd.conf中的ServerName www.example.com:80這一行的註釋開啟

啟動smokeping
[root@bastion-IDC etc]# /usr/local/smokeping/bin/smokeping

設定smokeping開機啟動
[root@bastion-IDC etc]# echo "/usr/local/smokeping/bin/smokeping" >> /etc/rc.local

設定smokeping環境變數
[root@bastion-IDC etc]# echo 'export PATH=/usr/local/smokeping/bin/:$PATH' >> /etc/profile

本地hosts繫結smokeping.wangshibo.com,然後訪問上面部署的smokeping介面:
http://smokeping.wangshibo.com/smokeping    (首次訪問,採集資料需要一段時間,等一會就會有資料圖形展示)

以上為實驗環境,可根據自己實際的網路情況進行監控配置的修改。

如果按照上面操作後,直接在網上訪問是十分的不安全,需要加入安全訪問控制
修改apache的httpd.conf配置(將上面新增的apache配置直接如下覆蓋或再新增如下紅色字型內容)
[root@bastion-IDC 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
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName "Smokeping"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/htpasswd
Require valid-user
DirectoryIndex smokeping.fcgi
</Directory>

設定訪問的使用者名稱和密碼(比如admin/admin)
[root@bastion-IDC etc]# htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin
New password:
Re-type new password:
Adding password for user admin

重啟apache
[root@bastion-IDC etc]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

再次訪問smokeping介面

相關文章