由于公司需要监控机房的网络质量无奈只能安装smokeping,鉴于网上的教程大多都是老版本的,所以今天我就讲诉一下我在centos上安装新版本的过程,有些得不好的地方还请大家多多原谅。以下所有安装包请到http://www.yunvn.com/thread-1589-1-1.html这里下载。
1.先关闭selinux和清空iptables
vim /etc/selinux/config
SELINUX=disabled
iptables -F
2.更改国内比较快的yum源,我修改为ustc的,个人感觉他比较快。
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
vim CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#YunVN.com
#
[base]
name=CentOS-$releasever - Base - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
ok,准备工作已做好,下面我们开始安装了。
3.安装环境所需要的yum包
yum -yinstall libxml2-devel libpng-devel glib pango pango-devel freetypefreetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel perl perl-Net-Telnet perl-Net-DNSperl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6perl-CGI-SpeedyCGI rrdtool-perl
4.安装rrdtool
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz
tar zxvf rrdtool-1.4.7.tar.gz
cd rrdtool-1.4.7
./configure --prefix=/usr/local/rrdtool
make && make install
5.安装smokeping依赖的软件
【cgilib】
tar zxvf cgilib-0.5.tar.gz
cd cgilib-0.5
make
cp libcgi.a /usr/local/lib
cp cgi.h /usr/include
【fping-2.4b2_to】
tar zxvf fping.tar.gz
cd fping-2.4b2_to
./configure
make
make check
make install
whereis fping
fping: /usr/local/sbin/fping
【echoping】
tar zxvf echoping-6.0.0.tar.gz
cd echoping-6.0.0
./configure
make
make test
遇到测试不成功等信息就 ctrl+c 回到命令行;
make install
whereis echoping
echoping: /usr/local/bin/echoping/usr/local/lib/echoping
安装echoping是有可能会报错,这是因为缺少popt支持,我们需要安装popt
要安装popt还需要gettext的支持,首先安装gettext
tar zxvf gettext-0.18.tar.gz
cd gettext-0.18
./configure
make && make install
cd ..
tar zxvf popt-1.10.4.tar.gz
cd popt-1.10.4
./configure
make && make install
cd ..
cd echoping-6.0.0
./configure
make && make install
6.安装smokeping
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz
tar zxvf smokeping-2.6.8.tar.gz
cd smokeping-2.6.8
./configure ?prefix=/usr/local/smokeping
编译的时候会报错提示缺少很多的扩展程序,这时候我们只需要执行一个安装脚本就好了
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
等他安装完再继续编译安装
./configure ?prefix=/usr/local/smokeping
gmake install
安装完毕,下面修改配置文件。
进入bin目录,修改smokeping文件
#vim smokeping
第八行: use lib qw(); # PERL5LIB
修改为: use lib qw(/usr/local/rrdtool/lib/perl);
进入htdocs目录
# mv smokeping.fcgi.dist smokeping.fcgi
进入etc目录
cp config.dist config
修改config文件
#vim config
以下自行修改为自己需要的
owner = YunVN
contact =
mailhost =
修改报警邮箱
*** Alerts ***
to = [email protected]
from = [email protected]
*** Probes ***
+ FPing
binary = /usr/sbin/fping##修改为实际路径
binary = /usr/local/sbin/fping
监控主机是分层结构的,用+号表示
例如+第一层 ++第二层 +++第三层 根据自己情况修改;
在这里,设备名中不能有”.”和“-”,应该还有其他的字符我没有遇到的。
master/slave方式以及其他的一些功能后续补充
+ Test
menu= local
#parents = owner:/Test/James location:/
++ Yunvn
menu = localhost
title =localhost
host = localhost
下面附录我的配置文件,仅供参考。
[[email protected] smokeping]# cat etc/config
*** General ***
owner = YunVN
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.
# This is www.yunvn.com smokeping server!
imgcache = /usr/local/smokeping/cache
imgurl = cache
datadir = /usr/local/smokeping/data
piddir = /usr/local/smokeping/var
cgiurl = http://172.18.85.213/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
*** Alerts ***
to = [email protected]
from = [email protected]
+someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = loss 3 times in a row
*** Database ***
step = 30 #这里是数据刷新时间,默认是300s,我设置为30s刷新
pings = 20
# consfn mrhb steps total
AVERAGE 0.5 1 1008
AVERAGE 0.5 12 4320
MIN 0.5 12 4320
MAX 0.5 12 4320
AVERAGE 0.5 144 720
MAX 0.5 144 720
MIN 0.5 144 720
*** Presentation ***
template = /usr/local/smokeping/etc/basepage.html.dist
+ charts
menu = Charts
title = The most interesting destinations
++ stddev
sorter = StdDev(entries=>4)
title = Top Standard Deviation
menu = Std Deviation
format = Standard Deviation %f
++ max
sorter = Max(entries=>5)
title = Top Max Roundtrip Time
menu = by Max
format = Max Roundtrip Time %f seconds
++ loss
sorter = Loss(entries=>5)
title = Top Packet Loss
menu = Loss
format = Packets Lost %f
++ median
sorter = Median(entries=>5)
title = Top Median Roundtrip Time
menu = by Median
format = Median RTT %f seconds
+ 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
#+ hierarchies
#++ owner
#title = Host Owner
#++ location
#title = Location
*** Probes ***
+ FPing
binary = /usr/local/sbin/fping
*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+boomer
display_name=boomer
color=0000ff
+slave2
display_name=another
color=00ff00
*** Targets ***
probe = FPing
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.
+ Test
menu= local
#parents = owner:/Test/James location:/
++ James
menu = localhost
title =localhost
host = localhost
+DianXinTong
menu = Storage
++Storage
menu = Storage
title = Stoage
host = 192.168.0.2
创建存放数据文件的目录
mkdir c/usr/local/smokeping/data /usr/local/smokeping/var /usr/local/smokeping/cache
修改smokeping的目录为apache运行用户的属主、组
chown -R daemon.daemon smokeping/
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
chmod ?R 777 /usr/local/smokeping/cache /usr/local/smokeping/data /usr/local/smokeping/var
创建smokeping的log文件
touch /var/log/smokeping.log
chown daemon.daemon /var/log/smokeping.log
启动smokeping
perl /usr/local/smokeping/bin/smokeping --logfile=/var/log/smokeping.log
建立smokeping启动脚本,方便启动
vim /etc/init.d/smokeping
添加为以下内容:
#!/bin/bash
#
# chkconfig: 2345 80 05
# Description: Smokeping init.d script
# Hacked by : YunVN - http://www.yunvn.com
# Get function from functions library
. /etc/init.d/functions
# Start the service Smokeping
start() {
echo -n "Starting Smokeping: "
/usr/local/smokeping/bin/smokeping >/dev/null 2>&1
### Create the lock file ###
touch /var/lock/subsys/smokeping
success $"Smokeping startup"
echo
}
# Restart the service Smokeping
stop() {
echo -n "Stopping Smokeping: "
kill -9 `ps ax | grep "/usr/local/smokeping/bin/smokeping" | grep -v grep | awk ’{ print $1 }’` >/dev/null 2>&1
### Now, delete the lock file ###
rm -f /var/lock/subsys/smokeping
success $"Smokeping shutdown"
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status Smokeping
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
给脚本有可执行权限
# chmod 755 /etc/init.d/smokeping
设置开机启动smokeping
Chkconfigure ?level 35 smokeping on
配置apache
#vim /etc/httpd/conf/httpd.conf
最后加入
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
Alias /cache "/usr/local/smokeping/cache"
Alias /cropper "/usr/local/smokeping/htdocs/cropper/"
<Directory /usr/local/smokeping>
AllowOverride None
AddHandler cgi-script cgi fcgi
Options ExecCGI
Order allow,deny
Allow from all
DirectoryIndex smokeping.cgi
</Directory>
设置开机启动httpd
Chkconfig ?level 35 smokeping on
好了,至此安装配置完成;
Gettext安装包下载地址:http://l5.yunpan.cn/lk/313gqhtvvc
最后我们可以实现smokeping登陆配置
Apache服务器已经内置用户验证机制,大家只要适当的加以设置,便可以控制网站的某些部分要用户验证。
编辑httpd.conf
在smokeping配置项中找到AllowOverride修改为
AllowOverride AuthConfig Alias /demo "/usr/local/apache/htdocs/demo"<Directory "/usr/local/apache/htdocs/demo">Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
#AllowOverride AuthConfig 表示进行身份验证这是关键的设置
在/usr/local/smokeping/htdocs/创建.htaccess文件
vi /usr/local/smokeping/htdocs/.htaccess vi /usr/local/apache/htdocs/demo /.htaccess
AuthName " This is Smokeping Server !"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/.htpasswd
require valid-user
AuthName " my share web"
AuthType Basic
AuthUserFile /usr/local/apache/htdocs/demo/.htpasswd
require valid-user
#AuthName 描述,随便写
#AuthUserFile
#密码文件推荐使用.htpasswd,因为apache默认系统对“.ht”开头的文件默认不允许外部读取,安全系数会高一点哦。
说明:文件.htaccess中常用的配置命令有以下几个:
1) AuthName命令:指定认证区域名称。区域名称是在提示要求认证的对话框中显示给用户的(见附图)。
2)AuthType命令:指定认证类型。在HTTP1.0中,只有一种认证类型:basic。在HTTP1.1中有几种认证类型,如:MD5。
3) AuthUserFile命令:指定一个包含用户名和密码的文本文件,每行一对。
4) AuthGroupFile命令:指定包含用户组清单和这些组的成员清单的文本文件。组的成员之间用空格分开,如:
managers:user1 user2
5) require命令:指定哪些用户或组才能被授权访问。如:
require user user1 user2(只有用户user1和user2可以访问)
requiresgroupsmanagers (只有组managers中成员可以访问)
require valid-user (在AuthUserFile指定的文件中任何用户都可以访问)
创建apache的验证用户
htpasswd -c /usr/local/smokeping/htdocs/.htpasswd admin //添加用户admin
htpasswd -c /usr/local/apache/htdocs/test/.htpasswd admin //添加用户llk726
New password: 111111
Re-type new password:111111
Adding password for user admin
#第一次创建用户要用到-c 参数 第2次添加用户,就不用-c参数
如果你们想修改密码,可以如下
htpasswd -m .htpasswd admin
htpasswd -m .htpasswd admin
ok,重启apache服务,然后访问 站点如果顺利的话,应该能看到一个用户验证的弹出窗口,只要填入创建的用户名和密码就行
关于图表的解释:
RTT(Round-Trip Time)
简单说它是一个数据报在网络上两点中间往返一次的时间,是影响 TCP 性能和表征网络运行状况的重要参数。
在网络中实时、准确地测量大量 TCP 设备和系统的 RTT 参数是网络管的重要环节之一。
Smokeping 就是这样的自动测试系统,它向目标设备和系统发送各种类型的测试数据包,测量、记录和展示 RTT。
Median RTT 中间数
它是中间数并不是平均值。Smokeping 有多种类型的探针,探针在默认的设置下,每 300 秒向目标设备发送 20 测探测数据包。假如这 20个数据包都返回的话,它就记录下了 20 个 RTT,那么Median RTT 就是第十个包的 RTT;如果有 5 个包丢失的话,那么 Median RTT 就是第八个返回的包的 RTT 值。
Avg RTT 评价值
它是每一个测试回合中所有RTT的算术评价值。
Avg pkt loss 丢包率
上图中测试的三个服务器,是用默认的 FPing 探针探测该服务器是否在线。Smokepin g就装在 OpenNMS 上,可以看出它的 RTT 最小;奇怪的是它的丢包率却是最大。其它的,一个是美国的一个 Web 服务器,另一个是美国的 Exchange 邮件服务器。
Last 3 Hours 最近的 3 小时
Median Ping RTT (506.2 ms avg)中间数的平均值是 5.6. 2 毫秒。如果是绿色的短横线,说明一 个300 秒的周期内所有的包都返回都有 RTT 的时间记录下来;如果是蓝色的短横线则说明有 2 个包丢失。
Packet Loss:丢包率。从上图中我们看出全都是绿线,所以丢包率当然是0。
Probe:10 HTTP pings using echoping(1) every 300 seconds
每一个绿色的短横线都是一个测试回合 300 秒内用 echoping 测试 HTTP 协议10次。绿色画出的是中间数的位置,一个回合中的其它值都在它附近被以灰度的形式被刻画;灰度的范围越小越好,灰色的范围像是烟雾一样笼罩在中间数附近。在中间数附近的烟越小越好,说明网络很平稳。 RTT 曲线的起伏还显示了网络的负载情况。
下面是官方的smokeping平台,可以去体验一下:
http://oss.oetiker.ch/smokeping-demo