高可用集群之heartbeat安装配置

高可用集群之heartbeat安装配置

说明:

系统为rhel 5.8 64bit

heartbeat版本为v2

配置web高可用服务

节点为两个:node1和node2

创建高可用集群需要注意的地方:

各节点需要传递集群事务信息,传递时需要识别各节点,每个节点对对方的识别必须靠节点名称来实现,节点名称能够解析IP地址,配置DNS的话,如果DNS挂了,节点也找不到了,所以对于名称的解析不要依赖DNS,这就需要使用本地hosts文件,需要为每一个节点配置好hosts文件解析,每一个节点的hosts配置文件都需要一样。

每一个节点名称必须和uname –n执行结果的名称一致。

如果想要停掉某个节点集群服务,不可以在当前节点上停掉,需要在别的正常节点上通过SSH停掉或启动。第一个节点是自己启动的。

需要配置各节点主机SSH互信通信,不用密码可以连接,基于密钥访问。

各个节点系统时间需要同步。

练习1:利用heartbeat构建高可用http服务

VIP:192.168.1.221

由于web网页在各个节点上,确保节点上的web能够正常访问,注意,确保正常后各个节点需要关闭httpd服务,并且设置开机不要自动启动:

[[email protected] bao]# service httpd stop

Stopping httpd:                                           [  OK  ]

[[email protected] bao]# chkconfig httpd off

[[email protected] bao]# chkconfig --list | grep httpd

httpd           0:off   1:off  2:off   3:off   4:off  5:off   6:off

[[email protected] bao]#

1.配置各节点主机能够互相通信,基于名称互相通信,基于SSH互信通信,时间同步:

(1)节点1配置主机名,IP为192.168.1.169

[[email protected] ~]# hostname node1.magedu.com

[[email protected] ~]# uname -n

node1.magedu.com

[[email protected] ~]# vim /etc/sysconfig/network

HOSTNAME=node1.magedu.com

"/etc/sysconfig/network" 3L, 61Cwritten

[[email protected] ~]#

(2)节点2配置主机名,IP为192.168.1.171

[[email protected] ~]# hostname node2.magedu.com

[[email protected] ~]# uname -n

node2.magedu.com

[[email protected] ~]# vim /etc/sysconfig/network

HOSTNAME=node2.magedu.com

"/etc/sysconfig/network" 3L, 61Cwritten

[[email protected] ~]#

(3)配置使用ssh秘钥方式进行彼此登录(两个节点都要配置)

节点1生成秘钥:

[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘

Generating public/private rsa key pair.

Created directory ‘/root/.ssh‘.

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:

fa:a1:fb:21:56:8c:0e:a9:a3:bb:3e:80:29:b9:76:[email protected]

[[email protected] ~]# ll .ssh/id_rsa*

-rw------- 1 root root 1675 Jul 21 09:42.ssh/id_rsa

-rw-r--r-- 1 root root  403 Jul 21 09:42 .ssh/id_rsa.pub

[[email protected] ~]#

说明:

-t :指定类型。

-f :指定输出文件路径名称。

-P :指定密码。

将公钥复制给web2主机:

[[email protected] ~]# ssh-copy-id -i .ssh/[email protected]

15

The authenticity of host ‘192.168.1.171(192.168.1.171)‘ can‘t be established.

RSA key fingerprint is88:36:2f:60:c8:5b:1a:f7:d6:fd:2a:9d:8a:44:fb:98.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added ‘192.168.1.171‘(RSA) to the list of known hosts.

Address 192.168.1.171 maps to localhost,but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

[email protected]‘s password:

Now try logging into the machine, with"ssh ‘[email protected]‘", and check in:

.ssh/authorized_keys

to make sure we haven‘t added extra keysthat you weren‘t expecting.

[[email protected] ~]#

说明:

ssh-copy-id -i .ssh/[email protected]此时没有解析,不能用[email protected] node2.magedu.com。

测试一下:

[[email protected] ~]# ssh 192.168.1.171 ‘ifconfig‘

节点2生成秘钥:

[[email protected] .ssh]# pwd

/root/.ssh

[[email protected] .ssh]# hostname

node2.magedu.com

[[email protected] .ssh]# ll

total 12

-rw------- 1 root root  403 Jul 21 09:46 authorized_keys    (节点1传来的密钥)

[[email protected] .ssh]#

[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘

Generating public/private rsa key pair.

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:

73:aa:36:a4:43:33:93:1b:c8:01:17:78:83:d3:87:[email protected]

[[email protected] ~]# ll .ssh/id_rsa*

-rw------- 1 root root 1675 Jul 21 09:53.ssh/id_rsa

-rw-r--r-- 1 root root  403 Jul 21 09:53 .ssh/id_rsa.pub

[[email protected] ~]#

将公钥复制给web1主机:

[[email protected] ~]# ssh-copy-id -i .ssh/[email protected]

15

The authenticity of host ‘192.168.1.169(192.168.1.169)‘ can‘t be established.

RSA key fingerprint is80:4a:11:64:9c:fa:34:fc:3d:ef:47:ce:9c:06:76:57.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added ‘192.168.1.169‘(RSA) to the list of known hosts.

Address 192.168.1.169 maps to localhost,but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

[email protected]‘s password:

Now try logging into the machine, with"ssh ‘[email protected]‘", and check in:

.ssh/authorized_keys

to make sure we haven‘t added extra keysthat you weren‘t expecting.

[[email protected] ~]#

测试一下:

[[email protected] ~]# ssh 192.168.1.169‘ifconfig‘

[[email protected] ~]# hostname

node1.magedu.com

[[email protected] ~]# ll .ssh/

total 16

-rw------- 1 root root  403 Jul 21 09:56 authorized_keys

-rw------- 1 root root 1675 Jul 21 09:42id_rsa

-rw-r--r-- 1 root root  403 Jul 21 09:42 id_rsa.pub

-rw-r--r-- 1 root root  395 Jul 21 09:45 known_hosts

[[email protected] ~]#

(4)配置两个节点hosts解析文件,确保可以使用主机名进行通信:

[[email protected] ~]# uname -n

node1.magedu.com

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

192.168.1.169   node1.magedu.com node1     (最后node1是别名)

192.168.1.171   node1.magedu.com node2

"/etc/hosts" 6L, 265Cwritten

[[email protected] ~]#

测试ping:

[[email protected] ~]# ping node2

PING node1.magedu.com (192.168.1.171)56(84) bytes of data.

64 bytes from node1.magedu.com(192.168.1.171): icmp_seq=1 ttl=64 time=1.59 ms

………………………..

[[email protected] ~]# ssh node2 ‘date‘

Address 192.168.1.171 maps tonode1.magedu.com, but this does not map back to the address - POSSIBLE BREAK-INATTEMPT!

Tue Jul 21 10:09:30 CST 2015

[[email protected] ~]#

连接报错,服务器端启用了GSSAPI。登陆的时候客户端需要对服务器端的IP地址进行反解析,如果服务器的IP地址没有配置PTR记录,那么就容易在这里卡住了。

解决方法:

[[email protected]node1 ~]# vim /etc/ssh/ssh_config

44        GSSAPIAuthentication no

[[email protected] ~]# ssh node2 ‘date‘

Tue Jul 21 10:12:17 CST 2015

[[email protected] ~]#

[[email protected] ~]# uname -n

node2.magedu.com

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

192.168.1.169   node1.magedu.com node1

192.168.1.171   node1.magedu.com node2

"/etc/hosts" 7L, 266Cwritten

[[email protected] ~]#

测试ping:

[[email protected] ~]# ping node1

PING node1.magedu.com (192.168.1.169)56(84) bytes of data.

64 bytes from node1.magedu.com(192.168.1.169): icmp_seq=1 ttl=64 time=1.32 ms

………………………………….

[[email protected] ~]#

(5)确保系统时间同步:

[[email protected] ~]# date;ssh node2 ‘date‘

Tue Jul 21 10:15:45 CST 2015

Tue Jul 21 10:15:45 CST 2015

[[email protected] ~]#

[[email protected] ~]# date;ssh node1 ‘date‘

Tue Jul 21 10:18:53 CST 2015

Tue Jul 21 10:18:53 CST 2015

[[email protected] ~]#

2. 安装配置heartbeat v2

安装包说明:

[[email protected] bao]# ll

total 2656

-rw-r--r-- 1 root root 1691714 Jul 21 10:32heartbeat-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  293752 Jul 21 10:32 heartbeat-devel-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  231689 Jul 21 10:32heartbeat-gui-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  111941 Jul 21 10:32heartbeat-ldirectord-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   93297 Jul 21 10:32 heartbeat-pils-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  190686 Jul 21 10:32heartbeat-stonith-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   63324 Jul 21 10:32libnet-1.1.6-7.el5.x86_64.rpm

-rw-r--r-- 1 root root   87149 Jul 21 10:45 perl-MailTools-1.77-1.el5.rf.noarch.rpm

[[email protected] bao]#

heartbeat :核心包。

heartbeat-devel:开发包。

heartbeat-gui:提供图形接口管理集群。

heartbeat-ldirectord:为ipvs高可用提供规则自动生成及后端realserver健康状态检查的组件。

heartbeat-pils:用来装载库的通用插件和接口。

heartbeat-stonith :实现爆头的接口。

heartbeat包依赖libnet和perl-MailTools包。

(1)节点1安装heartbeat,192.168.1.169上:

[[email protected] bao]# ll

total 2748

-rw-r--r-- 1 root root 1691714 Jul 21 10:32heartbeat-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  293752 Jul 21 10:32heartbeat-devel-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  231689 Jul 21 10:32heartbeat-gui-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  111941 Jul 21 10:32heartbeat-ldirectord-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   93297 Jul 21 10:32heartbeat-pils-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  190686 Jul 21 10:32heartbeat-stonith-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   63324 Jul 21 10:32libnet-1.1.6-7.el5.x86_64.rpm

-rw-r--r-- 1 root root   87149 Jul 21 10:45perl-MailTools-1.77-1.el5.rf.noarch.rpm

 

配置好yum源 (文章0.0配置RedHat 5系统YUM源方法)

[[email protected] bao]# yum --nogpgcheck localinstall *

(2)节点2安装heartbeat,192.168.1.171上:

配置好yum源 (文章0.0配置RedHat 5系统YUM源方法)

[[email protected] bao]# ll

total 2680

-rw-r--r-- 1 root root 1691714 Jul 21 10:33heartbeat-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  293752 Jul 21 10:33heartbeat-devel-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  231689 Jul 21 10:33heartbeat-gui-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  111941 Jul 21 10:33heartbeat-ldirectord-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   93297 Jul 21 10:33heartbeat-pils-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root  190686 Jul 21 10:33heartbeat-stonith-2.1.4-11.el5.x86_64.rpm

-rw-r--r-- 1 root root   63324 Jul 21 10:33libnet-1.1.6-7.el5.x86_64.rpm

-rw-r--r-- 1 root root   87149 Jul 21 10:46perl-MailTools-1.77-1.el5.rf.noarch.rpm

[[email protected] bao]# yum --nogpgcheck localinstall *.rpm

(3)查看heartbeat安装了那些文件:

[[email protected] ~]# uname -n

node1.magedu.com

[[email protected] ~]# rpm -ql heartbeat

/etc/ha.d        (配置文件)

/etc/ha.d/rc.d    (和资源管理相关的脚本目录)

/etc/ha.d/resource.d   (资源代理脚本目录)

……………………

/var/lib/heartbeat/crm

/var/lib/heartbeat/pengine

/var/run/heartbeat

/var/run/heartbeat/ccm

/var/run/heartbeat/crm

[[email protected] ~]#

3.手动提供heartbeat的三个配置文件:

[[email protected] ha.d]# pwd

/etc/ha.d

[[email protected] ha.d]# ll

total 24

-rwxr-xr-x 1 root root  745 Mar 21 2010 harc

drwxr-xr-x 2 root root 4096 Jul 21 12:55rc.d

-rw-r--r-- 1 root root  692 Mar 21 2010 README.config

drwxr-xr-x 2 root root 4096 Jul 21 12:55resource.d

-rw-r--r-- 1 root root 7864 Mar 21  2010 shellfuncs

[[email protected] ha.d]#

heartbeat的配置文件主要有三个:

密钥文件:权限要是600, 名称是authkeys文件,是主机之间信息传递使用的秘钥。

heartbeat服务的配置文件ha.cf:如有几个节点,节点名称的设置,多长时间检测心跳信息,集群事务信息传递是否加密等设置。

资源管理配置文件:v2版本提供了两个,haresources和crm,默认使用haresources。

安装完heartbeat,提供了配置文件的样例,路径为:

[[email protected] heartbeat-2.1.4]# pwd

/usr/share/doc/heartbeat-2.1.4

[[email protected] heartbeat-2.1.4]# ls

apphbd.cf COPYING.LGPL        GettingStarted.txt hb_report.html      README             startstop

authkeys   DirectoryMap.txt     ha.cf               hb_report.txt       Requirements.html

AUTHORS   faqntips.html       HardwareGuide.html heartbeat_api.html Requirements.txt

ChangeLog faqntips.txt        HardwareGuide.txt  heartbeat_api.txt   rsync.html

COPYING   GettingStarted.html  haresources        logd.cf             rsync.txt

[[email protected] heartbeat-2.1.4]#

复制三个配置文件样例到/etc/ha.d目录下:

[[email protected] heartbeat-2.1.4]# pwd

/usr/share/doc/heartbeat-2.1.4

[[email protected] heartbeat-2.1.4]# cp authkeys ha.cfharesources /etc/ha.d/

[[email protected] heartbeat-2.1.4]# cd /etc/ha.d/

[[email protected] ha.d]# ll

total 48

-rw-r--r-- 1 root root   645 Jul 21 14:06 authkeys

-rw-r--r-- 1 root root 10539 Jul 21 14:06ha.cf

-rwxr-xr-x 1 root root   745 Mar 21 2010 harc

-rw-r--r-- 1 root root  5905 Jul 21 14:06 haresources

drwxr-xr-x 2 root root  4096 Jul 21 12:55 rc.d

-rw-r--r-- 1 root root   692 Mar 21 2010 README.config

drwxr-xr-x 2 root root  4096 Jul 21 12:55 resource.d

-rw-r--r-- 1 root root  7864 Mar 21 2010 shellfuncs

[[email protected] ha.d]#

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

注意:需要更改authkeys权限为600。

(1)配置authkeys文件:

该文件是主机之间信息传递使用的秘钥,权限要是600。

[[email protected] ha.d]# pwd

/etc/ha.d

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

-rw------- 1 root root 645 Jul 21 14:06authkeys

[[email protected] ha.d]#

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

……………….

#auth 1

#1 crc

#2 sha1 HI!

#3 md5 Hello!

[[email protected] ha.d]#

说明:

默认都是注释掉的,用法用auth关键字指定下列列表中的数字,使用哪个认证机制。

crc :循环冗余校验码(CyclicRedundancy Check),不安全。

sha1 :安全哈希算法

md5 :消息摘要算法第五版

配置使用md5认证机制:

[[email protected] ha.d]# uname -n

node1.magedu.com

[[email protected] ha.d]# pwd

/etc/ha.d

[[email protected] ha.d]# dd if=/dev/random count=1 bs=512 | md5sum   (生成随机数做密钥)

0+1 records in

0+1 records out

128 bytes (128 B) copied, 6.4e-05 seconds,2.0 MB/s

e46c1b850b41efcebc5d95fa614c1d18  -   (使用该行随机数)

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

auth 1

1 md5 e46c1b850b41efcebc5d95fa614c1d18

"authkeys" 29L, 692C written

[[email protected] ha.d]#

或者使用openssl生成密钥也可以:

[[email protected] ha.d]# openssl rand -hex 6

e5b50e897cb4   (生成的秘钥)

(2)配置主配置文件ha.cf

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

48 keepalive 2                        (多长时间发一次心跳)

92 bcast  eth0            # Linux    (心跳通过以太网eth0网卡广播方式)

214 node   node1.magedu.com        (集群节点都有哪些)

215 node   node2.magedu.com

223 ping 192.168.1.1              (使用ping通网关来判断存活状态)

"ha.cf" 343L, 10600C written

[[email protected] ha.d]#

说明:

24 #debugfile /var/log/ha-debug    (调试文件)

29 #logfile        /var/log/ha-log   (日志文件)

34 logfacility     local0       (日志的设施,和logfile项不要同时使用)

48 #keepalive 2     (多长时间发一次心跳,加ms为毫秒,不加默认为秒,2秒发一次)

56 #deadtime 30   (死亡时间,多长时间来声明这个主机故障了)

61 #warntime 10  (警告时长,比如说keepalive每2秒发一次心跳,最多等10秒)

71 #initdead 120 (一般来说节点是一个一个启动的,一个节点启动后,需要等待其他节点,设置等待其他节点的时间)

76 #udpport        694   (heartbeat监听的端口)

80 #baud   19200  (heartbeat支持两种传递心跳信息方式,以太网和串行线,该设置是串行线发送速率是多少)

83 #serial /dev/ttyS0      # Linux

84 #serial /dev/cuaa0      # FreeBSD

85 #serial /dev/cuad0      # FreeBSD 6.x

86 #serial /dev/cua/a      # Solaris      (串行设备是什么)

91 #bcast eth0            # Linux

92 #bcast eth1 eth2       # Linux

93 #bcast le0             # Solaris

94 #bcast le1 le2         # Solaris  (基于以太网发送心跳信息,bcast是广播)

113 #mcast eth0 225.0.0.1 694 1 0  (mcast是多播,组播方式,网卡+地址+端口+ttl+循环数)

121 #ucast eth0 192.168.1.2     (ucast单播)

说明:

heartbeat支持两种传递心跳信息方式,以太网和串行线,baud是定义串行线速率的,如果是基于以太网传递心跳信息,需要设置传递方式,三种:广播,组播或单播。

157 auto_failback on  (原来的节点又上线了,是否转移回到以前节点,on为转移回去)

211 #node  ken3

212 #node  kathy

说明:当前集群有几个节点,有几个就需要写几个,node后面的节点名称一定要和uname –n命令结果一致。

220 #ping 10.10.10.254  (ping node主机,当前节点连接不上ping谁)

227 #ping_group group1 10.10.10.25410.10.10.253 (ping一组主机)

253 #respawn hacluster /usr/lib/heartbeat/ipfail (当一个heartbeat服务停止后,一个节点故障后首先重启一下heartbeat服务)

271 #deadping 30   (设置ping node多长时间ping不同,就认为联系不上node了)

314 #msgfmt classic/netstring   (管理信息格式)

323 # use_logd yes/no   (日志可以寄到其他主机上去)

333 #compression    bz2   (集群事务信息发送时是否压缩,是否启用bz3压缩功能)

339 #compression_threshold 2   (大于多少k之后开始压缩)

(3)配置资源管理配置文件haresources

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

150 node1.magedu.comIPaddr::192.168.1.221/24/eth0 httpd

"haresources" 150L, 5958C written

[[email protected] ha.d]#

说明:

node1.magedu.com :主节点名称。

IPaddr::192.168.1.221/24/eth0

资源代理名称::VIP地址/掩码/配置在eth0网卡上的别名上

httpd :服务名。

资源代理名称在resource.d目录里面脚本都定义好了。

其他说明:

haresources文件里每一行定义一个集群服务,都是实例。

例如:

142 #node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2

node1 :主节点名称,上来就是默认活动节点的名称,默认作为主节点的名称,和uname –n命令结果要一样。

10.0.0.170 :VIP地址。

Filesystem::/dev/sda1::/data1::ext2 :定义文件系统::挂载的设备::哪个目录下::文件系统类型,Filesystem是个资源代理,在resource.d目录下就有,可以接收参数,多个参数用两个冒号隔开。

4.把配置好的三个文件传到另一个节点上192.168.1.171

[[email protected] ha.d]# uname -n

node1.magedu.com

[[email protected] ha.d]# pwd

/etc/ha.d

[[email protected] ha.d]# scp -p authkeys ha.cf haresources  node2:/etc/ha.d/    (-p保持原属性)

authkeys                                                                  100%  692     0.7KB/s  00:00

ha.cf                                                                     100%   10KB  10.4KB/s  00:00

haresources                                                                100% 5958     5.8KB/s  00:00

[[email protected] ha.d]#

5.启动heartbeat服务:

[[email protected] ~]# service heartbeat start

Starting High-Availability services:

2015/07/21_15:50:34 INFO:  Resource is stopped

[  OK  ]

[[email protected] ~]# ssh node2 ‘service heartbeat start‘

Starting High-Availability services:

2015/07/21_15:51:15 INFO:  Resource is stopped

[ OK  ]

[[email protected] ~]#

一般远程启动其他节点服务。

6.查看启动结果,浏览器访问192.168.1.221应该出现node1节点的网页:

[[email protected] ~]# netstat -lntp

tcp       0      0 :::80         :::*          LISTEN      2677/httpd

[[email protected] ~]#

[[email protected] ~]# ifconfig

eth0:0   Link encap:Ethernet  HWaddr00:0C:29:51:CD:0B

inet addr:192.168.1.221 Bcast:192.168.1.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500  Metric:1

[[email protected] ~]#

已经都启动!

7.模拟node1节点故障,查看节点node2是否显示:

heartbeat提供了测试脚本,直接实现资源转移:

[[email protected] heartbeat]# pwd

/usr/lib64/heartbeat

[[email protected] heartbeat]# ll ha_propagatehb_standby hb_takeover

lrwxrwxrwx 1 root root 33 Jul 21 12:55ha_propagate -> /usr/share/heartbeat/ha_propagate

lrwxrwxrwx 1 root root 31 Jul 21 12:55hb_standby -> /usr/share/heartbeat/hb_standby

lrwxrwxrwx 1 root root 32 Jul 21 12:55hb_takeover -> /usr/share/heartbeat/hb_takeover

[[email protected] heartbeat]#

说明:

ha_propagate   \\此脚本是将heartbeat的配置文件复制给其他节点

hb_standby     \\此脚本是将当前节点切换为备节点

hb_takeover     \\此脚本是将当前节点切换为主节点

[[email protected] heartbeat]# uname -n

node1.magedu.com

[[email protected] heartbeat]# pwd

/usr/lib64/heartbeat

[[email protected] heartbeat]# ./hb_standby

2015/07/21_16:01:09 Going standby [all].

[[email protected] heartbeat]#

浏览器访问192.168.1.221查看是否是node2的网页。

把资源从node2节点上转移到节点node1上:

[[email protected] heartbeat]# uname -n

node2.magedu.com

[[email protected] heartbeat]# pwd

/usr/lib64/heartbeat

[[email protected] heartbeat]# ./hb_standby

2015/07/21_16:02:52 Going standby [all].

[[email protected] heartbeat]#

heartbeatv2+nfs实现高可用httpd

接上面练习!

使用NFS为两台高可用主机提供NFS文件系统

NFS:192.168.1.162

首先把HA两个节点的heartbeat服务都停掉:

在主节点上用ssh先停掉节点node2的服务:

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

Stopping High-Availability services:

[ OK  ]

[[email protected] ~]# service heartbeat stop

Stopping High-Availability services:

[  OK  ]

[[email protected] ~]#

1.开启NFS功能(192.168.1.162)

[[email protected] ~]# mkdir /web/htdocs –pv     (建立网页存放目录)

mkdir: created directory `/web‘

mkdir: created directory `/web/htdocs‘

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

/web/htdocs    192.168.1.0/24(ro)

"/etc/exports" 1L, 34Cwritten

[[email protected] ~]# service nfs start

Starting NFS services:                                     [ OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

[[email protected] ~]# showmount -e 192.168.1.162

Export list for 192.168.1.162:

/web/htdocs 192.168.1.0/24

[[email protected] ~]#

[[email protected] ~]# echo "<h1>NFSPage</h1>"  >/web/htdocs/index.html   (提供测试网页)

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

-rw-r--r-- 1 root root 18 Jul 21 16:57/web/htdocs/index.html

[[email protected] ~]#

2.在各节点上测试挂载NFS

[[email protected] ~]# uname -n

node1.magedu.com

[[email protected] ~]# mount -t nfs 192.168.1.162:/web/htdocs /mnt

[[email protected] ~]# ll /mnt/

total 4

-rw-r--r-- 1 root root 18 Jul 21 16:57index.html

[[email protected] ~]# umount /mnt/

[[email protected] ~]#  (测试完了要卸载掉)

3. 修改资源配置文件:

[[email protected] ha.d]# uname -n

node1.magedu.com

[[email protected] ha.d]# pwd

/etc/ha.d

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

150 node1.magedu.comIPaddr::192.168.1.221/24/eth0 Filesystem::192.168.1.162:/web/htdocs::/var/www/html::nfshttpd

"haresources" 150L, 6017Cwritten

[[email protected] ha.d]#

说明:

node1.magedu.com IPaddr::192.168.1.221/24/eth0

Filesystem::192.168.1.162:/web/htdocs::/var/www/html::nfshttpd

资源的先后次序很关键,先配置IP,文件系统,然后是服务,文件系统要在服务前面。

node1.magedu.com :主节点名称。

IPaddr::192.168.1.221/24/eth0

资源代理名称::VIP地址/掩码/配置在eth0网卡上的别名上

Filesystem::192.168.1.162:/web/htdocs::/var/www/html::nfs

资源代理名称::设备名称是1.162上的htdocs目录::挂载本机的html目录下::文件系统是nfs

httpd :服务httpd。

资源代理名称在resource.d目录下都有脚本名称。

4.复制资源配置文件给其他节点:

[[email protected] ha.d]# scp haresources node2:/etc/ha.d/

haresources                                                               100% 6017     5.9KB/s   00:00

[[email protected] ha.d]#

5.启动heartbeat服务:

[[email protected] ~]# service heartbeat start

Starting High-Availability services:

2015/07/21_17:06:04 INFO:  Resource is stopped

[  OK  ]

[[email protected] ~]# ssh node2 ‘service heartbeat start‘

Starting High-Availability services:

2015/07/21_17:06:18 INFO:  Resource is stopped

[ OK  ]

[[email protected] ~]#

6.浏览器访问192.168.1.221查看

时间: 2024-07-31 03:07:40

高可用集群之heartbeat安装配置的相关文章

Linux集群系列之十——高可用集群之heartbeat安装配置

rhel 5.8 32bit heartbeat v2 ha web node1 node2 节点名称, /etc/hosts 节点名称必须跟uname -n命令的直行结果一致 ssh 互信通信, 时间同步 1先配置两个主机的ip 列如 192.168.1.11   192.168.1.12 VIP192.168.1.8  网关 192.168.1.1 配置两个主机的主机名#hostname node1.mylinux.com #hostname node2.mylinux.com 为了让主机名

高可用集群之heartbeat基于crm进行资源管理(二)

一.高可用集群之heartbeat基于crm进行资源管理 1.集群的工作模型: A/P:两个节点,工作与主备模型 N-M N>M,N个节点,M个服务 N-N:N个节点,N个服务 A/A:双主模型: 2.资源转移的方式 rgmanager:failover domain priority pacemaker: 资源黏性: 资源约束(三种类型): 位置约束:资源更倾向于那个节点上 inf:无穷大 n: -n: -inf:负无穷 排列约束:资源运行在同一节点的倾向性 inf: -inf: 顺序约束:资

CentOS linux 高可用集群之heartbeat

CentOS linux 高可用集群之heartbeat Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 Heartbeat 项目里,由 heartbeat 模块实现了这两个功能. Heartbeat是Linux-HA工程的一个组件,自1999年开始到现在,发布了众多版本,是目前开源Linux-HA项目最成功的一个例子,在行业内得到了广泛的应用. 随着Linux在关键行业应用的逐渐增多,它必将提供一些

分布式架构高可用架构篇_02_activemq高可用集群(zookeeper+leveldb)安装、配置、高可用测试

从 ActiveMQ 5.9 开始,ActiveMQ 的集群实现方式取消了传统的Master-Slave 方式,增加了基于ZooKeeper + LevelDB的 Master-Slave实现方式,其他两种方式目录共享和数据库共享依然存在. 三种集群方式的对比: (1)基于共享文件系统(KahaDB,默认): <persistenceAdapter> <kahaDB directory="${activemq.data}/kahadb"/> </persi

高可用集群之heartbeat

高可用集群的基本概念 一.什么是高可用集群: 所谓高可用集群就是在其出现故障时,可以把业务自动转移到其他主机上并让服务正常运行的集群架构. 二.heartbeat的概念 Linux-HA的全称是High-Availability Linux,它是一个开源项目,这个开源项目的目标是:通过社区开发者的共同努力,提供一个增强LInux可靠性(reliability).可用性(availability)和可服务性(serviceability)(RAS)的群集解决方案.其中heartbeat就是Linu

高可用集群软件Heartbeat介绍

一.Heartbeat的定义 Heartbeat 项目是 Linux-HA 工程的一个组成部分,也是目前开源HA项目中最成功的一个例子,Linux-HA的全称是High-Availability Linux,这个开源项目的目标是:通过社区开发者的共同努力,提供一个增强linux可靠性(reliability).可用性(availability)和可服务性(serviceability)(RAS)的群集解决方案,它实现了一个高可用集群系统.心跳服务和集群通信是高可用集群的两个关键组件,在 Hear

Keepalived高可用集群应用场景与配置

1.Keepalived单实例主备模式集群方案 这是最简单的模式,不只考虑高可用集群,先不考虑后方的Nginx负载均衡集群,即后端的服务器集群,参考下面的图示: 其对应的Keepalived核心配置如下: lb01 global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_serv

HA(高可用集群)heartbeat

HA 即 (high available)高可用,又被叫做双机热备, 常用实现高可用的开源软件有heartbeat和keepalived,其中keepalived有负载均衡的功能. 下面我们使用heartbeat来做HA集群,并且把nginx服务作为HA对应的服务. 试验准备:两个机器, 都是centos6.5,网卡eth0 ip如下:aming   192.168.31.166aming1  192.168.31.100两个eth1 ip如下:aming  192.168.21.166 ami

高可用集群之heartbeat v2--基于CRM进行资源管理

CRM:Cluster Resource Management,集群资源管理 crmd:作为进程运行,监控一个端口5560/tcp/mgmtd,提供管理API GUI:图形化管理界面 CLI:命令行管理 集群节点超过两个(奇数个),集群分裂时,某一个子集群的法定票数超过半数,可认为自己正常 启用crm # vim /etc/ha.d/haresources,添加 crm respawn crm和haresource不兼容,使用crm的同时想使用haresources怎么解决? /usr/lib/