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


