SmokePing2.7.1版本安装过程记录

参考链接

下面的过程抄袭自:
https://blog.newtouch.com/setup-config-smokeping/#%E5%8F%82%E6%95%B0%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE

这里有2.6.11版本的安装过程。在2.7.1版本中,有些地方有变动。
服务器版本CentOS 7.2.

有变化的地方

  1. 新增安装CoreListyum install perl-Module-CoreList
  2. gmake install变更为make install
  3. cache目录改到了htdocs目录下面
  4. Apache虚拟主机配置文件
<VirtualHost *:80>
    ServerName 服务器IP或者域名
    Alias /cache "/usr/local/smokeping/cache/"
    Alias /smokeping "/usr/local/smokeping/htdocs/"
    <Directory  "/usr/local/smokeping/htdocs/">
        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>
    <Directory  "/usr/local/smokeping/cache/">
        AllowOverride None
        Options All
        AllowOverride AuthConfig
        Order allow,deny
        Allow from all
        AuthName "Smokeping"
        AuthType Basic
        AuthUserFile /usr/local/smokeping/htdocs/htpasswd
        Require valid-user
    </Directory>
</VirtualHost>

具体过程

1. 安装时间同步服务

yum -y install ntpdate
ntpdate times.aliyun.com

2. 安装依赖

yum groupinstall "Compatibility libraries" "Base" "Development tools" -y
yum -y install cpan perl perl-FCGI perl-CGI perl-Digest-HMAC perl-Net-Telnet perl-Net-OpenSSH perl-Net-SNMPperl-LDAP perl-Net-DNS perl-IO-Pty-Easy perl-Test-Simple perl-Sys-Syslog perl-libwww-perlperl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-Time-HiResperl-ExtUtils-MakeMaker rrdtool rrdtool-perl curl fping httpd httpd-devel gccmake wget libxml2-devel libpng-devel glib pango pango-devel freetypefreetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fcgidscreen

3. 安装fping

cd /home
wget https://fping.org/dist/fping-3.16.tar.gz
tar -zxvf fping-3.16.tar.gz -C /usr/local/src
cd /usr/local/src/fping-3.16
./configure
make && make install

4. 安装Echoping

cd /home
wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
tar -zxvf echoping-6.0.2.tar.gz -C /usr/local/
cd /usr/local/echoping-6.0.2
yum install -y popt-devel openssl openssl-devel
./configure --prefix=/usr/local/echoping --with-ssl --without-libidn
make && make install

5. 安装SmokePing

cd /home
wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.1.tar.gz
tar -zxvf smokeping-2.7.1.tar.gz -C /usr/local/src
cd /usr/local/src/smokeping-2.7.1
export PERL5LIB=/usr/local/smokeping/thirdparty/lib/perl5/
./configure --prefix=/usr/local/smokeping
make install

5.1 安装Perl模块

perl -MCPAN -e 'install Config::Grammar'
perl -MCPAN -e 'install "LWP::Simple"'
perl -MCPAN -e 'install "Net::SNMP"'
perl -MCPAN -e 'install "Net::LDAP"'
perl -MCPAN -e 'install IO::Pty'
yum install perl-Module-CoreList

6. 创建相关目录和日志文件

cd /usr/local/smokeping
mkdir htdocs/cache data var 
touch /var/log/smokeping.log 
chown apache:apache htdocs/cache data/ var/ /var/log

/usr/local/smokeping/htdocs/cache/ 存放缓存文件;

/usr/local/smokeping/data/ 存放SmokePing的RRD数据文件;

/usr/local/smokeping/var/log/ 存放SmokePing的日志文件;

tail /var/log/httpd/error_log Apache错误日志

7. 参数配置

7.1 生成配置文件

cp /usr/local/smokeping/htdocs/smokeping.fcgi.dist /usr/local/smokeping/htdocs/smokeping.fcgi 
cp /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config

7.2 修改配置文件

*** General ***

owner    = Peter Random
contact  = some@address.nowhere
mailhost = my.mail.host
sendmail = /usr/sbin/sendmail
# NOTE: do not put the Image Cache below cgi-bin
# since all files under cgi-bin will be executed ... this is not
# good for images.
imgcache = /usr/local/smokeping/htdocs/cache #修改cache目录位置
imgurl   = cache
datadir  = /usr/local/smokeping/data
piddir  = /usr/local/smokeping/var
cgiurl   = http://此处修改为服务器ip或者域名/smokeping.cgi
smokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/smokeping/etc/tmail.dist
# specify this to get syslog logging
syslogfacility = local0
# each probe is now run in its own process
# disable this to revert to the old behaviour
# concurrentprobes = no

*** Alerts ***
to = alertee@address.somewhere
from = smokealert@company.xy

+someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = loss 3 times  in a row

*** Database ***

step     = 300 #轮询周期,单位秒
pings    = 20 # 每个周期ping多少次

*** Presentation ***
charset= utf-8  #新增一行,将网页编码指定为UTF-8


#中间省略,没啥好看的

*** Targets ***
probe = FPing
menu = Top
@include targets #新建一个文件来存放要ping的主机

7.3 安装中文字体

yum -y install wqy-zenhei-fonts
vim /usr/local/smokeping/lib/Smokeping/Graphs.pm

修改文件中,增加一行字体配置部分('--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],
            '--font', "TITLE:20:WenQuanYi Zen Hei Mono",
            "DEF:maxping=$cfg->{General}{datadir}${host}.rrd:median:AVERAGE",
            'PRINT:maxping:MAX:%le' );
            my $ERROR = RRDs::error();
            return "RRDtool did not understand your input: $ERROR." if $ERROR;
            $val = $graphret->[0] if $val < $graphret->[0];
        }
        $val = 1e-6 if $val =~ /nan/i;
        $max = { $tasks[0][1] => $val * 1.5 };
    }

修改字符集,增加一行(charset= utf-8)
vim /usr/local/smokeping/etc/config

7.4 增加登陆验证

用户名:smokeping
密码:自行设置

htpasswd -c /usr/local/smokeping/htdocs/htpasswd smokeping
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist

7.5 为SmokePing新增一个Apache虚拟主机配置

vim /etc/httpd/conf.d/smokeping.conf
<VirtualHost *:80>
    ServerName ip或者域名
    Alias /cache "/usr/local/smokeping/htdocs/cache/"
    Alias / "/usr/local/smokeping/htdocs/"
    <Directory  "/usr/local/smokeping/htdocs/">
        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>
    <Directory  "/usr/local/smokeping/htdocs/cache/">
        AllowOverride None
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
        AuthName "Smokeping"
        AuthType Basic
        AuthUserFile /usr/local/smokeping/htdocs/htpasswd
        Require valid-user
    </Directory>
</VirtualHost>

重启Apache服务器service httpd restart
设置cache目录权限chmod 755 -R /usr/local/smokeping/htdocs/cache
给cache目录增加权限管理文件.htaccessvim /usr/local/smokeping/htdocs/cache/.htaccess

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

7.6 修复Web页面一个小Bug

监控点列表超出页面后,并没有滚动条可以滚动。此处修复。
vim /usr/local/smokeping/htdocs/css/smokeping-screen.css
在32行以后.sidebar里面新增一个属性overflow:scroll

.sidebar {
    background: #4c4c4c;
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100%;
    color: #ccc;
    overflow:scroll;
}

7.7 增加监控对象

原教程里面是直接编辑/usr/local/smokeping/etc/config
我这里把这个监控目标配置文件独立了出来,编辑这个文件。

vim /usr/local/smokeping/etc/targets

此处的配置文件用户生成Web页面的菜单,以及监控目标。格式如下:

+ 一级目录,用于url显示,只能用英文
menu = 目录显示的名称,可以用中文
title = 点开目录后,右边显示的标题
++ 二级目录,用于url显示,只能用英文
menu = 二级目录显示的名称,可以用中文
title = 二级目录显示的名称,可以用中文
host = 要监控的目标的ip或者域名
# 只有一级菜单
+ Aliyun
menu = 阿里云
title = 阿里云dns
host = 223.5.5.5


# 二级菜单
+ Euro
menu = 欧洲
title = 欧洲节点
++ Italy
menu = 意大利
title = 意大利节点
host = www.domain.com
++ Britain
menu = 英国
title = 英国xx机房
host = 5.5.5.5


# 三级菜单
+ IDC
menu = IDC LookingGlass
title = 主机商的测试IP

++ Vultr
+++ Vultr-los
menu = 洛杉矶
title = Vultr 洛杉矶
host = losangels.vultr.com
+++ Vultr-tokyo
menu = 东京
title = Vultr 东京
host = tokyo.lg.vultr.com

++ DigitalOcean
+++ Do-london
menu = 伦敦
title = DO 伦敦
host = london.lg.digitalocean.com

+++ Do-tokyo
menu = 东京
title = DO东京
host = tokyo.lg.digitalocean.com

# 将已有的节点重新分类
+ AllTokyo
menu = 所有东京机房的主机
host = IDC\Vultr-tokoy IDC\Do-tokyo

配置在Web页面中的作用

添加新评论