前言 上次說到要配合Grafana使用的話,必須要先安裝Somkeping,因為擔心把篇幅拉得太長也沒必要,所以拆開來 (´・ω・`)
如果你是之前沒看到,可以從這邊過去 將Somkeping整合進Grafana呈現
如果覺得麻煩,這邊也有自動安裝的腳本可以使用 こっち
進入正題 以下由Centos 7為範例
1 yum install epel-release
. 接著安裝smokeping 所需的套件:
1 yum -y install perl httpd httpd-devel mod_fcgid rrdtool perl-CGI-SpeedyCGI fping rrdtool-perl perl-Sys-Syslog gcc gcc-c++ libxml* pango* freetype-devel zlib-devel libpng-devel libart_lgpl-devel apr-util-devel apr-devel
. 安裝rrdtool
1 yum -y install libart_lgpl-devel zlib-devel libpng-devel freetype-devel cairo-devel libxml2-devel pango-devel dejavu-lgc-fonts* pango* freetype* rrdtool-perl
※中文顯示有問題,則安裝wqy套件
. 安裝CPAN模組:
1 yum -y install perl-CPAN perl-local-lib perl-Time-HiRes
. 安裝好所需的套件後, 現在到官網下載 SmokePing 原始碼安裝, 目前最新的版本是 2.6.11:
1 wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz
. 解壓縮原始碼:
1 tar -zxvf smokeping-2.6.11.tar.gz
. 安裝 SmokePing 所需的 Perl 模組, 以及編譯 SmokePing:
1 2 3 4 cd smokeping-2.6.11/ ./configure --prefix=/usr/local/smokeping ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty make install
. 安裝fping:
1 2 3 4 5 wget http://fping.org/dist/fping-3.10.tar.gz tar -zxvf fping-3.10.tar.gz cd fping-3.10 ./configure make && make install
. 確認Fping的位置
1 2 whereis fping fping: /usr/local/sbin/fping
. 建立資料夾
1 2 3 mkdir /usr/local/smokeping/cache mkdir /usr/local/smokeping/var mkdir /usr/local/smokeping/data
. 變更權限
1 2 3 4 5 6 7 chown -R apache:apache /usr/local/smokeping/cachechown -R apache:apache /usr/local/smokeping/varchown -R apache:apache /usr/local/smokeping/datachown -R nginx:nginx /usr/local/smokeping/cachechown -R nginx:nginx /usr/local/smokeping/varchown -R nginx:nginx /usr/local/smokeping/data
. 設定Apache
1 2 3 4 5 6 7 8 9 10 11 12 13 vim /etc/httpd/conf.d/smokeping.conf Alias /smokeping/cache /usr/local/smokeping/cache/ Alias /smokeping/cropper /usr/local/smokeping/htdocs/cropper/ Alias /smokeping /usr/local/smokeping/htdocs <Directory /usr/local/smokeping> AllowOverride None Options All AddHandler cgi-script .fcgi .cgi Order allow,deny Allow from all </Directory>
. 配置smokeping 設定檔
1 2 3 4 5 mv /usr/local/smokeping/etc/basepage.html.dist /usr/local/smokeping/etc/basepage.htmlmv /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/configmv /usr/local/smokeping/etc/smokemail.dist /usr/local/smokeping/etc/smokemailmv /usr/local/smokeping/etc/smokeping_secrets.dist /usr/local/smokeping/etc/smokeping_secretsmv /usr/local/smokeping/etc/tmail.dist /usr/local/smokeping/etc/tmail
. 修改smokeping_secrets權限
1 chmod 400 /usr/local/smokeping/etc/smokeping_secrets
. 設定smokeping config
vim /usr/local/smokeping/etc/config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 owner = Owner contact = example.com mailhost = mail.example.com sendmail = /usr/sbin/sendmail imgcache = /usr/local/smokeping/cache imgurl = cache datadir = /usr/local/smokeping/data piddir = /usr/local/smokeping/var cgiurl = http://localhost/bin/smokeping_cgi smokemail = /usr/local/smokeping/etc/smokemail tmail = /usr/local/smokeping/etc/tmail *** Presentation *** template = /usr/local/smokeping/etc/basepage.html charset = utf-8 *** Slaves *** secrets=/usr/local/smokeping/etc/smokeping_secrets +boomer display_name=boomer color=0000ff
. 建立啟動程序 vim /etc/init.d/smokeping
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 #!/bin/sh # # smokeping This starts and stops the smokeping daemon # chkconfig: 345 98 11 # description: Start/Stop the smokeping daemon # processname: smokeping # Source function library. . /etc/rc.d/init.d/functions SMOKEPING=/usr/local/smokeping/bin/smokeping LOCKF=/var/lock/subsys/smokeping CONFIG=/usr/local/smokeping/etc/config [ -f $SMOKEPING ] || exit 0 [ -f $CONFIG ] || exit 0 RETVAL=0 case "$1" in start) echo -n $"Starting SMOKEPING: " daemon $SMOKEPING RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCKF ;; stop) echo -n $"Stopping SMOKEPING: " killproc $SMOKEPING RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $LOCKF ;; status) status smokeping RETVAL=$? ;; reload) echo -n $"Reloading SMOKEPING: " killproc $SMOKEPING -HUP RETVAL=$? echo ;; restart) $0 stop sleep 3 $0 start RETVAL=$? ;; condrestart) if [ -f $LOCKF ]; then $0 stop sleep 3 $0 start RETVAL=$? fi ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" exit 1 esac exit $RETVAL
. 修改啟動檔權限
1 chmod 755 /etc/init.d/smokeping
. 修改網頁檔名
1 mv /usr/local/smokeping/htdocs/smokeping.fcgi.dist /usr/local/smokeping/htdocs/smokeping.cgi
. 啟動smokeping
可能出現的例外錯誤
如果出現Apache 403 Forbidden
在conf中加入
Require All granted
TCP Ping 的BUG修改 經過大排長龍的設定後,自此Smokeping就安裝完成啦~但你會發現Tcpping的時候資料很奇怪,是因為tcptraceroute呈現改變了,因此要以下調整:
vim /usr/bin/tcpping
1 2 3 4 5 6 7 8 ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>&1` 改成 ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* |grep -v traceroute 2>&1` ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* 2>/dev/null` 改成 ttr=`tcptraceroute -f ${ttl} -m ${ttl} -q ${q} -w ${w} $* |grep -v traceroute 2>/dev/null`
第二個 bug 為甚麼延遲都是255,上網查了之後這是smokeping的BUG。
你用tcpping -C -x 1 www.google.com 80 永遠都是255。
照着如下修改:
vi /usr/bin/tcpping
1 2 3 rtt=`echo "${ttr} " | sed 's/.*] //' | awk '{print $1}' ` 改成 rtt=`echo "${ttr} " | sed 's/.*] //' | awk '{print $5}' `
修改完後再重啟smokeping就完成了。