设为首页 收藏本站
查看: 874|回复: 0

[经验分享] 高可用集群之heartbeat安装配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-22 08:40:09 | 显示全部楼层 |阅读模式
高可用集群之heartbeat安装配置

说明:
系统为rhel 5.8 64bit
heartbeat版本为v2
配置web高可用服务
节点为两个:node1和node2

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

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

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

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

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

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

spacer.jpg

VIP:192.168.1.221
由于web网页在各个节点上,确保节点上的web能够正常访问,注意,确保正常后各个节点需要关闭httpd服务,并且设置开机不要自动启动:
[iyunv@node2 bao]# service httpd stop
Stopping httpd:                                           [  OK  ]
[iyunv@node2 bao]# chkconfig httpd off
[iyunv@node2 bao]# chkconfig --list | grep httpd
httpd           0:off   1:off  2:off   3:off   4:off  5:off   6:off
[iyunv@node2 bao]#

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

(1)节点1配置主机名,IP为192.168.1.169:
[iyunv@localhost ~]# hostname node1.magedu.com
[iyunv@localhost ~]# uname -n
node1.magedu.com
[iyunv@localhost ~]# vim /etc/sysconfig/network
HOSTNAME=node1.magedu.com
"/etc/sysconfig/network" 3L, 61Cwritten                                                  
[iyunv@localhost ~]#

(2)节点2配置主机名,IP为192.168.1.171:
[iyunv@localhost ~]# hostname node2.magedu.com
[iyunv@localhost ~]# uname -n
node2.magedu.com
[iyunv@localhost ~]# vim /etc/sysconfig/network
HOSTNAME=node2.magedu.com
"/etc/sysconfig/network" 3L, 61Cwritten                                                  
[iyunv@localhost ~]#

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

节点1生成秘钥:
[iyunv@node1 ~]# 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:63root@node1.magedu.com
[iyunv@node1 ~]# 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
[iyunv@node1 ~]#
说明:
-t :指定类型。
-f :指定输出文件路径名称。
-P :指定密码。

将公钥复制给web2主机:
[iyunv@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pubroot@192.168.1.171
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!
root@192.168.1.171's password:
Now try logging into the machine, with"ssh 'root@192.168.1.171'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keysthat you weren't expecting.
[iyunv@node1 ~]#
说明:
ssh-copy-id -i .ssh/id_rsa.pubroot@192.168.1.171此时没有解析,不能用root@ node2.magedu.com。

测试一下:
[iyunv@node1 ~]# ssh 192.168.1.171 'ifconfig'

节点2生成秘钥:
[iyunv@node2 .ssh]# pwd
/root/.ssh
[iyunv@node2 .ssh]# hostname
node2.magedu.com
[iyunv@node2 .ssh]# ll
total 12
-rw------- 1 root root  403 Jul 21 09:46 authorized_keys    (节点1传来的密钥)
[iyunv@node2 .ssh]#

[iyunv@node2 ~]# 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:bfroot@node2.magedu.com
[iyunv@node2 ~]# 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
[iyunv@node2 ~]#

将公钥复制给web1主机:
[iyunv@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pubroot@192.168.1.169
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!
root@192.168.1.169's password:
Now try logging into the machine, with"ssh 'root@192.168.1.169'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keysthat you weren't expecting.
[iyunv@node2 ~]#

测试一下:
[iyunv@node2 ~]# ssh 192.168.1.169'ifconfig'

[iyunv@node1 ~]# hostname
node1.magedu.com
[iyunv@node1 ~]# 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
[iyunv@node1 ~]#

(4)配置两个节点hosts解析文件,确保可以使用主机名进行通信:
[iyunv@node1 ~]# uname -n
node1.magedu.com
[iyunv@node1 ~]# vim /etc/hosts
192.168.1.169   node1.magedu.com node1     (最后node1是别名)
192.168.1.171   node1.magedu.com node2
"/etc/hosts" 6L, 265Cwritten                                                            
[iyunv@node1 ~]#
测试ping:
[iyunv@node1 ~]# 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
………………………..
[iyunv@node1 ~]# 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
[iyunv@node1 ~]#
连接报错,服务器端启用了GSSAPI。登陆的时候客户端需要对服务器端的IP地址进行反解析,如果服务器的IP地址没有配置PTR记录,那么就容易在这里卡住了。
解决方法:
[iyunv@node1 ~]# vim /etc/ssh/ssh_config
44        GSSAPIAuthentication no
[iyunv@node1 ~]# ssh node2 'date'      
Tue Jul 21 10:12:17 CST 2015
[iyunv@node1 ~]#

[iyunv@node2 ~]# uname -n
node2.magedu.com
[iyunv@node2 ~]# vim /etc/hosts
192.168.1.169   node1.magedu.com node1   
192.168.1.171   node1.magedu.com node2
"/etc/hosts" 7L, 266Cwritten                                                            
[iyunv@node2 ~]#
测试ping:
[iyunv@node2 ~]# 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
………………………………….
[iyunv@node2 ~]#

(5)确保系统时间同步:
[iyunv@node1 ~]# date;ssh node2 'date'
Tue Jul 21 10:15:45 CST 2015
Tue Jul 21 10:15:45 CST 2015
[iyunv@node1 ~]#

[iyunv@node2 ~]# date;ssh node1 'date'
Tue Jul 21 10:18:53 CST 2015
Tue Jul 21 10:18:53 CST 2015
[iyunv@node2 ~]#

2. 安装配置heartbeat v2:

安装包说明:
[iyunv@node1 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
[iyunv@node1 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上:
[iyunv@node1 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源方法):
[iyunv@node1 bao]# yum --nogpgcheck localinstall *

(2)节点2安装heartbeat,192.168.1.171上:
配置好yum源 (文章0.0配置RedHat 5系统YUM源方法):
[iyunv@node2 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
[iyunv@node2 bao]# yum --nogpgcheck localinstall *.rpm

(3)查看heartbeat安装了那些文件:
[iyunv@node1 ~]# uname -n
node1.magedu.com
[iyunv@node1 ~]# 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
[iyunv@node1 ~]#

3.手动提供heartbeat的三个配置文件:
[iyunv@node1 ha.d]# pwd
/etc/ha.d
[iyunv@node1 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
[iyunv@node1 ha.d]#

heartbeat的配置文件主要有三个:
密钥文件:权限要是600, 名称是authkeys文件,是主机之间信息传递使用的秘钥。
heartbeat服务的配置文件ha.cf:如有几个节点,节点名称的设置,多长时间检测心跳信息,集群事务信息传递是否加密等设置。
资源管理配置文件:v2版本提供了两个,haresources和crm,默认使用haresources。

安装完heartbeat,提供了配置文件的样例,路径为:
[iyunv@node1 heartbeat-2.1.4]# pwd
/usr/share/doc/heartbeat-2.1.4
[iyunv@node1 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
[iyunv@node1 heartbeat-2.1.4]#

复制三个配置文件样例到/etc/ha.d目录下:
[iyunv@node1 heartbeat-2.1.4]# pwd
/usr/share/doc/heartbeat-2.1.4
[iyunv@node1 heartbeat-2.1.4]# cp authkeys ha.cfharesources /etc/ha.d/
[iyunv@node1 heartbeat-2.1.4]# cd /etc/ha.d/
[iyunv@node1 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
[iyunv@node1 ha.d]#
[iyunv@node1 ha.d]# chmod 600 authkeys
注意:需要更改authkeys权限为600。

(1)配置authkeys文件:
该文件是主机之间信息传递使用的秘钥,权限要是600。
[iyunv@node1 ha.d]# pwd
/etc/ha.d
[iyunv@node1 ha.d]# ll authkeys
-rw------- 1 root root 645 Jul 21 14:06authkeys
[iyunv@node1 ha.d]#

[iyunv@node1 ha.d]# cat authkeys
……………….
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
[iyunv@node1 ha.d]#
说明:
默认都是注释掉的,用法用auth关键字指定下列列表中的数字,使用哪个认证机制。
crc :循环冗余校验码(CyclicRedundancy Check),不安全。
sha1 :安全哈希算法
md5 :消息摘要算法第五版

配置使用md5认证机制:
[iyunv@node1 ha.d]# uname -n
node1.magedu.com
[iyunv@node1 ha.d]# pwd
/etc/ha.d
[iyunv@node1 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  -   (使用该行随机数)
[iyunv@node1 ha.d]# vim authkeys
auth 1
1 md5 e46c1b850b41efcebc5d95fa614c1d18
"authkeys" 29L, 692C written                                                              
[iyunv@node1 ha.d]#

或者使用openssl生成密钥也可以:
[iyunv@web1 ha.d]# openssl rand -hex 6
e5b50e897cb4   (生成的秘钥)

(2)配置主配置文件ha.cf:
[iyunv@node1 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                                                              
[iyunv@node1 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:
[iyunv@node1 ha.d]# vim haresources
150 node1.magedu.comIPaddr::192.168.1.221/24/eth0 httpd
"haresources" 150L, 5958C written
[iyunv@node1 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:
[iyunv@node1 ha.d]# uname -n
node1.magedu.com
[iyunv@node1 ha.d]# pwd
/etc/ha.d
[iyunv@node1 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   
[iyunv@node1 ha.d]#

5.启动heartbeat服务:
[iyunv@node1 ~]# service heartbeat start
Starting High-Availability services:
2015/07/21_15:50:34 INFO:  Resource is stopped
                                                           [  OK  ]
[iyunv@node1 ~]# ssh node2 'service heartbeat start'
Starting High-Availability services:
2015/07/21_15:51:15 INFO:  Resource is stopped
[ OK  ]
[iyunv@node1 ~]#
一般远程启动其他节点服务。

6.查看启动结果,浏览器访问192.168.1.221应该出现node1节点的网页:
[iyunv@node1 ~]# netstat -lntp
tcp       0      0 :::80         :::*          LISTEN      2677/httpd         
[iyunv@node1 ~]#
[iyunv@node1 ~]# 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
[iyunv@node1 ~]#
已经都启动!

7.模拟node1节点故障,查看节点node2是否显示:
heartbeat提供了测试脚本,直接实现资源转移:
[iyunv@node1 heartbeat]# pwd
/usr/lib64/heartbeat
[iyunv@node1 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
[iyunv@node1 heartbeat]#
说明:
ha_propagate   \\此脚本是将heartbeat的配置文件复制给其他节点
hb_standby     \\此脚本是将当前节点切换为备节点
hb_takeover     \\此脚本是将当前节点切换为主节点

[iyunv@node1 heartbeat]# uname -n
node1.magedu.com
[iyunv@node1 heartbeat]# pwd
/usr/lib64/heartbeat
[iyunv@node1 heartbeat]# ./hb_standby
2015/07/21_16:01:09 Going standby [all].
[iyunv@node1 heartbeat]#

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

把资源从node2节点上转移到节点node1上:
[iyunv@node2 heartbeat]# uname -n
node2.magedu.com
[iyunv@node2 heartbeat]# pwd
/usr/lib64/heartbeat
[iyunv@node2 heartbeat]# ./hb_standby
2015/07/21_16:02:52 Going standby [all].
[iyunv@node2 heartbeat]#








heartbeatv2+nfs实现高可用httpd

接上面练习!
使用NFS为两台高可用主机提供NFS文件系统

spacer.jpg

NFS:192.168.1.162

首先把HA两个节点的heartbeat服务都停掉:
在主节点上用ssh先停掉节点node2的服务:
[iyunv@node1 ~]# ssh node2 'service heartbeat stop'
Stopping High-Availability services:
[ OK  ]
[iyunv@node1 ~]# service heartbeat stop           
Stopping High-Availability services:
                                                          [  OK  ]
[iyunv@node1 ~]#

1.开启NFS功能(192.168.1.162):
[iyunv@rh5 ~]# mkdir /web/htdocs –pv     (建立网页存放目录)
mkdir: created directory `/web'
mkdir: created directory `/web/htdocs'
[iyunv@rh5 ~]# vim /etc/exports
/web/htdocs    192.168.1.0/24(ro)
"/etc/exports" 1L, 34Cwritten                                                            
[iyunv@rh5 ~]# service nfs start
Starting NFS services:                                     [ OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
[iyunv@rh5 ~]# showmount -e 192.168.1.162
Export list for 192.168.1.162:
/web/htdocs 192.168.1.0/24
[iyunv@rh5 ~]#
[iyunv@rh5 ~]# echo "<h1>NFSPage</h1>"  >/web/htdocs/index.html   (提供测试网页)
[iyunv@rh5 ~]# ll /web/htdocs/index.html
-rw-r--r-- 1 root root 18 Jul 21 16:57/web/htdocs/index.html
[iyunv@rh5 ~]#

2.在各节点上测试挂载NFS:
[iyunv@node1 ~]# uname -n
node1.magedu.com
[iyunv@node1 ~]# mount -t nfs 192.168.1.162:/web/htdocs /mnt         
[iyunv@node1 ~]# ll /mnt/
total 4
-rw-r--r-- 1 root root 18 Jul 21 16:57index.html
[iyunv@node1 ~]# umount /mnt/
[iyunv@node1 ~]#  (测试完了要卸载掉)

3. 修改资源配置文件:
[iyunv@node1 ha.d]# uname -n
node1.magedu.com
[iyunv@node1 ha.d]# pwd
/etc/ha.d
[iyunv@node1 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                                                         
[iyunv@node1 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.复制资源配置文件给其他节点:
[iyunv@node1 ha.d]# scp haresources node2:/etc/ha.d/
haresources                                                               100% 6017     5.9KB/s   00:00   
[iyunv@node1 ha.d]#

5.启动heartbeat服务:
[iyunv@node1 ~]# service heartbeat start
Starting High-Availability services:
2015/07/21_17:06:04 INFO:  Resource is stopped
                                                          [  OK  ]
[iyunv@node1 ~]# ssh node2 'service heartbeat start'
Starting High-Availability services:
2015/07/21_17:06:18 INFO:  Resource is stopped
[ OK  ]
[iyunv@node1 ~]#

6.浏览器访问192.168.1.221查看






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-89260-1-1.html 上篇帖子: Drbd+nfs+heartbeat 简要总结 下篇帖子: HeartBeat+DRBD+NFS 高可用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表