SmokePing 快速搭建
SmokePing介绍
环境介绍
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网络监控环境部署过程做一记录:
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
tar xf fping-4.1.tar.gz cd fping-4.1 ./configure make && make install
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
##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
出现编码错误
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.logchmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
cd /usr/local/smokeping/htdocsmv 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、图像浏览界面的中文支持
yum -y install wqy-zenhei-fonts.noarch
vim /usr/local/smokeping/etc/config *** Presentation *** charset = UTF-8 #添加这行,解决出图乱码问题 template = /usr/local/smokeping/etc/basepage.html.dist
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访问没有权限
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服务
/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.confServerName 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、设置密码
htpasswd -c /usr/local/smokeping/htdocs/htpasswd smokeping New password: Re-type new password: ##账号是smokeping,密码自行设置
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 配置文件
作者:SRE运维博客
博客地址: https://www.cnsre.cn/