CentOS5.8 HA集群之基于crm配置 heartbeat + nfs + httpd
大纲一、系统环境
二、基于heartbeat的GUI管理示例
一、系统环境
CentOS5.8 x86_64
node1.network.com node1 172.16.1.101
node2.network.com node2 172.16.1.105
NFS Server /www 172.16.1.102
拓扑图
http://s2.运维网.com/wyfs02/M01/79/AB/wKioL1aXs8jBuC8iAAGietGLMH8745.jpg
二、基于heartbeat的GUI管理示例
1、准备工作
(1)、时间同步
# ntpdate s2c.time.edu.cn
# ntpdate s2c.time.edu.cn
可根据需要在每个节点上定义crontab任务
# which ntpdate
/sbin/ntpdate
# echo "*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null" >> /var/spool/cron/root
# crontab -l
*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null(2)、主机名称要与uname -n,并通过/etc/hosts解析
node1
# hostname node1.network.com
# uname -n
node1.network.com
# sed -i 's@\(HOSTNAME=\).*@\1node1.network.com@g'/etc/sysconfig/network
node2
# hostname node2.network.com
# uname -n
node2.network.com
# sed -i 's@\(HOSTNAME=\).*@\1node2.network.com@g'/etc/sysconfig/network
node1添加hosts解析
# vim /etc/hosts
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.101node1.network.com node1
172.16.1.105node2.network.com node2
拷贝此hosts文件至node2
# vim /etc/hosts
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.101node1.network.com node1
172.16.1.105node2.network.com node2
# scp /etc/hosts node2:/etc/
The authenticity of host 'node2 (172.16.1.105)' can't be established.
RSA key fingerprint is 13:42:92:7b:ff:61:d8:f3:7c:97:5f:22:f6:71:b3:24.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,172.16.1.105' (RSA) to the list of known hosts.
root@node2's password:
hosts 100%233 0.2KB/s 00:00
(3)、ssh互信通信
node1
# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
Generating public/private rsa key pair.
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? n # 我这里已经生成过了
# ssh-copy-id -i ~/.ssh/id_rsa.pub node2
root@node2's password:
Now try logging into the machine, with "ssh 'node2'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
# setenforce 0
# ssh node2 'ifconfig'
eth0 Link encap:EthernetHWaddr 00:0C:29:D6:03:52
inet addr:172.16.1.105Bcast:255.255.255.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed6:352/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:9881 errors:0 dropped:0 overruns:0 frame:0
TX packets:11220 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5898514 (5.6 MiB)TX bytes:1850217 (1.7 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:16436Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1112 (1.0 KiB)TX bytes:1112 (1.0 KiB)
同理node2也需要做同样的双击互信,一样的操作,此处不再演示2、安装heartbeat一系列的软件包(需配置epel源)
node1
# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-guinode2
# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-gui3、配置密钥文件authkeys
# cd /etc/ha.d/
# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,authkeys} .
# ls
authkeysha.cfharcrc.dREADME.configresource.dshellfuncs
# vim authkeys
# tail -2 authkeys
auth 2
2 sha1 UTen4saEz4g= # 这里使用sha1认证,可自行定义
# chmod 600 authkeys
# ll authkeys
-rw------- 1 root root 672 Jan6 22:29 authkeys # 保证权限为6004、配置主配置文件ha.cf
# vim ha.cf
# grep "^[^#]" ha.cf # 参数可自行根据需要调整
logfile/var/log/heartbeat.log
keepalive 1
deadtime 10
warntime 3
udpport694
mcast eth0 225.0.100.20 694 1 0
auto_failback on
node node1.network.com # 注意此处的主机名一定要与uname -n结果保持一致
node node2.network.com
ping172.16.1.1
compressionbz2
compression_threshold 2
crm on # 添加此项才能使用v2版的heartbeat功能
将以上两个文件的修改同步至node2节点
# /usr/lib64/heartbeat/ha_propagate
Propagating HA configuration files to node node2.network.com.
ha.cf 100% 10KB10.4KB/s 00:00
authkeys 100%672 0.7KB/s 00:00
Setting HA startup configuration on node node2.network.com.
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: chkconfig --list
chkconfig --add
chkconfig --del
chkconfig [--level ]5、启动heartbeat服务(请确保资源不能开机启动)
# service heartbeat start
Starting High-Availability services:
# ssh node2 'service heartbeat start'
Starting High-Availability services:
# ss -tnl # 可以看到5560端口(mgmtd)处于监听状态
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 *:111 *:*
0 0 *:22 *:*
0 0 *:5560 *:*
0 0 127.0.0.1:6011 *:*
0 0 *:955 *:*
0 0 :::22 :::*
0 0 ::1:6011 :::*6、hacluster用户添加密码(只需配置一个节点的hacluster的密码)
node1
# grep "hacluster" /etc/passwd
hacluster:x:101:103:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin
# passwd hacluster
Changing password for user hacluster.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.7、登录图形界面
# hb_gui & # 必须得安装heartbeat软件包才能使用gui
9228点击登录-->输入密码点ok
http://s1.运维网.com/wyfs02/M01/79/4B/wKiom1aN2SLyHNbKAAIJtJrQbjM140.jpg
登录成功后的界面
http://s1.运维网.com/wyfs02/M01/79/4D/wKiom1aN94Dzq5tXAAMB-1vOkY8466.jpg
8、配置group资源和webip
右键Resources-->Add New Item
http://s5.运维网.com/wyfs02/M01/79/4C/wKioL1aN_DmAGAYZAAMuiGXAPNc086.jpg
选择Item Type为group,点击OK
http://s4.运维网.com/wyfs02/M00/79/4C/wKioL1aN_DvB3B16AAKIEAvRt3Q340.jpg
group资源ID修改为webservice,点击ok
http://s4.运维网.com/wyfs02/M02/79/4D/wKiom1aN_BXQU9JeAAKyynJf7-o891.jpg
ResourceID修改为webip,资源代理选择IPaddr,双击IPadd,下面填写此代理的相关参数
http://s5.运维网.com/wyfs02/M02/79/4C/wKioL1aN_EGROHOOAATiZTcKBYE415.jpg
点击Add,到此一个webservice组和第一个资源webip添加完成
9、配置webstore
右键webservice-->Add New Item
http://s4.运维网.com/wyfs02/M00/79/4C/wKioL1aN_bCQVsvDAAPJDa3m2W0110.jpg
Item Type选择native,点击OK
http://s5.运维网.com/wyfs02/M02/79/4E/wKiom1aN_YrAk_JVAAMsafx0hOs165.jpg
Resource ID修改为webstore,资源代理选择Filesystem,双击选择填写挂载设备,挂载点,文件系统类型
http://s1.运维网.com/wyfs02/M00/79/4C/wKioL1aN_baTuALlAATeLggQsiw573.jpg
点击Add,到此第二个资源webstore添加完成
10、配置httpd
右键webservice-->Add New Item
http://s3.运维网.com/wyfs02/M01/79/4F/wKiom1aN_mSzv1PKAAPOw7yxoKg990.jpg
Item Type选择native,点击OK
http://s4.运维网.com/wyfs02/M01/79/4D/wKioL1aN_o7w_TAlAANuwF5O8_U615.jpg
Resource ID修改为httpd,资源代理选择httpd,此LSB类型的脚本不需要添加额外的参数
http://s2.运维网.com/wyfs02/M02/79/4F/wKiom1aN_mqDSi2IAATUPiU7uKU995.jpg
点击Add,到此第三个资源httpd添加完成
11、给webservice资源组添加位置约束(并非必须)
右键Locations-->Add New Item
http://s2.运维网.com/wyfs02/M02/79/4D/wKioL1aN_3LQCz6DAANE2nka_Ko591.jpg
Item Type选择location,点击OK
http://s3.运维网.com/wyfs02/M02/79/4F/wKiom1aN_0yRtEm0AALkrX8zIKk466.jpg
位置约束ID自行定义,我这里是webservice_on_node1,Resource选择组资源webservice
http://s5.运维网.com/wyfs02/M02/79/4D/wKioL1aN_3aicheKAAMIOW7av10593.jpg
定义Score分数,我这里是INF(正无穷),还可以点击Add Expression,自行定义其他的属性
http://s1.运维网.com/wyfs02/M00/79/4F/wKiom1aN_1GwbS6zAAQtIcnZqmo406.jpg
定义完成之后显示如下
http://s4.运维网.com/wyfs02/M00/79/4D/wKioL1aN_3zTZfQnAAQRVu1Bwlc536.jpg
到此为止,一个排列约束定义完毕
12、启动webservice资源组
右键webservice-->start
http://s3.运维网.com/wyfs02/M00/79/4F/wKiom1aOARPS0mgiAAQIt2WLxBY694.jpg
启动成功,显示如下
http://s3.运维网.com/wyfs02/M01/79/4D/wKioL1aOAT2AHjrkAANreZRjWzg958.jpg
浏览器访问http://172.16.1.110,显示如下
http://s2.运维网.com/wyfs02/M02/79/4D/wKioL1aOAXryePj5AAF6qaKdLLU892.jpg
可以看到已然正常工作,此时让node1节点模拟故障,看资源是否会自动迁移
http://s4.运维网.com/wyfs02/M00/79/4D/wKioL1aOAhODJ1cbAAOqBbxQLZ4788.jpg
http://s5.运维网.com/wyfs02/M01/79/4F/wKiom1aOAe2ykIR7AAN98nICIqI494.jpg
此时可以看到资源成功迁移至node2节点上了
http://s1.运维网.com/wyfs02/M02/79/4E/wKioL1aOAmvwI3NtAAOP69xmckQ523.jpg
再用浏览器访问一下,看能否实现高可用
http://s3.运维网.com/wyfs02/M00/79/4E/wKioL1aOAprCKQfzAAF6qaKdLLU243.jpg
可以看到,正常访问完全没有问题。到此为止,一个基于heartbeat的GUI配置完成,明天继续讲基于CLI的配置方式
注意:为避免出现各种问题,这里关闭了iptables和SElinux
页:
[1]