之前的heartbeat双机热备多数都是从其它的网站上抄袭来的。其它的地方配置起来都没什么问题。但mon的配置一直不起做用。今天终于配置成功了,在这里把mon的配置再重新梳理一遍。
其中省略了一些依赖包的安装,因为我的安装过程持续了很长时间有一些记不清了。那些可以参考网上的其它文章。
从www.cpan.org下载并安装Time-HiRes:
http://search.cpan.org/CPAN/authors/id/J/JH/JHI/Time-HiRes-1.9721.tar.gz
tar -xzvf Time-HiRes-1.9721.tar.gz
cd Time-HiRes-1.9721
perl Makefile.PL
make
make test
make install
如果安装时提示:
then set the environment variable LC_ALL to "C" and retry,则设置环境变量LC_ALL:
# export LC_ALL=C
重新编译
perl-Mon-0.11-2.2.el5.rf.noarch.rpm
perl-Convert-BER-1.31.01-1.2.el5.rf.noarch.rpm
perl-Net-Telnet-3.03-1.2.el5.rf.noarch.rpm
perl-Time-HiRes-1.55-3.i386.rpm
perl-Time-Period-1.20-2.el5.rf.noarch.rpm
安装命令:
perl -MCPAN -e shell
cpan>install Time::Period
cpan>install Time::HiRes
cpan>install Convert::BER
cpan>install Mon::Protocol
cpan>install Mon::SNMP
cpan>install Mon::Client
从www.kernel.org/software/mon/下载并安装软件包mon-0.99.2.tar.bz2:
ftp://ftp.kernel.org/pub/software/admin/mon/mon-1.2.0.tar.gz
tar -xzvf mon-1.2.0.tar.gz
cp -r mon-1.2.0 /usr/lib/mon
mkdir /etc/mon
cp /usr/lib/mon/etc/auth.cf /etc/mon
编辑/etc/mon/mon.cf文件
cfbasedir = /etc/mon
alertdir = /usr/lib/mon/alert.d
mondir = /usr/lib/mon/mon.d
statedir = /usr/lib/mon/state.d
logdir = /usr/lib/mon/log.d
dtlogfile = /usr/lib/mon/log.d/dt.log
maxprocs = 20
histlength = 100
randstart = 60s
dtlogging = yes
authtype = getpwnam
hostgroup www 192.168.1.30
watch www
service http
interval 1m
monitor http.monitor
period wd {Sun-Sat}
alert apacherestart.alert
alertevery 45m
然后编辑/usr/lib/mon/alert.d/apacherestart.alert文件
#!/bin/sh
service heartbeat stop
设置服务
cp /usr/lib/mon/etc/S99mon /etc/init.d/mon
vim /etc/init.d/mon
在第二十四行的末尾加上一个 &
#!/bin/sh
#
# start/stop the mon server
#
# You probably want to set the path to include
# nothing but local filesystems.
#
# chkconfig: 2345 99 10
# description: mon system monitoring daemon
# processname: mon
# config: /etc/mon/mon.cf
# pidfile: /var/run/mon.pid
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo -n "Starting mon daemon: "
daemon /usr/lib/mon/mon -c /etc/mon/mon.cf &
echo
touch /var/lock/subsys/mon
;;
stop)
echo -n "Stopping mon daemon: "
killproc mon
echo
rm -f /var/lock/subsys/mon
;;
status)
status mon
;;
restart)
killall -HUP mon
;;
*)
echo "Usage: mon {start|stop|status|restart}"
exit 1
esac
exit 0
最后要说的还有我的配置不知道是哪有问题一直就没有出现过log文件,这也是造成我调试的这么长时间的原因之一。没有日志文件真的是很麻烦。
我的这个配置只是用mon控制了httpd和hearbeat的联动。但httpd关闭后自动关闭heartbeat。mon还是很强大的,还有许多其它的功能,能达到很多种效果,由于时间的原因目前无法一一的调试了。