Ewige前夕
Ewige前夕

在CentOS7上部署SmokePing

缘起

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

安装依赖

进行时间同步

yum install ntp -y
ntpdate times.aliyun.com

接下来安装开发依赖包

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

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

yum install epel-release -y

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

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

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配置

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配置

vim /etc/httpd/conf/httpd.conf

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

https://www.evec.cc/wp-content/uploads/2021/11/1.png

建立一个SmokePing的网站配置

/etc/httpd/conf.d/somekping.conf

写入以下内容

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

https://www.evec.cc/wp-content/uploads/2021/11/2-1024x480.png

至此,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,根据实际情况进行修改

修改监控频率

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

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

https://www.evec.cc/wp-content/uploads/2021/11/3.png

添加监控配置

+ 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

/usr/local/smokeping/bin/smokeping

 

现在查看网页会发现乱码

https://www.evec.cc/wp-content/uploads/2021/11/4-1024x511.png

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

vim /usr/local/smokeping/etc/config

在Presentation下添加charset = utf-8

安装字体包

yum -y install wqy-zenhei-fonts

修改 Graphs.pm

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

在148行附近寻找,增加这一行 '--font TITLE:20""',

https://www.evec.cc/wp-content/uploads/2021/11/5.png

 

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

[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后,可以正常显示中文了

https://www.evec.cc/wp-content/uploads/2021/11/6-1024x510.png

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

vim /usr/local/smokeping/etc/config
imgurl   = cache 改为  imgurl   = http://IP/cache

至此,SmokePing已经搭建完毕且可正常使用。

参考资料

https://www.web-workers.ch/index.php/2017/06/21/how-to-install-smokeping-on-centos-7/

https://tweenpath.net/install-smokeping-centos-7/

http://bbs.chinaunix.net/thread-3778999-1-1.html

https://www.cnblogs.com/nmap/articles/6514332.html

https://wzfou.com/smokeping/

发表评论

textsms
account_circle
email

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Ewige前夕

在CentOS7上部署SmokePing
缘起 公司某一业务网站在晚上有个别用户反映PING值不稳定的情况,由于影响到业务运行,故搭建SmokePing监控业务运行情况,收集数据以便分析。 安装依赖 进行时间同步 yum install ntp…
扫描二维码继续阅读
2021-11-06