应用redhat cluster suit,实现高可用(HA)集群。
注:本文在第一次成文时少写了几个关键步骤,已添加:2.1.4A, 2.3 4
虚拟机环境如下:
[root@stu121 ~]# uname -a
Linux stu121.example.com 2.6.18-238.12.1.el5 #1 SMP Tue May 31 13:23:01 EDT 2011 i686 i686 i386 GNU/Linux
0 规划
我们用red hat cluster suit在3个centos5u4虚拟机上建立一个高可用集群(练习,练习哈);
集群中有3个节点: 192.168.0.121(node1), 192.168.0.122(node2), 192.168.0.123(fence,虚拟机上没有fence设备,所以用一个节点来模拟);
集群名:cluster_ha;
faildomain名:fd_1;
服务名: web_s(实际启动的服务就是apache-httpd)
服务下有2个资源,fip(浮动ip)资源:192.168.0.120, script资源:httpd自带的启动脚本/etc/init.d/httpd;
1. 准备工作
1.1 安装
1.1.1 因为本地没有fence设备,用一个节点模拟fence,所以要安装GNBD
[root@stu121 ~]# yum install gnbd1.1.2 安装 red hat linux cluster suit
[root@stu121 ~]# yum groupinstall Clustering
安装好后,测试一下:
[root@stu121 ~]# system-config-cluster
如果出现下面的图形界面,表示安装成功了:
1.1.3 如果没有安装apache
yum install httpd
1.2 一些辅助配置
1.2.1 配置节点名
在node1上
vim /etc/hosts
在文件最后加上3行:
192.168.0.121 node1.test.com node1
192.168.0.122 node2.test.com node2
192.168.0.123 fence.test.com fence
1.2.2 生成3个节点互访用的公钥私钥
在node1上
ssh-keygen -t dsa
一路回车,然后
ssh-copy-id -i .ssh/id_dsa.pub root@node1
1.2.3 让node2和fence和node1保持一致
在node1上 执行:
scp -r ~/.ssh/ root@192.168.0.122:/root/
scp -r ~/.ssh/ root@192.168.0.123:/root/
scp /etc/hosts root@192.168.0.122:/etc/
scp /etc/hosts root@192.168.0.123:/etc/
#然后就可以用ssh root@node1/node2/fence相互登录了,不需要密码
2 配置集群
2.1 配置HA cluster(现在node1上配置)
2.1.1 执行
system-config-cluster
会出现上面那个图,然后选择"create new configuration"
2.1.2 配置cluster
2.1.3 添加节点 "Cluster Nodes -> Add a Cluster Node",node1,node2,fence的操作都相同
2.1.4 添加fence设备 "Fence Devices->Add a Fence Device",主义fence的name不能和fenfce节点的名字相同
2.1.4A 为每个节点,包括fence节点,配置fence-level和fence,点击"Manage Fencing For This Node",然后点击”Add a New Fence Level" 来增加一个fence-level,然后选择这个fence-level,点击“Add A new Fence to this Level",截图如下:
2.1.5 添加fail over domain"Failover Domains->Create a Failover Domain" 按规划取名fd_1,它的配置信息如下
2.1.6 添加资源
添加fip(192.168.0.120)“Resources->Create a Resource->IP Address"
添加script “Resources->Create a Resource->Script"
2.1.7 添加服务“Services->Create a Service",按规划服务名为web_s;并添加资源,点击"Add a Shared Resource to this service"(哈,这个service为什么不大写呢?语法错误?呵呵),先添加ip资源,然后选中ip资源添加httpd资源。结果如下
2.2 复制cluster.conf 到node2 和 fence
scp /etc/cluster/cluster.conf root@node2:/etc/cluster/
scp /etc/cluster/cluster.conf root@fence:/etc/cluster/
2.3 3个节点一起启动cman,注意要在selinux的配置上保持一致,全开(打开对应的端口),或者关闭iptables (servcie iptables stop)
在3个节点同时执行
[root@*** ~]# service cman start
Starting cluster:
Loading modules... done
Mounting configfs... done
Starting ccsd... done
Starting cman... done
Starting daemons... done
Starting fencing... done
[确定]
ok了! 然后可以在3个节点执行
[root@xxx ~]# service rgmanager start
启动 Cluster Service Manager: [确定]
2.3 4 在fence节点上启动gnbd_serv
[root@fence ~]#gnbd_serv
2.4 检查 在fence节点上执行
[root@fence ~]# clustat
Cluster Status for cluster_ha @ Sat Jul 23 22:48:27 2011
Member Status: Quorate
Member Name ID Status
------ ---- ---- ------
node1 1 Online, rgmanager
node2 2 Online, rgmanager
fence 3 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:web_s node1 started
这时,是node1提供服务
2.5 现在我们就可以访问fip了
http://192.168.0.120/ 你会看到apache首页,如果node1和node2的首页不一样,你会明确看到node1的页面
注意,这个时候node2上的httpd没有被自动起来!
2.6 手工停止node1上httpd,验证failover:在node1上执行service httpd stop,然后还是在fence节点上刷clustat,过几秒钟会看到
Member Name ID Status
------ ---- ---- ------
node1 1 Online, rgmanager
node2 2 Online, rgmanager
fence 3 Online, Local, rgmanager
Service Name Owner (Last) State
------- ---- ----- ------ -----
service:web_s node2 started
注意,因为node1是httpd被stop了,节点依然是活着的,所以上面node1的status还是Online状态,如果在node1上执行ifdown eth0(关闭node1上的工作网卡),那么node1就成为Offline状态。
3 其他
上述只是练习,实际生产环境是用硬件fence设备的---在选fence设备类型时要选APC。
其他,增删节点,就相对容易了。