三、安装及配置Smokeping
1. 下载并安装Smokeping
cd /tmp
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz
tar -zxvf smokeping-2.6.9.tar.gz
cd smokeping-2.6.9
mkdir /usr/local/smokeping
./configure --prefix=/usr/local/smokeping
出现问题是因为需要安装perl的模块,所以运行下面内容即可
解决 'Config::Grammar' ... Failed
Wget http://search.cpan.org/CPAN/authors/id/D/DS/DSCHWEI/Config-Grammar-1.10.tar.gz
tar zxvf Config-Grammar-1.10.tar.gz
cd Config-Grammar
perl Makefile.PL
make
make install
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install
现在smokeping安装完成。
2. 配置Smokeping(基于Apache)
(1) 创建cache、data、var目录
cd /usr/local/smokeping
mkdir cache data var
(2) 在创建日志
touch /var/log/smokeping.log
(3) 授权
chown apache:apache cache data var
chown apache:apache /var/log/smokeping.log
(4) 修改配置文件
mv cache ./htdocs/
cd /usr/local/smokeping/htdocs/
mv smokeping.fcgi.dist smokeping.fcgi
cd /usr/local/smokeping/etc
mv config.dist config
修改配置文件config
vim config
imgcache = /usr/local/smokeping/cache
imgcache = /usr/local/smokeping/htdocs/cache
修改cache的路径与Apache里修改的对应。
cgiurl = http://some.url/smokeping.cgi
把some.url修改为你的ip或者域名
*** Database ***
step = 300
pings = 20
然后修改step,从300改为60,这是检测的时间, pings 从20 改为60, 即60秒ping 60次
(5) .配置完成之后修改密码文件权限
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
3. 修改apache的配置
vi /etc/httpd/conf/httpd.conf
在DocumentRoot "/var/www/html" 这一行之下添加如下内容:
Alias /cache "/usr/local/smokeping/htdocs/cache"
Alias /cropper "/usr/local/smokeping/htdocs/cropper"
Alias /smokeping "/usr/local/smokeping/htdocs"
<Directory "/usr/local/smokeping/htdocs">
AllowOverride None
AddHandler cgi-script .fcgi .cgi
Options ExecCGI
<IfModule dir_module>
DirectoryIndex smokeping.fcgi
</IfModule>
Order allow,deny
Allow from all
</Directory>
4. 启动httpd服务并设置httpd开机启动及关闭防火墙
/etc/init.d/httpd start #启动httpd服务或 service httpd start
chkconfig httpd on #开机启动httpd进程
service iptables stop #关闭防火墙
chkconfig iptables off #开机不启动iptables服务
四、添加smokeping中文支持及rrd图片支持中文
1. 页面支持中文 vi /usr/local/smokeping/etc/config
在配置文件的*** Presentation ***下添加(红色部分为添加内容)
*** Presentation ***
charset = utf-8
template = /usr/local/smokeping/etc/basepage.html.dist
vi basepage.html.dist
2. 如页面左侧层里文字依然是乱码 vi /usr/local/smokeping/etc/basepage.html.dist
可在basepage.html.dist文件头部位置中添加一句。
<HEAD>
<META charset="utf-8" />
<META HTTP-EQUIV="Cache-Control" content="no-cache">
3. 添加rrd图片支持中文,安装中文字库
yum -y install wqy-zenhei-fonts.noarch
修改配置文件 vi /usr/local/smokeping/lib/Smokeping/Graphs.pm
My ($graphret,$xs,$ys) = RRDs::graph
("dummy",
'--start', $tasks[0][1],
'--end', $tasks[0][2],
'--font TITLE:20:"WenQuanYi Zen Hei Mono"',
"DEF:maxping=$cfg->{General}{datadir}${host}.rrd:median:AVERAGE",
'PRINT:maxping:MAX:%le' );
4. 重启smokeping服务service smokeping restart 或者/etc/init.d/smokeping restart
修改/usr/local/smokeping/etc/config 文件的配置参数,必须重启动smokeping程序。
如果重启动smokeping程序失败,根据报错提示删除/usr/local/smokeping/data子文件夹的rrd文件。
七、打开检测主机的Web页面
在Web浏览器里输入http://您的监控主机IP/smokeping
如果遇到500错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/2.2.15 (CentOS) Server at 192.168.2.101 Port 80
说明没有关闭SElinux 选项,关闭就正常setenforce 0
vi /etc/sysconfig/selinux
SELINUX=permissive
[iyunv@localhost ~]# getenforce #查看SElinux 的命令
Permissive #返回的结果是Permissive, 表示已经关闭SElinux了
八、在Web页面增加验证用户名和密码(可选步骤) 1. 修改httpd.conf里的内容
vi /etc/httpd/conf/httpd.conf
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName "Smokeping"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/htpasswd
Require valid-user
DirectoryIndex smokeping.fcgi
</Directory>
注:上面的内容部分已经添加,这里仅添加红色字体内容即可。 2. 设置登录账户与密码
进入cd /usr/local/smokeping/htdocs目录, 执行命令:
htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin
这个是设置登录账户为admin,密码在后面输入,然后重启httpd就可以实现密码验证登录。
service httpd restart
重新登录web页面,会要求输入用户名和密码。