34补-2 HA Cluster基础及heartbeat实现HA

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了34补-2 HA Cluster基础及heartbeat实现HA相关的知识,希望对你有一定的参考价值。

HA Cluster基础及heartbeat实现HA


配置环境

node1:192.168.1.121 CentOS6.7

node2:192.168.1.122 CentOS6.7

node3:192.168.1.123 CentOS6.7

vip 192.168.1.80


配置前准备

   # cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.121           node1

192.168.1.122           node2

192.168.1.123           node3 

   #  ssh-keygen -t rsa -P ‘‘

   #  ssh-copy-id -i ~/.ssh/id_rsa.pub node1

   #  ssh-copy-id -i ~/.ssh/id_rsa.pub node2

   #  ssh-copy-id -i ~/.ssh/id_rsa.pub node3

   #  rpm -ivh epel-release-latest-6.noarch.rpm 

   #  yum -y ansible

   #  yum -y install ansible

   # cat /etc/ansible/hosts 

[ha]

192.168.1.121

192.168.1.122

192.168.1.123

   #  ansible ha -m copy -a ‘src=/etc/hosts dest=/etc‘

   #  ansible ha -m shell -a ‘ntpdate 192.168.1.62‘

   # ansible ha -m cron -a ‘minute="*/3" job="/usr/sbin/ntpdate 192.168.1.62" name="ntpdate"‘

   # ansible ha -m copy -a ‘src=/root/heartbeat2 dest=/root‘

   

   node1、node2和node3

   #yum -y install net-snmp-libs libnet PyXML perl-Time-Date

   # ls heartbeat2/

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 #提供hb-gui的包,可以先不装

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 #提供仲裁设备,节点隔离的包

# cd heartbeat2/

# rpm -ivh heartbeat-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

[[email protected] ha.d]# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,haresources,authkeys} /etc/ha.d/

[[email protected] ha.d]# cd /etc/ha.d/

[[email protected] ha.d]# chmod 600 authkeys

[[email protected] ha.d]# openssl rand -base64 4

nuGXcw==

[[email protected] ha.d]# vim authkeys 

修改

#auth 1

#2 sha1 HI!

auth 2

2 sha1 nuGXcw==

[[email protected] ha.d]# vim ha.cf

修改

#logfile    /var/log/ha-log

logfile    /var/log/ha-log

修改

logfacility local0

#logfacility    local0

修改

#mcast eth0 225.0.0.1 694 1 0

mcast eth0 225.23.190.1 694 1 0

在node   kathy(212行左右)下添加

node node1 #指明所有的node结束

node node2

node node3

在#ping 10.10.10.254(223行左右)下添加

ping 192.168.1.1 #仲裁设备

修改

#compression    bz2 #是否压缩

#compression_threshold 2 #多大的文件才压缩

compression bz2

compression_threshold 2

[[email protected] ha.d]# vim haresources 

在末尾添加

node1   192.168.1.80/16/eth0/192.168.255.255 httpd

[[email protected] ha.d]# scp -p authkeys ha.cf haresources node2:/etc/ha.d

[[email protected] ha.d]# scp -p authkeys ha.cf haresources node3:/etc/ha.d

[[email protected] ~]# vim /var/www/html/index.html

<h1>node1.magedu.com</h1>

[[email protected] ~]# service httpd stop

Stopping httpd:                                            [  OK  ]

[[email protected] ~]# chkconfig httpd off

[[email protected] ~]# vim /var/www/html/index.html

<h1>node2.magedu.com</h1>

[[email protected] ~]# service httpd stop

Stopping httpd:                                            [  OK  ]

[[email protected] ~]# chkconfig httpd off

[[email protected] ~]# vim /var/www/html/index.html

<h1>node3.magedu.com</h1>

[[email protected] ~]# service httpd stop

Stopping httpd:                                            [  OK  ]

[[email protected] ~]# chkconfig httpd off

[[email protected] ha.d]# ansible ha -m service -a ‘name=heartbeat state=started‘

03 HA Cluster概念扩展及heartbeat实现

使自己变成备用结点

[[email protected] heartbeat]# /usr/lib64/heartbeat/hb_standby

使用变回主结点

[[email protected] heartbeat]# /usr/lib64/heartbeat/hb_takeover 

[[email protected] ~]# mkdir /web/htdocs -pv

[[email protected] ~]# vim /web/htdocs/index.html

<h1>Page On NFS Server</h1>

[[email protected] ~]# vim /etc/exports 

/web/htdocs     192.168.1.0/24(rw,no_root_squash)

[[email protected] ~]# service nfs start

[[email protected] heartbeat]# service heartbeat stop;ssh node2 ‘service heartbeat stop‘

[[email protected] ~]# cd /etc/ha.d/

[[email protected] ha.d]# vim haresources 

在末尾添加

node1   192.168.1.80/16/eth0/192.168.255.255 Filesystem::192.168.1.123::/web/htdocs::/var/www/htm::nfs httpd

[[email protected] ha.d]# service heartbeat start;ssh node2 ‘service heartbeat start‘

本文出自 “追梦” 博客,请务必保留此出处http://sihua.blog.51cto.com/377227/1856054

以上是关于34补-2 HA Cluster基础及heartbeat实现HA的主要内容,如果未能解决你的问题,请参考以下文章

34补1-4 实现高可用mysql集群

HA Cluster基础概念及实现高可用集群

Mysql8 InnoDB Cluster Shell Router HA配置图解

Flink 1.2 没有在 HA Cluster 模式下启动

架构之高可用性(HA)集群(Keepalived)

rabbitmq集群故障恢复