heartbeatHA应用示例(一)

2023年 7月 16日 30.0k 0

下载安装包!
heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-debuginfo-2.1.4-12.el6.x86_64.rpm
heartbeat-devel-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
1,创建密钥,无密码认证
[root@node2 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9f:60:cf:c3:c9:cf:13:d4:1f:6d:71:1e:72:7a:7b:65 root@node2
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . +.|
| .+.=|
| ...oE|
| S . .++|
| . B o. .o|
| X . .|
| +. |
| o. |
+-----------------+
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@172.16.249.186
The authenticity of host '172.16.249.186 (172.16.249.186)' can't be established.
RSA key fingerprint is 81:80:c0:0a:61:21:77:cb:4d:ef:c8:98:a0:71:4f:94.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.249.186' (RSA) to the list of known hosts.
root@172.16.249.186's password:
Now try logging into the machine, with "ssh 'root@172.16.249.186'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@node2 ~]# ssh root@172.16.249.186
Last login: Thu May 14 15:03:49 2015 from 172.16.250.167
[root@node3 ~]#
确保时间一致
[root@node2 ~]# date;ssh node3 'date'
Thu May 28 22:42:06 CST 2015
Thu May 28 22:42:06 CST 2015
  2015-05-29_011005HAAA node2和node3安装必要包组
[root@node2 ~]# yum install net-snmp-libs libnet PyXML
[root@node2 heartbeat2]# 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
在node2上复制这些包至node3
[root@node2 ~]# scp -r heartbeat2/ node3:/root
heartbeat-debuginfo-2.1.4-12.el6.x 100% 3505KB 3.4MB/s 00:00
heartbeat-2.1.4-12.el6.x86_64.rpm 100% 1388KB 1.4MB/s 00:00
heartbeat-pils-2.1.4-12.el6.x86_64 100% 90KB 90.2KB/s 00:00
heartbeat-ldirectord-2.1.4-12.el6. 100% 106KB 106.4KB/s 00:00
heartbeat-devel-2.1.4-12.el6.x86_6 100% 276KB 276.2KB/s 00:00
heartbeat-gui-2.1.4-12.el6.x86_64. 100% 164KB 164.1KB/s 00:00
heartbeat-stonith-2.1.4-12.el6.x86 100% 163KB 162.7KB/s 00:00
在node2上写hosts文件
[root@node2 ~]# vim /etc/hosts
172.16.249.186 node3
172.16.249.97 node2
/etc/ha.d目录下:
ha.cf: 主配置文件,定义各节点上的heartbeat HA集群的基本属性;
authkeys:集群内节点间彼此传递消息时使用加密算法及密钥;
haresources: 为heartbeat v1提供资源管理器配置接口;v1版本专用的配置接口;
修改配置文件权限
1,复制模板文件到/etc/ha.d/
[root@node2 ha.d]# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,haresources,authkeys} /etc/ha.d/
2,修改文件权限,否则无法正常启动
[root@node2 ha.d]# chmod 600 authkeys
3,修改配置文件
修改之前生成域共享随机密文复制到authkeys中
[root@node2 ~]# openssl rand -base64 16
SXNE0uEHyOltEhK27MzHuw==
[root@node2 ~]#
在authkeys启用auth 2,并且将2 sha1 密钥修改
[root@node2 ha.d]# vim authkeys
auth 2
#1 crc
2 sha1 SXNE0uEHyOltEhK27MzHuw
修改ha.cf
1,开启日志文件
[root@node2 ~]# vim /etc/ha.d/ha.cf
logfacility local0
2,在rsyslog添加local0,而后重载
[root@node2 ~]vim /etc/rsyslog.conf
local0.* /var/log/heartbeat.log
#keepalive 2 2秒心跳
#deadtime 30 30秒未收到,便是挂掉状态
#warntime 10 这个数字小于deadtime,大于keepalive
广播参数
#bcast eth0 # Linux
#bcast eth1 eth2 # Linux
#bcast le0 # Solaris
#bcast le1 le2 # Solaris
这里使用多播
3,添加多播
mcast eth0 225.23.190.1 694 1 0
4,添加node
node node2
node node3
5,添加仲裁网关
ping 172.16.0.1
6,打开压缩功能
compression bz2
compression_threshold 2
修改haresources文件
[root@node2 ha.d]# vim haresources
node2 172.16.100.17/16/eth2/172.16.255.255 httpd
复制文件到node3
[root@node2 ha.d]# scp -p authkeys ha.cf haresources node3:/etc/ha.d/
authkeys 100% 662 0.7KB/s 00:00
ha.cf 100% 10KB 10.4KB/s 00:00
haresources 100% 5956 5.8KB/s 00:00
[root@node2 ha.d]#
查看694端口是否开启
[root@node2 ha.d]# ss -tunl |grep :694
udp UNCONN 0 0 225.23.190.1:694 *:*
[root@node2 ha.d]#
查看日志是否正常记录
[root@node2 ha.d]# tail /var/log/heartbeat.log
注意:
1,如果使用多播,首先确认是否开启多播功能,MULTICAST
开启eth0命令
ip link set etho multicast on 2,关闭httpd,关闭开机启动
[root@node2 ha.d]# chkconfig httpd off
 
搭建完成!
当node2宕机,node3会自动启动httpd!
  2015-05-29_011054HANFS 基于nfs共享
在node1机器上创建/web/mark/index.html,明确写入NFS _SERVER
[root@node1 ~]# vim /etc/exports
/web/mark 172.16.0.0/16(rw,no_root_squash)
在node2和node3进行测试
[root@node2 ha.d]# mount -t nfs 172.16.249.117:/web/mark /var/www/html/
进行测试,如果测试没问题,就停止httpd
全部ok后,在任意一台机器修改haresources
[root@node2 ha.d]# vim haresources
node2 172.16.100.17/16/eth2/172.16.255.255 Filesystem::172.16.249.117:/web/mark::/var/www/html::nfs httpd
将配置文件cp到node3
[root@node2 ha.d]# scp authkeys ha.cf haresources node3:/etc/ha.d/
authkeys 100% 662 0.7KB/s 00:00
ha.cf 100% 10KB 10.4KB/s 00:00
haresources 100% 6014 5.9KB/s 00:00
[root@node2 ha.d]#
同步
[root@node2 ~]# /usr/lib64/heartbeat/ha_propagate
OK! 2015-05-28_233536nfs_server  

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论