smokeping-2.6.8 主从部署

除了上文说的 SP 在报警方面比较强大之外,M/S 也是 SP 一个比较强大的地方,这样,从各地收集的数据更能客观的说明情况。

slave
# hostname
slave1.jaseywang.me
# cd /etc/smokeping
# echo "helloworld" > slavesecrets.conf
# chmod 600 !$
# chown smokeping !$
# cat /etc/default/smokeping

MODE=slave
MASTER_URL=http://master_ip/smokeping/smokeping.cgi
SHARED_SECRET=/etc/smokeping/slavesecrets.conf
SLAVE_NAME=slave1.jaseywang.me

master:
# cd /etc/smokeping
# echo "helloworld" > slavesecrets.conf
# chmod 600 !$
# chown smokeping !$
# echo "slave1.jaseywang.me:helloworld" > smokeping_secrets
# chown www-data !$
# chmod 600 !$
# cat /etc/default/smokeping

MODE=master
# cat config.d/Slaves
*** Slaves ***
secrets=/etc/smokeping/smokeping_secrets
+test.jaseywang.me
display_name=test.jaseywang.me
color=00ff00
# head config.d/Targets
*** Targets ***

slaves = test.jaseywang.me

在启动过程中,会出现类似如下的一些 error:
WARNING: Opening secrets file /etc/smokeping/smokeping_secrets: Permission denied
WARNING: No targets found for slave 'slave1.jaseywang.me'
ERROR: we did not get config from the master. Maybe we are not configured as a slave for any of the targets on the master ?
ERROR: the shared secret file (/etc/smokeping/slavesecrets.conf) is world-readable or writable at /usr/share/perl5/Smokeping.pm line 4117.

原因无非是上面哪个步骤做的有问题。正确的启动 log 如下:
 * Starting latency logger daemon smokeping                                                                                                                    Sent data to Server and got new config in response.
                                                                     [ OK ]
# ps axu | grep sm
root        83  0.0  0.0      0     0 ?        SN   Dec06   0:00 [ksmd]
109      31537  0.3  0.1 143980 27100 ?        Ss   00:38   0:00 /usr/bin/perl /usr/sbin/smokeping –config=/etc/smokeping/config –master-url http://master_ip/smokeping/smokeping.cgi –shared-secret /etc/smokeping/slavesecrets.conf –slave-name slave1.jaseywang.me –cache-dir /var/lib/smokeping –pid-dir /var/run/smokeping
109      31538  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [Curl]
109      31540  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [DNS]
109      31541  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [FPing]
root     31561  0.0  0.0   7624   928 pts/0    R+   00:38   0:00 grep –color=auto sm

以上是在 ubuntu 上,有 /etc/default/smokeping 文件,比较省心,如果是 CentOS 等,则需要像下面这样手动启动:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --master-url http://master_ip/smokeping/smokeping.cgi --shared-secret /usr/local/smokeping/etc/slavesecrets.conf --slave-name test.jaseywang.me --cache-dir /usr/local/smokeping/cache/ --pid-dir /usr/local/smokeping/var/
Sent data to Server and got new config in response.
### parsing dig output…OK
### assuming you are using an fping copy reporting in milliseconds
Note: logging to syslog as local0/info.
Daemonizing /usr/local/smokeping/bin/smokeping …

ref:
https://nsrc.org/workshops/2012/menog-dns-dnssec/attachment/wiki/References/sample-smokeping-master-slave.txt

smokeping-2.6.8 安装

smokeping 2.4.2 的参照这篇文档就好了,可以把 chroot 安装在他默认的地方,这样需要修改的地方就大大减少了。

下面这个是 2.6.8 的记录,简单记录一下步骤,选择性的解释:
# rpm -ivh http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rp
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
# yum makecache
# yum install rrdtool fping  echoping curl dig
# yum install perl  perl-CPAN rrdtool-perl

# cpan
> install FCGI
> install FCGI::ProcManager
> install CGI::Fast
> install Config::Grammar
> install Digest::HMAC_MD5
> install Net::Telnet
> install Net::OpenSSH
> install Net::SNMP
> install Net::DNS
> install Getopt::Long
> install IO::All
> install Socket
> install LWP

# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz -O /usr/local/src/smokeping-2.6.8.tar.gz ; cd /usr/local/src/
# tar zxvf smokeping-2.6.8.tar.gz
# cd smokeping-2.6.8
# ./configure --prefix=/usr/local/smokeping
# gmake install

在进行编译的时候,会出现一些如下的信息,有助于 debug,可以留意。

checking checking for gnu make availablility… /usr/bin/gmake is GNU make
checking checking for perl module 'RRDs'… Ok
checking checking for perl module 'FCGI'… Ok
checking checking for perl module 'CGI'… Ok
checking checking for perl module 'CGI::Fast'… Ok
checking checking for perl module 'Config::Grammar'… Failed
checking checking for perl module 'Digest::HMAC_MD5'… Ok
checking checking for perl module 'LWP'… Ok

上面安装 cpan 的步骤其实在源文件里面已经有了:
# pwd
/usr/local/src/smokeping-2.6.8/setup
# ll build-perl-modules.sh
-rwxr-xr-x. 1 jaseywang jaseywang 287 Oct  5  2011 build-perl-modules.sh

# cd /usr/local/smokeping/etc
# for foo in *.dist; do cp $foo `basename $foo .dist`; done

or
# find . -name '*.dist' -print -execdir sh -c 'mv {} $(basename {} .dist)' \;
# cd ..
# mkdir -p ./{data,cache,var}
# chmod -R 777 cache
# chmod 600 ./etc/smokeping_secrets
# ln -s htdocs/cropper/

检查语法:
# /usr/local/smokeping/bin/smokeping --check

开启 debug 模式,运行完退出:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --debug

启动,将 log 输出至 smokeping.log 文件中:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --logfile=/usr/local/logs/smokeping.log
Continue reading