在CentOS7上部署SmokePing

缘起

公司某一业务网站在晚上有个别用户反应PING值不稳定的情况,由于影响到业务运行,故搭建SmokePing监控业务运行情况,收集数据以便分析。

安装依赖

进行时间同步

1
2
yum install ntp -y
ntpdate times.aliyun.com

接下来安装开发依赖包

1
yum groupinstall "Compatibility libraries" "Base" "Development tools" -y

有些软件在epel上,首先安装epel

1
yum install epel-release -y

安装smokeping所依赖的包,因为官方推荐使用apache,这里我们使用apache。nginx也是可以的,但是需要自行配置FCGI。

1
yum install 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 -y

安装SmokePing

1
2
3
4
5
6
7
wget --no-check-certificate http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz   #官网证书用的是Let's Encrypt,有些网络环境无法下载,需要添加 --no-check-certificate 参数
tar xvf smokeping-2.6.8.tar.gz
cd smokeping-2.6.8
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install
/usr/bin/gmake install #第一次安装会出错,需要安装两次

修改SmokePing配置

1
2
3
4
5
6
7
8
9
10
cd /usr/local/smokeping/
mkdir cache data var #需要自行创建这几个目录
touch /var/log/smokeping.log #创建日志文件
chown apache:apache cache data var #阿帕奇权限配置
chown apache:apache /var/log/smokeping.log #阿帕奇权限配置
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist #必须给600权限
cd /usr/local/smokeping/htdocs
mv smokeping.fcgi.dist smokeping.fcgi
cd /usr/local/smokeping/etc
mv config.dist config

配置Apache配置

1
vim /etc/httpd/conf/httpd.conf

<Directory “/var/www/html”> 改成 <Directory “/usr/local/smokeping”>

建立一个SmokePing的网站配置
/etc/httpd/conf.d/somekping.conf
写入以下内容

1
2
3
4
5
6
7
8
9
10
11
Alias /cache "/usr/local/smokeping/cache/"
Alias /cropper "/usr/local/smokeping/htdocs/cropper/"
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
Order allow,deny
Allow from all
DirectoryIndex smokeping.fcgi
</Directory>

之后重启Apache服务器
systemctl restart httpd
访问 http://IP/smokeping

至此,SmokePing搭建完毕,不过现在还是不能使用,我们还需要一些配置。

监控配置

修改SmokePing配置文件
vim /usr/local/smokeping/etc/config
cgiurl = http://some.url/smokeping.cgi 修改为 cgiurl = http://10.1.30.184/smokeping.cgi
10.1.30.184为SmokePing服务器IP,根据实际情况进行修改
修改监控频率

1
2
*** Database ***
step = 600 改为 step = 30

之后删除默认的test数据,数据在配置文件的末尾,从 +Test开始全部删除

添加监控配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
+ Other
menu = 网络监控
title = 监控统计
++ PhiWeb
menu = PhiWeb网络状态
title = PhiWeb网络监控
+++ Master
menu = Phi主控
title = Phi主控
alerts = someloss
host = 12.34.56.78
+++ SlaveServer02
menu = PhiServer02
title = PhiServer02
alerts = someloss
host = 12.34.56.78
+++ SlaveServer03
menu = PhiServer03
title = PhiServer02
alerts = someloss
host = 12.34.56.78

+是第一层,++是第二层,+++ 是第三层,根据实际情况修改

启动SmokePing

1
/usr/local/smokeping/bin/smokeping

现在查看网页会发现乱码

修改配置文件,指定字符集

1
vim /usr/local/smokeping/etc/config

在Presentation下添加charset = utf-8
安装字体包

1
yum -y install wqy-zenhei-fonts

修改 Graphs.pm

1
vim /usr/local/smokeping/lib/Smokeping/Graphs.pm

在148行附近寻找,增加这一行 ‘–font TITLE:20””‘,

SmokePing有个问题,无法重载配置,只能手动Kill掉进程再启动

1
2
3
4
5
6
7
8
9
[root@localhost etc]# /usr/local/smokeping/bin/smokeping
Note: logging to syslog as local0/info.
ERROR: I Quit! Another copy of /usr/local/smokeping/bin/smokeping (87268) seems to be running.
Check /usr/local/smokeping/var/smokeping.pid
[root@localhost etc]# kill 87268
[root@localhost etc]# /usr/local/smokeping/bin/smokeping
Note: logging to syslog as local0/info.
Daemonizing /usr/local/smokeping/bin/smokeping ...
[root@localhost etc]#

重启SmokePing后,可以正常显示中文了

后发现图片不能正常显示,需要更改配置文件

1
vim /usr/local/smokeping/etc/config

imgurl = cache 改为 imgurl = http://IP/cache
至此,SmokePing已经搭建完毕且可正常使用。

参考资料

  1. [How to install SmokePing on CentOS 7] https://www.web-workers.ch/index.php/2017/06/21/how-to-install-smokeping-on-centos-7/
  2. [Install SmokePing on CentOS 7] https://tweenpath.net/install-smokeping-centos-7/
  3. [Smokeping显示不了图 - 监控及自动化运维技术-Chinaunix] http://bbs.chinaunix.net/thread-3778999-1-1.html
  4. [smokeping在centos7.3上安装部署 - nmap - 博客园] https://www.cnblogs.com/nmap/articles/6514332.html
  5. [Smokeping安装与配置] https://wzfou.com/smokeping/

在CentOS7上部署SmokePing
http://www.evec.cc/2021/11/06/centos7-smokeping/
作者
前夕
发布于
2021年11月6日
许可协议