天天看點

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

目錄

文章目錄

  • 目錄
      • 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頁面中文支援
  1. 先安裝:wqy-zenhei-fonts.noarch
[[email protected] etc]# yum -y install wqy-zenhei-fonts.noarch
           
  1. 編輯smokeping配置檔案(Presentation子產品)

    Presentation子產品下,大概50行左右添加:

    charset = utf-8

  2. 編輯庫檔案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

           

繼續閱讀