heartbeat
配置
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
一.
网络结构
VIP[eth0:0]:172.18.199.131
lvs01:172.18.199.128
lvs02:172.18.199.129
realserver:172.18.199.130
二.
安装heartbeat
yum install heartbeat-*
yum install heartbeat-ldirectord
安装的包有:heartbeat-pils,heartbeat-stonith,heartbeat,heartbeat-ldirectord
其中heartbeat-ldirectord需要有perl的相关支持
三.
将相关配置文件copy到/etc/ha.d目录下
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
四.
编辑/etc/hosts文件
vi /etc/hosts
172.18.199.128 lvs01
172.18.199.129 lvs02
172.18.199.130 www.lvstest.com
五.编辑ha.cf文件
vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
baud 19200
bcast eth0
auto_failback on
node lvs01
node lvs02
ping_group group1 172.18.199.128 172.18.199.129
respawn root /usr/lib/heartbeat/ipfail
注意node 的名字要与uname –n 命令相同,可以编辑/etc/sysconfig/network 添加HOSTNAME指定
五.
编辑authkeys文件
vi /etc/ha.d/authkeys
auth 1
1 sha1 123456
将authkeys文件的权限改为600
chmod 600 /etc/ha.d/authkeys
六.
编辑haresources 文件
vi /etc/ha.d/haresources
lvs01 IPaddr::172.18.199.131/24/eth0:0 ldirectord
七.编辑ldirectord文件
vi /etc/ha.d/ldirectord.cf
checktimeout=3
checkinterval=1
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
quiescent=yes
virtual=172.18.199.131:80
real=172.18.199.130:80 gate
fallback=127.0.0.1:80 gate
service=http
scheduler=rr
persistent=600
protocol=tcp
checktype=connect
checkport=80
virtualhost=www.lvstest.com
七.
将配置文件复制到备份lvs上
scp /etc/ha.d/* 172.18.199.129:/etc/ha.d/
最后在主备服务器上启动heartbeat,并测试服务。
配置日志服务器
配置日志服务器,接收远程日志:
vi /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-r -m 0"
加上-r参数接收远程机器的日志
service syslog restart
配置客户端,将日志发送到远程主机:
vi /etc/syslog.conf
local0.* @172.18.199.129
local1.* @172.18.199.129
local2.* @172.18.199.129
local3.* @172.18.199.129
将apache的日志发送到日志服务器
编辑httpd.conf文件,修改
ErrorLog "| /usr/bin/logger -t httpd -p local1.info"
CustomLog "| /usr/bin/logger -t apache -p local2.info" combined
重启服务
service httpd restart
在日志服务器上编辑syslog.conf
local0.* /opt/log/ha-log
local1.* /opt/log/error.log
local2.* /opt/log/access.log
然后重启服务:
service syslog restart
将日志进行rotate
vi /etc/logrotate.conf
添加
/var/log/error.log{
daily
create
rotate 1
prerotate
/usr/bin/chattr -a /var/log/error.log
endscript
postrotate
/usr/bin/killall -HUP syslogd
/usr/bin/chattr +a /var/log/error.log
mv /var/log/error.log.1 /opt/log/error_log.`date -d "-1 days"+%Y%m%d`
gzip /opt/log/error_log.`date -d "-1 days" +%Y%m%d`
endscript
}
/var/log/access_log.log{
daily
create
rotate 1
prerotate
/usr/bin/chattr -a /var/log/access.log
endscript
postrotate
/usr/bin/killall -HUP syslogd
/usr/bin/chattr +a /var/log/access.log
mv /var/log/accessz.log.1 /opt/log/access_log.`date -d "-1 days" +%Y%m%d`
gzip /opt/log/access_log.`date -d "-1 days" +%Y%m%d`
endscript
}
daily
create
rotate 1
prerotate
/usr/bin/chattr -a /var/log/access.log
endscript
postrotate
/usr/bin/killall -HUP syslogd
/usr/bin/chattr +a /var/log/access.log
mv /var/log/accessz.log.1 /opt/log/access_log.`date -d "-1 days" +%Y%m%d`
gzip /opt/log/access_log.`date -d "-1 days" +%Y%m%d`
endscript
}
转载于:https://blog.51cto.com/linuxlab/315279