首页 > 代码库 > Heartbeat
Heartbeat
Heartbeat
心跳信息传递:
UDP Unicast
UDP Multicast
UDP broadcast
Serial Cable
组播地址用于标识一个IP组播域。IANA(internet assigned number authority)把D类地址空间分配给IP组播;其范围是从224.0.0.0至239.255.255.255。
永久组播地址:224.0.0.0——224.0.0.255;
临时组播地址:224.0.1.0——238.255.255.255;
本地组播地址:239.0.0.0——239.255.255.255,仅在特定的本地范围内有效;
配置HA集群前提:
1、时间必须同步;
建议使用ntp协议进行;
2、节点之间必须要通过主机名互相通信;
建议使用hosts文件;
通信中使用的名字必须与其节点为上“uname -n”命令展示出的名字保持一致;
3、需要仲裁设备;
4、彼此root用户能基于ssh密钥方式进行通信;
注意:定义为集群服务中的任意资源都不能开机自动启动,因为它们将由CRM启动;
资源准备:
1、选定vip;
2、httpd:
安装好程序;
配置好httpd,本地测试完成;
关闭服务,并确保开机不会自动启动;
3、shared storage:NFS
安装方法:
1、# yum install net-snmp-libs libnet PyXML perl-Time-Date
2、# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm
配置文件:
ha.cf: heartbeat的主配置文件;
authkeys:集群信息加密算法及密钥;
haresources: heartbeat v1的CRM配置接口;
如何配置:
首先需要说明的配置:
172.16.27.1 node1.stu27.com node1
172.16.27.2 node2.stu27.com node2
在配置集群时,vip地址为:172.16.27.27
[node1 ]#yum install net-snmp-libs libnet PyXML -y
#这里需要把heartbeat相关RPM包下载下来,一般下载到家目录中
[node1 ]#rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
#①heartbeat ②heartbeat-pils ③heartbeat-stonith ④heartbeat-gui
[node1 ]#ntpdate 172.16.0.1
[node1 ]#crontab -e
*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null
[node1 ]#ssh-keygen -P ‘‘ -t rsa
[node1 ]#ssh-copy-id root@node2
[node1 ]#vim /etc/hosts
172.16.27.1 node1.stu27.com node1
172.16.27.2 node2.stu27.com node2
[node1 ]#scp /etc/hosts node2:/etc/
[node2 ]#ntpdate 172.16.0.1
[node2 ]#crontab -e
*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &> /dev/null
[node2 ]#yum install net-snmp-libs libnet PyXML -y
[node2 ]#rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
[node1 ]#cd /usr/share/doc/heartbeat-2.1.4/
[node1 ]#cp ha.cf haresources authkeys /etc/ha.d/
[node1 ]#cd /etc/ha.d
[node1 ]#vim ha.cf
mcast eth0 229.71.30.27 694 1 0 //组播地址
ping 172.16.0.1 //ping node为网关
node node1.stu27.com //HA集群节点
node node2.stu27.com //HA集群节点
compression bz2 //启用心跳信息传递时信息压缩
compression_threshold 2
[node1 ]#vim /etc/rsyslog.conf
localo.* /var/log/halog.log
[node1 ]#service rsyslog restart
[node1 ]scp /etc/rsyslog.conf node2:/etc/
[node2 ]#service rsyslog restart
[node1 ]#vim authkeys
auth 1
1 sha1 dwecrhtvhthbbh
[node1 ]#chmod 400 authkeys
[node1 ]#cd /usr/lib64/heartbeat
[node1 ]#./ha_propagate 会把/etc/ha.d/下面的ha.cf、authkeys文件传递给node2
[node1 ]#/etc/init.d/heartbeat start; ssh node2 ‘/etc/init.d/heartbeat start‘
[node1 ]#cd /etc/ha.d/
[node1 ]#scp haresources node2:/etc/ha.d/
[node1 ]#/etc/init.d/heartbeat start; ssh node2 ‘/etc/init.d/heartbeat start‘
[node1 ]#vim haresources
node2.magedu.com IPaddr2::172.16.100.27(vip)/16/eth0/172.16.255.255(广播地址) httpd
172.16.100.27(vip)/16(掩码)/eth0(vip所在网卡)/172.16.255.255(广播地址) httpd(启动的服务)
[node1 ]#scp haresources node2:/etc/ha.d/
[node1 ]#/etc/init.d/heartbeat restart; ssh node2 ‘/etc/init.d/heartbeat restart‘
[node1 ]#vim /var/www/html/index.html
<h1>node1</h1>
[node2 ]#vim /var/www/html/index.html
<h1>node2</h1>
在浏览器输入:http://172.16.27.27
然后会看到: node2
[node2 ]#cd /usr/lib64/heartbeat
[node2 ]#./hb_standby
把vip让给node1,此时刷新浏览器发现:node1
[node1 ]#/etc/init.d/heartbeat stop; ssh node2 ‘/etc/init.d/heartbeat stop‘
[node1 ]#cd /etc/ha.d/
[node1 ]#vim ha.cf
crm on
#底部添加,启用 内置的v2版的crm的管理功能,此时/etc/ha.d/haresources文件已经没用处了
[node2 ]#cd /etc/ha.d/
[node2 ]#vim ha.cf
crm on
[node1 ]#ss -tnl
5560 端口显示mgmtd heartbeat内部的资源管理器所监听的进程
[node2 ]#crm_mon
显示集群状态
DC:指派的协调员(从集群中选取)做决策 dc把配置同步到素有集群主机上
[node2 ]#crm_sh
config配置资源
list
exit 退出
[node1 ]#tail /etc/passwd
hacluster
在哪个节点上登陆图形化界面使用hacluster 添加密码
[node1 ]#echo 111111 |passwd --stdin hacluster
[node1 ]#hb_gui &
此时使用xshell可能打不开图形化设置界面,进入虚拟机
[node1 ]#startx
进入linux图形界面
打开终端
如果,在别的节点打开的话
>ssh -X root@172.16.27.1 然后输入密码即可
[node1 ]#hb_gui &
进入图形设置界面
Heartbeat