SmokePing 快速搭建

 

SmokePing介绍

  smokeping是来监控IDC机房网络质量情况,可以从监控图上的延时与丢包情况分辨出机房的网络是否稳定,是否为多线,是否为BGP机房以及到各城市的三个运行商网络各是什么情况。如果出现问题,可以有针对性的去处理;如果选择新机房的时候,还可以根据smokeping的监控结果来判断这个机房是否适合。
  smokeping监控的是网络稳定性,而cacti或zabbix监控的是带宽使用情况(即进出口流量)cdops运维博客

环境介绍

fping-4.1
echoping-6.0.2
smokeping 2.7.3
CentOS Linux release 7.5.1804 (Core)
localhost.localdomain
3.10.0-862.11.6.el7.x86_64

下面就smokeping网络监控环境部署过程做一记录:

centos 6版本和7版本都有测试
centos 6版本不要完全按照此文档操作 会遇到N多的报错
参考文档时一定要注意批注

1.安装apache及所依赖包

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 popt popt-devel libidn libidn-devel perl-Sys-Syslog perl-core -y 

2.安装rrdtool

a.安装依赖的库
yum -y install libxml2-devel libpng-devel glib pango pango-devel  freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel 
b.安装rrdrool
yum -y install perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl   perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-CGI-SpeedCGI perl-Time-HiRes perl-ExtUtils-MakeMaker perl-RRD-Simple rrdtool rrdtool-per 

3.安装smokeping依赖的软件

yum install mod_fcgid bind-utils -y

4. 本地安装

wget wget https://github.com/schweikert/fping/releases/download/v4.1/fping-4.1.tar.gz
wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz
4.1、解压、编译安装fping
tar xf fping-4.1.tar.gz
cd fping-4.1
./configure
make && make install
4.2、解压、编译安装echoping
tar xf echoping-6.0.2.tar.gz
cd echoping-6.0.2
./configure --prefix=/usr/local/echoping --with-ssl --without-libidn
make && make install
4.3、解压、编译安装smokeping
##centos 7 最好用2.7.x 的版本
##centos 6 最好用2.6.x 的版本
tar xf smokeping-2.7.3.tar.gz
cd smokeping-2.7.3
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty ##2.6.9 版本的需要执行 2.7.3 测试可不执行
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install

出现编码错误

修改/usr/local/smokeping/etc/config配置文件
vim /usr/local/smokeping/lib/Smokeping.pm
...
$ENV{LC_NUMERIC}='C';
if (POSIX::setlocale(&POSIX::LC_NUMERIC,"") ne "C") {
    die("Resetting LC_NUMERIC failed - try removing LC_ALL from the environment");
}
...
为:
...
$ENV{LC_ALL}='zh_CN.UTF-8';
if (POSIX::setlocale(&POSIX::LC_ALL,"") ne "zh_CN.UTF-8") {
    die("Resetting LC_NUMERIC failed - try removing LC_ALL from the environment");
}
...

5. 开始配置 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
cd
/usr/local/smokeping/htdocs

mv smokeping.fcgi.dist smokeping.fcgi
cd /usr/local/smokeping/etc
mv config.dist configx

修改config配置

修改如下内容:
cgiurl=http://你的ip/smokeping.cgi
 *** Database ***
  step = 300  此处建议改为 120

6、编辑apache配置文件

vim /etc/httpd/conf/httpd.conf

在结尾添加如下代码:

Alias /cache "/usr/local/smokeping/cache/"

Alias /cropper "/usr/local/smokeping/htdocs/cropper/"

Alias /css "/usr/local/smokeping/htdocs/css"
Alias
/smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
Alias
/js "/usr/local/smokeping/htdocs/js/"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi
-script .fcgi .cgi
Order allow,deny
Allow
from all
DirectoryIndex smokeping.fcgi
</Directory>

7、图像浏览界面的中文支持

a、安装字体
yum -y install wqy-zenhei-fonts.noarch
b、编辑smokeping的配置文件
vim /usr/local/smokeping/etc/config
*** Presentation ***
charset = UTF-8 #添加这行,解决出图乱码问题
template = /usr/local/smokeping/etc/basepage.html.dist
c、编辑Grapsh.pm
vim /usr/local/smokeping/lib/Smokeping/Graphs.pm
#在第160行,下边插入这一行代码
'--font TITLE:20:"WenQuanYi Zen Hei Mono"',
if ($mode =~ /[anc]/){
        my $val = 0;
        for my $host (@hosts){
            my ($graphret,$xs,$ys) = RRDs::graph
            ("dummy",
            '--start', $tasks[0][1],
            '--end', $tasks[0][2],
            "DEF:maxping=$cfg->{General}{datadir}${host}.rrd:median:AVERAGE",
            '--font TITLE:20:"WenQuanYi Zen Hei Mono"',#加在这里
            'PRINT:maxping:MAX:%le' );
            my $ERROR = RRDs::error();
            return "<div>RRDtool did not understand your input: $ERROR.</div>" if $ERROR;
            $val = $graphret->[0] if $val < $graphret->[0];
        }
        $val = 1e-6 if $val =~ /nan/i;
        $max = { $tasks[0][1] => $val * 1.5 };
    }

8、测试数据可自定义

在后边加入自己的数据
看配置文件

9、smokeping的默认配置文件110行的fping安装目录与此次安装目录不相符需修改!

vi /usr/local/smokeping/etc/config
#第110更改fping的目录为
binary = /usr/local/sbin/fping

10、apache访问没有权限

在Apache安装目录下找到/etc/httpd/conf/httpd.conf文件
vim  /etc/httpd/conf/httpd.conf
# 如果是没有修改过此项配置,那默认的配置如下:
<Directory />
    AllowOverride none
    Require all denied
</Directory>
# 将默认设置改成如下配置:
<Directory />
    Options Indexes FollowSymLinks
    AllowOverride  None
    Order allow,deny
    Allow from all
</Directory>

11、启动apache服务和smokeping服务

a、启动apache
/usr/sbin/httpd -k start/restart
启动失败报错
[root@localhost ~]# /usr/sbin/httpd -k restart     
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/nbox.conf:1
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
解决方法
1.AH00548
vim /etc/httpd/conf.d/nbox.conf
#NameVirtualHost *:80注释掉

2.AH00558
编辑httpd.conf文件,搜索
"#ServerName",添加ServerName localhost:80
[root@server conf]# ls
extra httpd.conf magic mime.types original
[root@server conf]# vi httpd.conf

ServerName www.example.com:80

ServerName localhost:80
再重新启动apache 即可。

3.(98)
进入Apache的安装目录,搜索httpd
-ssl.conf,右击文本打开。寻找443替换成其他不常用的端口号,比如442。接下来就可以正常启动Apache了

b、启动smokeping

  /usr/local/smokeping/bin/smokeping

12、设置密码

a.配置密码
htpasswd -c /usr/local/smokeping/htdocs/htpasswd smokeping
New password:
Re-type new password:
##账号是smokeping,密码自行设置
b. 配置文件
vim /etc/http/conf/httpd.conf
##修改下边内容
Alias /cache "/opt/smokeping/htdocs/cache/"
Alias /css "/opt/smokeping/htdocs/css/"
Alias /smokeping "/opt/smokeping/htdocs/smokeping.fcgi"
Alias /js "/opt/smokeping/htdocs/js/"
<Directory "/opt/smokeping">
        AllowOverride None
        Options All
        AddHandler cgi-script .fcgi .cgi
        Order allow,deny 
        Allow from all 
        DirectoryIndex smokeping.fcgi
</Directory>
##改为以下内容
<Directory "/opt/smokeping">
        AllowOverride None
        Options All
        AddHandler cgi-script .fcgi .cgi
        Order allow,deny 
        Allow from all 
        AuthName "Smokeping"  ##新加内容
        AuthType Basic   ##新加内容
        AuthUserFile /opt/smokeping/htdocs/htpasswd   ##新加内容
        Require valid-user  ##新加内容
        DirectoryIndex smokeping.fcgi  
</Directory>

13、设置环境变量

echo 'export PATH=/usr/local/smokeping/bin/:$PATH' >> /etc/profile

14、启动http和smokeping

systemctl restart  httpd
/usr/local/smokeping/bin/smokeping

出现错误

Error: RRD parameter mismatch ('Wrong value of step: /usr/local/smokeping/data/user/taishan/smokeping.rrd has 300, create string has 120'). You must delete /usr/local/smokeping/data/user/taishan/smokeping.rrd or fix the configuration parameters.
解决办法
 rm -rf  /usr/local/smokeping/data/user/taishan/smokeping.rrd 

15、设置开机启动

echo "/usr/local/smokeping/bin/smokeping --logfile=/var/log/smokeping.log 2>&;1 &;" >> /etc/rc.local

16、config 配置文件

17、最终展示

 
 
 

作者:SRE运维博客

博客地址: https://www.cnsre.cn/

相关话题:https://www.cnsre.cn/tags/


posted @ 2020-04-30 13:10  SRE运维博客  阅读(8470)  评论(4编辑  收藏  举报