smokeping with tcpping centos 7 環境
阿新 • • 發佈:2018-11-22
本次環境採用centos7,使用centos6的同學就洗洗睡吧,此外一定要做好時間同步,並且關閉防火牆以及selinux,不然安裝可能會失敗的哦。
時間同步方式如下:
yum install ntpdate -y
ntpdate times.aliyun.com
安裝依賴:
yum groupinstall "Compatibility libraries" "Base" "Development tools" -y #很多同學在裝系統的時候選擇包有問題,因此安裝這些保證環境一致性 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 rrdtool rrdtool-perl curl 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 perl-CGI-SpeedyCGI perl-Sys-Syslog popt-devel libidn-devel fping yum install perl-core
安裝tcpping:
cd /usr/bin wget http://www.vdberg.org/~richard/tcpping chmod 755 tcpping
該tcpping是bash指令碼寫的,不過有點問題,後續會教你怎麼改
安裝smokeping:
wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.1.tar.gz tar -xf smokeping-2.7.1.tar.gz cd smokeping-2.7.1 ./configure --prefix=/opt/smokeping make install
修改配置:
cd /usr/local/smokeping/ mkdir cache data var chown apache:apache cache data var chown apache:apache /var/log/smokeping.log chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist cd /usr/local/smokeping/htdocs mv smokeping.fcgi.dist smokeping.fcgi cd /usr/local/smokeping/etc mv config.dist config
編輯config:
*** Probes *** +TCPPing binary = /usr/bin/tcpping # mandatory forks = 5 offset = 50% step = 60 timeout = 15 # The following variables can be overridden in each target section pings = 20 port = 80 # [...] *** Targets *** probe = TCPPing # if this should be the default probe menu = Top title = Network Latency Grapher remark = Welcome to the SmokePing website of xxx Company. \ Here you will learn all about the latency of our network. # [...] + mytarget probe = TCPPing # if the default probe is something else menu = baidu.com title = baidu.com host = www.baidu.com pings = 20 port = 80
apache配置修改:
Alias /cache "/opt/smokeping/cache/" Alias /cropper "/opt/smokeping/htdocs/cropper/" Alias /smokeping "/opt/smokeping/htdocs/smokeping.fcgi" Alias /css "/opt/smokeping/htdocs/css/" Alias /js "/opt/smokeping/htdocs/js/" <Directory "/opt/smokeping"> AllowOverride None Options All AddHandler cgi-script .fcgi .cgi Order allow,deny Allow from all Require all granted DirectoryIndex smokeping.fcgi </Directory>
啟動smokeping,重啟apache
自此,smokeping結合tcpping就安裝完成了。不過你過兒會發現啥資料都沒有,這是因為tcptraceroute包改變了所導致的。我從網上看到別人的tcpping結果應該是:
$ tcpping www.cisco.com seq 0: tcp response from www.cisco.com (198.133.219.25) [open] 155.513 ms seq 1: tcp response from www.cisco.com (198.133.219.25) [open] 148.907 ms seq 2: tcp response from www.cisco.com (198.133.219.25) [open] 153.686 ms seq 3: tcp response from www.cisco.com (198.133.219.25) [open] 150.864 ms seq 4: tcp response from www.cisco.com (198.133.219.25) [open] 147.917 ms
我的:
$ tcpping www.baidu.com traceroute to www.baidu.com (180.97.33.108), 255 hops max, 60 byte packets seq 0: tcp response from 180.97.33.108 (180.97.33.108) <syn,ack> 8.159 ms traceroute to www.baidu.com (180.97.33.107), 255 hops max, 60 byte packets seq 1: tcp response from 180.97.33.107 (180.97.33.107) <syn,ack> 8.288 ms traceroute to www.baidu.com (180.97.33.108), 255 hops max, 60 byte packets seq 2: tcp response from 180.97.33.108 (180.97.33.108) <syn,ack> 8.112 ms traceroute to www.baidu.com (180.97.33.108), 255 hops max, 60 byte packets seq 3: tcp response from 180.97.33.108 (180.97.33.108) <syn,ack> 8.160 ms traceroute to www.baidu.com (180.97.33.107), 255 hops max, 60 byte packets seq 4: tcp response from 180.97.33.107 (180.97.33.107) <syn,ack> 8.484 ms
發覺我多了一行traceroute to …,怪不得沒資料,這裡需要修改tcpping的指令碼:
vi /usr/bin/tcpping 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`
重啟smokeping後你發現有資料了,可是為啥延遲都是恆定的255ms呢,這裡又牽涉到另一個smokeping的bug了,這個bug十年前就有了,作者一直沒修改,連結:http://norman.rasmussen.co.za/62/tcpping-and-smokeping/
你會發現你用tcpping -C -x 1 www.baidu.com 80 永遠返回是255,這就是問題。
照著如下修改:
vi /usr/bin/tcpping rtt=`echo "${ttr}" | sed 's/.*] //' | awk '{print $1}'` 改成 rtt=`echo "${ttr}" | sed 's/.*] //' | awk '{print $5}'`
再重啟下smokeping,好了一切正常了