注意事项:
1、节点名称:hostname、/etc/hosts
2、ssh互信
3、节点时间同步
heartbeat的三个配置文件:
authkeys:通信密钥文件
ha.cf:heartbeat服务配置文件
haresources:资源管理配置文件
安装配置(系统为CentOS6.5):
WAN IP:192.168.101.168
node1:192.168.101.21
node2:192.168.101.22
1、配置node1、node2节点名称、ssh互信、时间同步
node1:
# hostname node1.redhat.com
# vim /etc/sysconfig/network
HOSTNAME=node1.redhat.com
# vim /etc/hosts
192.168.101.21 node1.redhat.com node1
192.168.101.22 node2.redhat.com node2
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub node2
# ntpdate 0.centos.pool.ntp.org
node2:
# hostname node2.redhat.com
# vim /etc/sysconfig/network
HOSTNAME=node2.redhat.com
# vim /etc/hosts
192.168.101.21 node1.redhat.com node1
192.168.101.22 node2.redhat.com node2
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub node1
# ntpdate 0.centos.pool.ntp.org
2、node1、node2安装heartbeat
# 注意:这里使用CentOS本地iso yum源+EPEL源安装。
# yum install http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm
# yum install heartbeat cluster-glue resource-agents pacemaker httpd
3、node1配置heartbeat
# 拷贝配置文件至/etc/ha.d/
# cp -p /usr/share/doc/heartbeat-3.0.4/{ha.cf,authkeys,haresources} /etc/ha.d/
# 配置生成通信密钥
# openssl rand -base64 20
tRlI5Dr/YHoE59kJ4yYOgNpVmDI=
# vim /etc/ha.d/authkeys
auth 1
1 md5 tRlI5Dr/YHoE59kJ4yYOgNpVmDI=
# chmod 600 /etc/ha.d/authkeys
# 配置heartbeat主配置文件
# vim /etc/ha.d/ha.cf
logfile/var/log/ha-log # 日志文件路径
keepalive 1 # 心跳信息传递间隔时间,这里设置1秒
deadtime 30 # 节点超时时间,超过30s没有收到心跳信息则认为节点死亡
warntime 10 # 告警时间
initdead 120 # heartbeat首次启动等待时间,默认120秒,此时间设置为deadtime的两倍
udpport 694 # 心跳信息传递所使用的端口
mcast eth0 225.1.1.1 694 1 0 # 采用组播地址
auto_failback off # 是否开启故障恢复
nodenode1.redhat.com # 主节点名称,必须与uname -n一致
nodenode2.redhat.com # 备用节点名称
ping 192.168.101.254 # 通过ping网关来检测心跳信息是否正常
# 配置资源管理文件,绑定外网IP:192.168.101.168
# vim /etc/ha.d/haresources
node1.redhat.com IPaddr::192.168.101.168/24/eth0/ httpd
4、复制配置文件至node2
# scp -p /etc/ha.d/{ha.cf,authkeys,haresources} node2:/etc/ha.d/
5、创建httpd index.html页面并关闭开机自启动httpd
# echo "<h1>node1.redhat.com</h1>" > /var/www/html/index.html
# ssh node2 ‘echo "<h1>node2.redhat.com</h1>" > /var/www/html/index.html‘
# chkconfig httpd off
# ssh node2 ‘chkconfig httpd off‘
6、启动heartbeat
# 链接heartbeat各类脚本
# ln -s /usr/share/heartbeat/* /usr/lib64/heartbeat/
# /etc/init.d/heartbeat start
# ssh node2 ‘/etc/init.d/heartbeat start‘
7、查看日志、绑定IP及浏览器访问
# tail /var/log/ha-log
# ifconfig
http://192.168.101.168/
8、使用NFS共享存储
# NFS主机IP为:192.168.101.28
# NFS共享目录:/data/www/
# vim /data/www/index.html
NFS Server.
# 停止heartbeat
# ssh node2 ‘/etc/init.d/heartbeat stop‘
# /etc/init.d/heartbeat stop
# node1修改资源配置文件并复制到node2
# vim /etc/ha.d/haresources
node1.redhat.com IPaddr::192.168.101.168/24/eth0/ Filesystem::192.168.101.28:/data/www::/var/www/html::nfs httpd
# scp /etc/ha.d/haresources node2:/etc/ha.d/
9、启动heartbeat
# /etc/init.d/heartbeat start
# ssh node2 ‘/etc/init.d/heartbeat start‘
10、查看日志、绑定IP及浏览器访问
# tail /var/log/ha-log
# ifconfig
http://192.168.101.168/
11、节点切换测试
# /usr/share/heartbeat/hb_standby
原文地址:http://yuyucat.blog.51cto.com/9627004/1659856