yum install heartbeat cluster-glue Since you most likely will also want to install Pacemaker (beyond the scope of this manual), do so by issuing the following commands as well:
yum install resource-agents pacemaker 12. 修改heartbeat配置文件(以下步骤需要在2台node上执行)
复制配置文件,资源文件,认证密钥文件
cp /usr/share/doc/heartbeat-3.0.4/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/
cp /usr/share/doc/heartbeat-3.0.4/authkeys /etc/ha.d/
之后编辑 配置文件。
vi /etc/ha.d/ha.cf
logfile /var/log/ha-log (主要检查日志文件)
logfacility local0
keepalive 1 #定义心跳频率1s
deadtime 10 #如果其他节点10S内没有回应,则确认其死亡
warntime 5 #确认一个节点连接不上5S之后将警告信息写入日志
initdead 60 #在其他节点死掉之后,系统启动前需要等待的时间,一般为deadtime的两倍
udpport 694 #端口号。
ucast eth0 192.168.135.129(对端IP) #对端的IP,在备机上改为192.168.135.130(本机IP)
auto_failback off
node web1 (IP)
node web2 (IP)
chmod 600 /etc/ha.d/authkeys
vi /etc/ha.d/authkeys
auth 1
1 crc
vi /etc/ha.d/haresources
web1 IPaddr::192.168.135.0/24/eth1 drbddisk::r0 Filesystem::/dev/drbd1::/drbd::ext3 httpd
资源文件说明:
test1– the hosname that will be the primary node
drbddisk::r0 – activate the r0 resource disk (make sure r0 corresponds to whatever your resource is named)
Filesystem::/dev/drbd1::/drbd::ext3 – mount /dev/drbd1 on /drbd as ext3 filesystem
nginx–the service we’re going to watch over and take care of, in this case nginx(which wasn’t really what I was configuring, but it’s the easiest to show as an example)
安装Keepalived
yum install keepalived 当然我说的是yum 安装 ,也可以去官网 http://www.keepalived.org/software/
找到你所需要的 版本。
[root@web1 ~]# keepalived --help Keepalived v1.2.7 (02/21,2013) Usage: keepalived keepalived -n keepalived -f keepalived.conf keepalived -d keepalived -h keepalived -v Commands: Either long or short options are allowed. keepalived --vrrp -P Only run with VRRP subsystem. keepalived --check -C Only run with Health-checker subsystem. keepalived --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop. keepalived --dont-release-ipvs -I Dont remove IPVS topology on daemon stop. keepalived --dont-fork -n Dont fork the daemon process. keepalived --use-file -f Use the specified configuration file. Default is /etc/keepalived/keepalived.conf. keepalived --dump-conf -d Dump the configuration data. keepalived --log-console -l Log message to local console. keepalived --log-detail -D Detailed log messages. keepalived --log-facility -S 0-7 Set syslog facility to LOG_LOCAL[0-7]. (default=LOG_DAEMON) keepalived --snmp -x Enable SNMP subsystem keepalived --help -h Display this short inlined help screen. keepalived --version -v Display the version number keepalived --pid -p pidfile keepalived --checkers_pid -c checkers pidfile keepalived --vrrp_pid -r vrrp pidfile