配置heartbeat
[root@node1 yum.repos.d]# cd/usr/share/doc/heartbeat-2.1.4/
[root@node1 heartbeat-2.1.4]# cp -pauthkeys haresources ha.cf /etc/ha.d/ (保持原有属性,复制文件)
ha.cf:heartbeat的主配置文件;
authkeys:集群信息加密算法及密钥;
haresources:heartbeat v1的CRM配置接口;
[root@node1 heartbeat-2.1.4]# cd /etc/ha.d/
[root@node1 ha.d]# chmod 600 authkeys
[root@node1 ha.d]# vim ha.cf (编辑主配置文件;)
# File to write other messages to
logfile /var/log/ha-log
# Facility to use for syslog()/logger
#logfacility local0
……………..
mcast eth0 225.0.0.14 6941 0 (多播地址,范围224.0.2.0~238.255.255.255
,可随意填写, 基于多播的方式进行通信 ,选网卡,组,端口,多播报文ttl值(1是直达目标主机),0拒绝接收本地回环
)
# Set up a unicast / udp heartbeat medium
……….
# (note: auto_failback can be any boolean or "legacy")
auto_failback on (默认选项,出故障时自动恢复)
……….
# Tell what machines are in the cluster
# node nodename ... -- must match uname -n
#node ken3
#node kathy
node node1.dragon.com (定义节点名称,必须是各主机#uname -n的名称)
node node2.dragon.com
……….
# note: don't use a cluster node as ping node
#ping 10.10.10.254
ping 172.16.18.30 (定义仲裁节点,能Ping通就说明正常工作)
……….
# library in the system.
compression bz2 (定义压缩工具)
# Confiugre compression threshold
compression_threshold 2 (小于2K不压缩)
[root@node1 ~]# openssl rand -hex 6 (生成一个随机数)
febe06c057d0
[root@node1 ha.d]# vim authkeys (集群信息加密算法及密钥)
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 1
1 sha1 febe06c057d0
[root@node1 ha.d]# vim haresources (设置资源管理haresources 主节点)
# They must match the names of the nodes listed in ha.cf, which in turn
# must match the `uname -n` of some node in the cluster. So they aren't
# virtual in any sense of the word.
node1.dragon.com 172.16.18.51/16/eth0/172.16.255.255 httpd (主节点,vip(虚拟IP),启动的服务)
[root@node1 ha.d]# scp -p authkeysharesources ha.cf node2:/etc/ha.d/ (node1,node2配置同步)
[root@node1 heartbeat2]# service heartbeatstart ; ssh node2 'service heartbeat start' (启动两节点heartbeat服务,会自动启用httpd服务)
[root@node1 ha.d]# vim /var/www/html/index.html
node1
[root@node2 heartbeat2]# vim/var/www/html/index.html
node2
访问虚拟IP,发现vip在Node1节点上
[root@node1 ha.d]# service heartbeat stop (再访问172.16.18.51,会跳转到node2)
[root@node1 ha.d]# service heartbeat start
[root@node1 ha.d]# cd /usr/lib64/heartbeat/
[root@node1 heartbeat]# ./hb_standby (也可以输入命令使自己变备用节点)
[root@node1 heartbeat]#./hb_takeover (也可以输入命令使自己变主节点) 添加NFS服务器
[root@node3 yum.repos.d]# mkdir /web/htdocs–pv
[root@node3 yum.repos.d]# vim/web/htdocs/index.html
pages from nfsserver
[root@node3yum.repos.d]# vim /etc/exports (共享文件/web/htdocs)
/web/htdocs172.16.0.0/16(rw,no_root_squash)
[root@node3 yum.repos.d]# service nfs start (启动NFS服务)
[root@node3 yum.repos.d]# chkconfig nfs on (设置开机启动此服务)
[root@node3 yum.repos.d]# chkconfig –list nfs (查看开机启动)
[root@node1 heartbeat]# cd /etc/ha.d/
[root@node1 ha.d]# service heartbeat stop;ssh node2 'service heartbeat stop' (先关闭服务)
[root@node1 ha.d]# mount -t nfs 172.16.18.30:/web/htdocs /mnt (尝试挂载,最好在两节点都亲尝试)
[root@node1 ha.d]# mount (查看是否挂载成功)
[root@node1 ha.d]# umount /mnt/ (成功后卸载)
[root@node1 ha.d]# vim haresources
#node1.dragon.com172.16.18.51/16/eth0/172.16.255.255 httpd (注释前面的配置)
node1.dragon.com172.16.18.51/16/eth0/172.16.255.255Filesystem::172.16.18.30:/web/htdocs::/var/www/html::nfs httpd
Node1(默认主节点名称) IP地址 Filesystem(代理文件)::172.16.18.30:/web/htdocs(代理文件地址,我们这里是共享文件,也可以是本地文件,如果是本地文件直接写本地路径)::/var/www/html挂在点::nfs文件系统 所用服务:httpd
[root@node1 ha.d]# scp haresourcesnode2:/etc/ha.d/ (复制给Node2)
[root@node1 ha.d]# service heartbeatrestart ;ssh node2 'service heartbeat restart' (启动服务)
[root@node1 ha.d]# mount (等待几秒发现文件已经挂载成功)
172.16.18.30:/web/htdocson /var/www/html type nfs (rw,vers=4,addr=172.16.18.30,clientaddr=172.16.18.10)