CentOS 6 安装SmokePing教程

smokeping是对IDC网络质量,稳定性等最好的检测工具,包括常规的 ping,dig,echoping,curl等,可以 监视 www 服务器性能,监视 dns 查询性能,监视 ssh 性能等。Smokeping是rrdtool的作者Tobi Oetiker的作品,所以底层也是 rrdtool 做支持。smokeping是一个很老的开源项目了,不过考虑到现网以下两方面的需求,感觉还是有必要部署的。1、针对虚拟化平台主机重启速度较快,普通的监控平台可能敏感度不够;2、业务和网络部门经常有对网络质量和页面访问速度对比的需求。

smokeping安装前,可以参考官方安装页面:

http://oss.oetiker.ch/smokeping/doc/smokeping_install.en.html

具体要求如下:

RRDtool 1.2.x or later
FPing (optional)
EchoPing (Optional)
Curl (Optional)
dig (Optional)
SSH (Optional)
Webserver
Perl 5.8.8 or later(对应的模块如下)
 FCGI
 CGI, CGI::Fast
 Config::Grammar
 LWP
 Socket6 (optional)
 Net::Telnet (optional)
 Net::OpenSSH (optional)
 Net::DNS (optional)
 Net::LDAP (optional)
 IO::Socket::SSL (optional)
 Authen::Radius (optional)


在centos环境下,上述包基本都可以通过增加第三方源epel 进行安装完整

smokeping 默认的是配合apache,因为apache 原生支持cgi 和 fcgi。但是我现在的服务器上跑的是nginx,尽管也可以给apache 单独设置一个非80 的端口,但是对于我这种有强迫症的人感觉非常不爽。。于是乎,就采用nginx 作为apache 的反向代理,来解决这个问题

下面是安装教程:

pre-requisition:
disable selinux and iptables ( or whitelist these ports)

install  epel package

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

 

  1. Install required package
yum install rrdtool fping wget curl bind-utils gcc make gcc-c++

yum install rrdtool-perl

      2. install perl compoment

yum 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-RRD-Simple perl-CGI-SpeedyCGI perl-ExtUtils-MakeMaker

在这里,其实我们不需要手动安装perl component,因为在smokeping 的安装过程中,会有程序来自动安装这个的

     3. install webserver nginx and apache, nginx as a reverse proxy for apache as nginx can’t run cgi application directly

下面开始配置web server, 首先是安装apache,并配置apache监控在8080端口:

yum install httpd -y

chkconfig httpd on

nano /etc/httpd/conf/httpd.conf
and set 

Listen 8080
NameVirtualHost *:8080 ;

save and exit httpd.conf

下面是安装和配置nginx

yum install nginx -y

chkconfig nginx on

service nginx start

下面开始安装smokeping

cd ~

wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz

tar -zxvf smokeping-2.6.11.tar.gz

// 注意,smokeping 默认使用/opt/smokeping, 因此最好按照官网的介绍来

./configure –prefix=/opt/smokeping /usr/bin/gmake install

这样我们就完成了smokeping 的基本安装,下面就是配置smokeping 和webserver了

创建数据文件目录

cd /opt/smokeping

mkdir data var cache

chmod 777 data

chmod 777 var

chmod 777 cache

下面把smokeping 加入自动启动列表

wget https://raw.githubusercontent.com/hippoking/public/master/smokeping

mv smokeping /etc/init.d/smokeping

chmod 755 /etc/init.d/smokeping

 

配置smokeping:

  1. Rename Config Files and set file permissions
cd /opt/smokeping/etc/

for foo in *.dist; do cp $foo `basename $foo .dist`; done

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

如果chmod 600,smokeping 会报错

2 配置config 文件

编辑/opt/smokeping/etc/config

配置文件从github上copy

3 copy smokeping files to apache directory

cp -r /opt/smokeping/htdocs/cropper /var/www/html/

cp /opt/smokeping/htdocs/smokeping.fcgi.dist /var/www/cgi-bin/smokeping.fcgi

ln -s /opt/smokeping/cache /var/www/html

这样我们就配置完了smokeping 和 apache, 但是由于apache 是监听在8080端口的,我们还需要用nginx来反代一下apache

nginx 反代就轻松很多了

下面是一个完整的nginx配置文件:

 

server{
 listen 80;
 server_name www.xxxxxx.com;
 index index.html index.htm index.php default.html default.htm default.php;
 access_log off;
 error_log /var/log/nginx/www.xxxxxx.com.error.log;
 location / {
 proxy_pass http://127.0.0.1:8080;
 #Proxy Settings
 proxy_redirect off;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
 proxy_max_temp_file_size 0;
 proxy_connect_timeout 90;
 proxy_send_timeout 90;
 proxy_read_timeout 90;
 proxy_buffer_size 128k;
 proxy_buffers 6 32k;
 proxy_busy_buffers_size 128k;
 proxy_temp_file_write_size 128k;
 client_max_body_size 50m;
 }
 }

perfect, 整篇文章完工

如果我们想让URL更好看一点,可以加入htaccess 来改写URL

RewriteEngine On
RewriteRule ^$ /cgi-bin/smokeping.fcgi [NC,L]

 

欢迎访问www.icmp.cc 做参考

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.