Fork me on GitHub
KeKe Blog

Smokeping安装部署

   SmokePing是一款完全免费的可以用来监控IDC网络质量的工具,并且它有一个基于RRDTool绘图的前端展示界面,用户可以直观的通过浏览器查看各类监控信息。虽然这东西年代久远,但是还是可以做为一个参考的工具使用。根据相关的教程,还是推荐使用zabbix较好。

   由于新公司的业务涉及到海外的市场,有较多的海外服务器,为了提升对关地区的业务服务器的网络状态进行把控,先部署了一套smokeping做为短期的网络状态监控工具,来判断相关的网络情况。

   由于目前没有本地的服务器资源和相关虚拟机资源,只能暂时在个人的香港服务器上进行部署,获取的数据是香港到各个的地区的网络状态。

1 系统环境

  • CentOS Linux release 7.4.1708 (Core)
  • nginx version: nginx/1.12.2
  • spawn-fcgi-1.6.3
  • smokeping-2.6.11

总结:CentOS7.x + Nginx + Fast_cgi + SmokePing

2 安装部署

2.1 安装依赖包

安装EPEL源

1
yum -y install epel-release

安装绘图工具

1
yum -y install rrdtool perl-rrdtool

安装smokeping的相关扩展

1
yum -y install perl-core openssl-devel fping curl gcc-c++

注:目前可先安装这些部分依赖包,后面编译过程中如果出错,smokeping本身提供了相关的依赖包安装脚本。

2.2 安装smokeping

下载源码

1
wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz -P /usr/local/src/

解压源码

1
2
cd /usr/local/src/
tar zxvf smokeping-2.6.11.tar.gz

尝试配置,会出现错误

1
2
3
4
5
6
7
8
9
10
11
12
13
cd smokeping-2.6.11
./configure --prefix=/opt/smokeping
# 报错信息(部分)
# 在目录下执行依赖包安装
./setup/build-perl-modules.sh /opt/smokeping/thirdparty
# 再次进行配置
./configure --prefix=/opt/smokeping
# 编译安装
make install

2.3 配置SmokePing

创建三个必要的目录

1
2
cd /opt/smokeping/htdocs
mkdir cache data var

重命名fcgi

1
mv smokeping.fcgi.dist smokeping.fcgi

修改权限,防止出错

1
chmod 600 /opt/smokeping/etc/smokeping_secrets.dist

编辑配置文件

1
2
3
4
5
6
7
8
9
cd /opt/smokeping/etc
cp config.dist config
vi config
# 需要将imgcache,datadir,piddir的路径改为 /opt/smokeping/htdocs/*
imgcache = /opt/smokeping/htdocs/cache
datadir = /opt/smokeping/htdocs/data
piddir = /opt/smokeping/htdocs/var

2.4 启动运行

使用debug模式尝试运行

1
2
3
cd /opt/smokeping/bin
./smokeping --config=/opt/smokeping/etc/config --debug
# 测试通过后则可以正常启动

启动运行smokeping,并开启日志记录

1
./smokeping --config=/opt/smokeping/etc/config --logfile=smoke.log

3 nginx反向代理

3.1 安装部署

安装Nginx和Fast_fcgi

1
2
3
yum -y install nginx
# 由于nginx本身不支持直接访问fcgi,所以需要装一个spawn-fcgi
yum -y install spawn-fcgi

调整WEB目录所有者

1
chown -R nginx:nginx /opt/smokeping/htdocs

使用spawn-fcgi以nginx用户来启动Smokeping的FCGI程序

1
spawn-fcgi -a 127.0.0.1 -p 9007 -P /var/run/smokeping-fastcgi.pid -u nginx -f /opt/smokeping/htdocs/smokeping.fcgi

3.2 配置访问主机

创建主机配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vi /etc/nginx/conf.d/somkeping.conf
# 主机内容如下
server {
listen 8080;
server_name localhost;
location / {
root /opt/smokeping/htdocs/;
index index.html index.htm smokeping.fcgi;
}
location ~ .*\.fcgi$ {
root /opt/smokeping/htdocs/;
fastcgi_pass 127.0.0.1:9007;
include /etc/nginx/fastcgi_params;
}
}

配置nginx主配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 清空主配置文件
:.,$d
# 输入新的内容
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}

启动nginx

1
systemctl start nginx

关闭防火墙

1
2
systemctl stop firewalld.service
systemctl disable firewalld.service

通过WEB浏览器输入http://ip:8080

4 中文支持

Smokeping的页面和图表都不支持中文,但可以稍作修改让它支持。

安装中文字体

1
yum -y install wqy-zenhei-fonts.noarch

配置文件插入相关编码

1
2
3
4
5
6
7
8
9
10
11
12
13
# 修改smokeping主配置文件
vi /opt/smokeping/etc/config
# 在*** Presentation ***下面插入
charset = utf-8
# 修改分组的配置文件
vi /opt/smokeping/lib/Smokeping/Graphs.pm
# 在 '--end', $stasks[0][2],下面插入
'--font TITLE:20:"WenQuanYi Zen Hei Mono"',
# 最后在主配置文件里修改相关部分为中文

重启smokeping和fcgi即可

1
2
3
4
5
6
ps -ef | grep smokeping
kill -9 进程PID
cd /opt/smokeping/bin
./smokeping --config=/opt/smokeping/etc/config --logfile=smoke.log
spawn-fcgi -a 127.0.0.1 -p 9007 -P /var/run/smokeping-fastcgi.pid -u nginx -f /opt/smokeping/htdocs/smokeping.fcgi

5 参考资料

IP地址分部查询

CentOS7详细安装配置Smokeing

smokeping安装配置使用

smokeping安装部署最佳实践

CentOS6安装smokeping

-------------本文结束 感谢您的阅读-------------