实验的环境条件,首先你应该确保你的selinux,iptables,是关闭的。
实验一:你需要准备2台机子:IP:192.168.0.17和192.168.0.75 步骤(1)cd ~ 你需要下载 :heartbeat-3.0.4-1.el6.x86_64.rpm heartbeat-devel-3.0.4-1.el6.x86_64.rpm heartbeat-libs-3.0.4-1.el6.x86_64.rpm ldirectord-3.9.2-1.2.x86_64.rpm (你可以到网上去下载,或者lftp 192.168.0.254 cd /pub/docs/heartbeat/rhel6 mget *) (2)cd ~scp * 192.168.0.75:/root(将下载的文件拷贝到另外一个节点处) 在两台机子上: yum localinstall -y --nogpgcheck * (3)在192.168.0.17上: cd /etc/ha.d/ ll cat README.config从中你可以知道你需要了解的关于heartbeat 的一些配置等。 cd /usr/share/doc/heartbeat-3.0.4/cp ha.cf haresources authkeys /etc/ha.d (4)在192.168.0.17上: cd /etc/ha.d/ vi ha.cfdebugfile /var/log/ha-debug //调试日志文件文件,取默认值logfile /var/log/ha-log //系统运行日志文件,取默认值logfacility local0 //日志等级,取默认值keepalive 1 //心跳频率,自己设定。1:表示 1 秒;200ms:表示 200 毫秒
deadtime 5 //节点死亡时间阀值,就是从节点在过了 5 后还没有收到心跳就认为主节点死亡,自己设定warntime 4 //发出警告时间,自己设定 initdead 10 //守护进程首次启动后应该等待 10 秒后再启动主服务器上的资源udpport 694 //心跳信息传递的 udp 端口,使用端口 694(也可以改成其他的) 进行 bcast 和 ucast 通信,取默认值(这个端口的值不可以与别人冲突,也不可以和/etc/services里面的端口重复,否则会出错)
bcast eth0 //(采用 udp 广播播来通知心跳)#ucast eth1 10.0.0.3 采用网卡 eth1 的 udp 单播来通知心跳,eth1 的 IP#mcast eth0 225.0.0.1 694 1 0 采用 udp 多播播来通知心跳watchdog /dev/watchdog (watchdog /dev/watchdog watchdog 能让系统在出现故障 1 分钟后重启该机器,这个功能可以帮助服务器在确实停止心跳后能够重新恢复心跳。 如果使用该特性,修改系统中/etc/modprobe.d/modprobe.conf, 添加如下行:options softdog nowayout=0。这样在系统启动的时候,在内核中装入"softdog"内核模块,用来生成实际的设备文件或者是:出来ll /dev/watchlog发现没有,你可以用modprobe softdog 此时 ll /dev/watchdog 你可以如上所说写进/etc/rc.local 写上:modprobe softdog(注意在从节点上也要执行的哦!),注意在另一个节点主机上写上哦!)auth_failback on node desktop17.example.com node desktop75.example.com(注意写在前面的是你的主节点。所以不要搞措顺序主次节点是在此区分的!)ping 192.168.0.254(你的网管地址)respawn hacluster /usr/lib/heartbeat/ipfail(在你的主机上 ll /usr/lib/heartbeat/ipfail 查看看看有没有,要是你的机子是64位的,你可以改成:/usr/lib64/heartbeat/ipfail)apiauth ipfail gid=haclient uid=hacluster (5)vi haresourcedesktop17.example.com IPaddr::192.168.0.1/24/eth0 httpd(desktop17是主节点哦,并且在从节点上也是desktop17的哦!千万不要改IP哦!) (IPaddr是在/etc/ha.d/resource.d/有IPaddr这条,也可以执行/etc/init.d/下面的) (6)vi authkeys auth 3 #1 crc #2 sha1 HI! 3 md5 Hello!chmod 600 authkeys(注意文件权限一定是600.否则会报错的!) (7) 为保证2个节点的配置文件一致:scp ha.cf haresources authkeys root:192.168.0.75:/etc/ha.cf/ 在另一个节点主机上也要保证:chmod 600 authkeys(在这里注意的是haresources中的desktop17.example.com IPaddr::192.168.0.1/24/eth0 httpd应该是主节点的IP。在主从上是一样的!) (8) 测试: 在主节点:desktop17.example.com上: /etc/init.d/heartbeat start chkconfig heartbeat on 你可以:tail /var/log/message tail /var/log/hc-log tail /var/log/hc-debug 你可以查看你的启动是否正常:httpd 和IPaddr是否启动!(该服务自动给你启动httpd)ifconfig 你可以看到:eth0:0 Link encap:Ethernet HWaddr 52:54:00:60:2F:57 inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:11 Base address:0x6000 打开测试页面:http://192.168.0.1刷新看!会首先选择主节点的desktop17.example.com除非主节点挂掉!(并且刷新到哪个主机上的ifconfig显示的含有eth0:0)在desktop75.example.com上:
/etc/init.d/heartbeat start。在desktop75.example.com上:/etc/init.d/heartbeat stop (chkconfig heartbeat on) echo b > /proc/sysrq-trigger,你刷新你的页面:http://192.168.0.1页面发现会换到 desktop75.example.com 当192.168.0.17启来的时候会发现又到desktop17.example.com上了。 当你的主节点的httpd关闭的时候,/etc/init.d/httpd stop你访问页面http://192.168.0.1会发现无法连接。也就是说在主控程序停止的时候会跳转到另一台机子上,但是当主节点上的httpd服务关闭的时候那么就不会自动跳转,因为文件中有desktop17.example.com IPaddr::192.168.0.1/24/eth0 httpd,在节点上的heartbeat关闭的时候会跳转到“从”节点上开启httpd等的服务。但是在主节点上的httpd服务关闭的话却不会自动跳转到从节点上。2.你可以选择colosync来替代heartbeat的,也能实现心跳的功能,你可以参考文档drbd中的关于、安装配置corosync和pacemaker 的部分,在本地实验室里、安装配置corosync和pacemaker 直接可使用命令yum install corosync pacemaker -y,配置主配置文件就按照文档上的走就可以了。
注意bindnetaddr: 192.168.0.0指的是一个网段。在配置资源的时候- [root@desktop53 ~]# crm
- crm(live)# configure
- crm(live)configure# show
- crm(live)configure# property stonith-enabled="false"
- crm(live)configure# property no-quorum-policy="ignore"
- crm(live)configure# property start-failure-is-fatal="false"
- crm(live)configure# commit
- crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=192.168.0.2 cidr_netmask==32 op monitor interval=30s
- crm(live)configure# show
- crm(live)configure# primitive apache lsb:httpd op monitor interval=30s(刚启动的时候vip和apache分布在2个机子上,如何让他们服务分布在一个服务器上呢!)
- crm(live)configure# show
- crm(live)configure# commit
- crm(live)configure# colocation apache-with-vip inf: apache vip (绑定关系,也就是绑定和vip和apache在一个服务器上启动)
- crm(live)configure# order apache-after-vip inf: vip apache (设计启动的启动顺序,apache的启动在vip之后)
- crm(live)configure# commit
- crm(live)configure# end
- crm(live)# resource
- crm(live)resource# stop apache
- crm(live)resource# stop vip
- crm(live)resource# sta
- start status
- crm(live)resource# start apache
- crm(live)resource# start vip
- crm(live)resource# move apache desktop94.example.com
- crm(live)resource# move apache desktop53.example.com
- crm(live)resource#
在一台机子上用命令watch crm status既可以动态的查看他们的状态。