https://www.cnblogs.com/weifeng1463/p/10002783.html
本次环境采用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:
该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,好了一切正常了