3流プログラマのメモ書き

元開発職→社内SE→派遣で営業支援の三流プログラマのIT技術メモ書き。 このメモが忘れっぽい自分とググってきた技術者の役に立ってくれれば幸いです。(jehupc.exblog.jpから移転中)

CentOS6.4にsmokeping2.6.9を入れてみた

以前に、(Linux)CentOS6.0にSmokePing2.4.2を入れようとしてハマッたでもSmokePingのインストール方法を書いたんですが、SmokePingがバージョンアップして、 "configure, make install" がサポートされインストールが簡単になったようです。

How to install and configure smokeping on CentOS 6 or CentOS 5? | We debug youでCentOS6,CentOS5の場合のSmokePing2.6のインストール方法が細かくまとめられていました。ほぼコピペですが、一応書いておきます。

今回はCentOS6.4(x64)環境にSmokePing2.6.9をソースインストールします。

まず、前準備として必要なパッケージを入れるわけですが、FPingとかはrpmforgeリポジトリにあるので、rpmforgeをインストールしてサードパーティリポジトリが使えるようにします。
(バージョンは適宜最新のものに置き換えてください)

CentOS6の場合:
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
CentOS5の場合:
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

次に必要なパッケージをインストールします。rrdtoolやfpingもここでインストールします。

# yum install mod_fcgid httpd httpd-devel rrdtool fping wget curl bind-utils gcc make
# 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-SpeedCGI perl-ExtUtils-MakeMaker

次にsmokpeing本体のインストールです。 ソースコードをダウンロードします。

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

解凍して、インストール先は /opt/smokeping とします。

# tar -zxvf smokeping-2.6.9.tar.gz -C /opt/
# mkdir /opt/smokeping
# cd /opt/smokeping-2.6.9/setup
# ./build-perl-modules.sh
# cp -r ../thirdparty /opt/smokeping/
# cd ..
# ./configure -prefix=/opt/smokeping
# make install

サービスのスクリプトを作成しますが、既に親切丁寧に作成してくれているので、それを使います。

# wget http://static.wedebugyou.com/smokeping_start_stop.txt
# mv smokeping_start_stop.txt /etc/init.d/smokeping
# chmod 755 /etc/init.d/smokeping

(実際のスクリプトは以下のようになっています。)

#!/bin/sh
#
# smokeping    This starts and stops the smokeping daemon
# chkconfig: 345 98 11
# description: Start/Stop the smokeping daemon
# processname: smokeping
# Source function library.
. /etc/rc.d/init.d/functions

SMOKEPING=/opt/smokeping/bin/smokeping
LOCKF=/var/lock/subsys/smokeping
CONFIG=/opt/smokeping/etc/config

[ -f $SMOKEPING ] || exit 0
[ -f $CONFIG ] || exit 0

RETVAL=0

case "$1" in
  start)
        echo -n $"Starting SMOKEPING: "
        daemon $SMOKEPING
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $LOCKF
        ;;
  stop)
        echo -n $"Stopping SMOKEPING: "
        killproc $SMOKEPING
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $LOCKF
        ;;
  status)
        status smokeping
        RETVAL=$?
        ;;
  reload)
        echo -n $"Reloading SMOKEPING: "
        killproc $SMOKEPING -HUP
        RETVAL=$?
        echo
        ;;
  restart)
        $0 stop
        sleep 3
        $0 start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f $LOCKF ]; then
                $0 stop
                sleep 3
                $0 start
                RETVAL=$?
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
        exit 1
esac

exit $RETVAL

設定ファイル名の変更をします。

# cd /opt/smokeping/etc/
# for foo in *.dist; do cp $foo `basename $foo .dist`; done
# chmod 600 /opt/smokeping/etc/smokeping_secrets.dist

設定ファイルを以下のように書き換えます。

# vi /opt/smokeping/etc/config

contact  = root@localhost (環境に合わせて変更)
mailhost = localhost (変更)
cgiurl   = http://xxx.xxx.xxx.xxx/smokeping/smokeping.cgi (環境に合わせて変更)

*** Presentation ***
charset = UTF-8 (追加)

Webサーバがアクセスするための設定を行います。

# cd /opt/smokeping
# ln -s /opt/smokeping/cache /opt/smokeping/htdocs/cache
# chown -R apache cache
# chown -R apache data

/etc/httpd/conf.d/smokeping.conf を作成し、以下の内容とします。

ScriptAlias /smokeping/smokeping.cgi /opt/smokeping/htdocs/smokeping.fcgi.dist
Alias /smokeping /opt/smokeping/htdocs

<Directory "/opt/smokeping/htdocs">;
Options FollowSymLinks
</Directory>

後は、chkconfig で smokeping と httpd をスタートアップ起動するようにし、サービスを開始します。

# chkconfig smokeping on
# chkconfig httpd on
# service smokeping start
# service httpd start

これで、http://xxx.xxx.xxx.xxx/smokeping/smokeping.cgi にアクセスして、smokepingが動いていればOKです。

アラートメールとかの設定は、(ツール)SmokePingでアラートメールの設定をするを参考にしてください。

参考:
【メモ】SmokePingでlatency視覚化はじめました(1)導入編
SmokePingをインストールしてみた