smokeping+apache可視化監控網絡(安裝+配置)

目錄

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端頁面展示的服務器。

機器準備

同步時間
[root@myhost ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@myhost ~]# uname -r
2.6.32-431.el6.x86_64
[root@myhost ~]#  /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
[root@myhost ~]# 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 

[root@myhost ~]# getenforce
enforcing
[root@myhost ~]# setenforce 0
[root@myhost ~]# getenforce
Permissive
[root@myhost ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g"   /etc/sysconfig/selinux 

下載相關安裝包

[root@myhost ~]# cd  /home/tools/
[root@myhost tools]# wget http://www.fping.org/dist/fping-3.10.tar.gz
[root@myhost tools]# wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
[root@myhost tools]# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz
[root@myhost 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

安裝各依賴軟件

[root@myhost ~]# 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 
[root@myhost ~]# yum install -y curl httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel 
[root@myhost ~]# yum install -y fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel popt popt-devel libidn libidn-devel
[root@myhost ~]# yum install -y rrdtool rrdtool-perl    #一定要安裝 否則後面編譯安裝smokeping會報錯

解壓fping並編譯安裝

[root@myhost tools]# tar xf fping-3.10.tar.gz 
[root@myhost 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
[root@myhost tools]# cd fping-3.10
[root@myhost fping-3.10]# ./configure && echo $?
[root@myhost fping-3.10]# make && make install && echo $?

解壓echoping並編譯安裝

[root@myhost tools]# tar xf echoping-6.0.2.tar.gz 
[root@myhost 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
[root@myhost tools]# cd echoping-6.0.2
[root@myhost tools]# ./configure && echo $?
[root@myhost tools]# make && make install && echo $?

解壓smokeping並編譯安裝

[root@myhost tools]# tar xf smokeping-2.6.9.tar.gz 
[root@myhost 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
[root@myhost tools]# cd smokeping-2.6.9
[root@myhost 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

[root@myhost smokeping-2.6.9]# ./setup/build-perl-modules.sh   /usr/local/smokeping/thirdparty  && echo $?         #這個安裝時間稍稍有點長
[root@myhost 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

[root@myhost ~]# yum install -y rrdtool rrdtool-perl    #再次安裝,問題解決。

我之前已經安裝了rrdtool rrdtool-perl 並且通過命令 ./setup/build-perl-modules.sh /usr/smokeping/thirdparty 檢測rrdtool也是安裝成功的,可就是報上面的錯誤,最後重新yum安裝了一遍就好了。┭┮﹏┭┮

##編譯安裝繼續進行
[root@myhost tools]# ./configure --prefix=/usr/local/smokeping    && echo $?
[root@myhost tools]# /usr/bin/gmake install && echo $?

到此,所有跟smokeping相關的軟件安裝工作就完成了。接下來就是各種配置了~

配置smokeping

smokeping配置文件組成

smokeping配置文件主要由以下幾個模塊組成,不同配置應該放在相應模塊的下方。

[root@myhost etc]# cat /usr/local/smokeping/etc/config |grep '\*'
*** General ***
*** Alerts ***
*** Database ***
*** Presentation ***
*** Probes ***
*** Slaves ***
*** Targets ***
smokeping各配置文件所在路徑
[root@myhost smokeping-2.6.9]# cd /usr/local/smokeping/
[root@myhost 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
[root@myhost smokeping]# cd etc/
[root@myhost  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後綴的都是配置文件的模板,使用時需要去掉後綴方能讀取。
[root@myhost  etc]# cp  config.dist   config
新建smokeping需要的目錄
[root@myhost smokeping]# mkdir cache data var log location
[root@myhost smokeping]# touch /usr/local/smokeping/log/smokeping.log
[root@myhost smokeping]# chown -R apache:apache /usr/local/smokeping
[root@myhost 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

[root@myhost etc]#  /usr/local/smokeping/bin/smokeping  --check
ERROR: /usr/local/smokeping/bin/../etc/config, line 14: unknown variable 'logfile'
[root@myhost 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關聯)
[root@myhostr 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端口被其他服務佔用,則還有修改其監聽端口。

[root@myhostr 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權限爲所屬者只讀
[root@myhost etc]# chmod 400 /usr/local/smokeping/etc/smokeping_secrets.dist
[root@myhost 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頁面中文支持
  1. 先安裝:wqy-zenhei-fonts.noarch
[root@myhostr etc]# yum -y install wqy-zenhei-fonts.noarch
  1. 編輯smokeping配置文件(Presentation模塊)
    Presentation模塊下,大概50行左右添加:
    charset = utf-8

  2. 編輯庫文件Graphs.pm

[root@myhost  etc]# find / -name Graphs.pm
/home/tools/smokeping-2.6.9/lib/Smokeping/Graphs.pm
/usr/local/smokeping/lib/Smokeping/Graphs.pm
[root@myhost  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安裝目錄相關
[root@myhost 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服務

[root@myhost ~]# /etc/init.d/httpd start
正在啓動 httpd:
[root@myhost  etc]# ps -ef |grep apache  && lsof -i:80

啓動smokeping服務

[root@myhost ~]# /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

[root@myhost ~]#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開機自啓動

[root@myhost ~]# echo 'export PATH=/usr/local/smokeping/bin/:$PATH' >> /etc/profile

[root@myhost ~]# echo "/usr/local/smokeping/bin/smokeping  --logfile=/usr/local/smokeping/log/smokeping.log" & >> /etc/rc.d/rc.local
[root@myhost ~]# tail -1 /etc/rc.d/rc.local
/usr/local/smokeping/bin/smokeping  --logfile=/usr/local/smokeping/log/smokeping.log

拓展(導入的配置文件編寫—示例)

root@myhost ~]#  /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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章