大纲
一、系统环境
二、基于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
拓扑图
二、基于heartbeat的GUI管理示例
1、准备工作
(1)、时间同步
[root@node1 ~]# ntpdate s2c.time.edu.cn [root@node2 ~]# ntpdate s2c.time.edu.cn 可根据需要在每个节点上定义crontab任务 [root@node1 ~]# which ntpdate /sbin/ntpdate [root@node1 ~]# echo "*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null" >> /var/spool/cron/root [root@node1 ~]# crontab -l */5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null
(2)、主机名称要与uname -n,并通过/etc/hosts解析
node1 [root@node1 ~]# hostname node1.network.com [root@node1 ~]# uname -n node1.network.com [root@node1 ~]# sed -i 's@\(HOSTNAME=\).*@\1node1.network.com@g' /etc/sysconfig/network node2 [root@node2 ~]# hostname node2.network.com [root@node2 ~]# uname -n node2.network.com [root@node2 ~]# sed -i 's@\(HOSTNAME=\).*@\1node2.network.com@g' /etc/sysconfig/network node1添加hosts解析 [root@node1 ~]# vim /etc/hosts [root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.1.101 node1.network.com node1 172.16.1.105 node2.network.com node2 拷贝此hosts文件至node2 [root@node1 ~]# vim /etc/hosts [root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.1.101 node1.network.com node1 172.16.1.105 node2.network.com node2 [root@node1 ~]# 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 [root@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 # 我这里已经生成过了 [root@node1 ~]# 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. [root@node1 ~]# setenforce 0 [root@node1 ~]# ssh node2 'ifconfig' eth0 Link encap:Ethernet HWaddr 00:0C:29:D6:03:52 inet addr:172.16.1.105 Bcast:255.255.255.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fed6:352/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: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.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric: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
[root@node1 ~]# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-gui
node2
[root@node2 ~]# yum install -y heartbeat heartbeat-pils heartbeat-stonith heartbeat-gui
3、配置密钥文件authkeys
[root@node1 ~]# cd /etc/ha.d/ [root@node1 ha.d]# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,authkeys} . [root@node1 ha.d]# ls authkeys ha.cf harc rc.d README.config resource.d shellfuncs [root@node1 ha.d]# vim authkeys [root@node1 ha.d]# tail -2 authkeys auth 2 2 sha1 UTen4saEz4g= # 这里使用sha1认证,可自行定义 [root@node1 ha.d]# chmod 600 authkeys [root@node1 ha.d]# ll authkeys -rw------- 1 root root 672 Jan 6 22:29 authkeys # 保证权限为600
4、配置主配置文件ha.cf
[root@node1 ha.d]# vim ha.cf [root@node1 ha.d]# grep "^[^#]" ha.cf # 参数可自行根据需要调整 logfile /var/log/heartbeat.log keepalive 1 deadtime 10 warntime 3 udpport 694 mcast eth0 225.0.100.20 694 1 0 auto_failback on node node1.network.com # 注意此处的主机名一定要与uname -n结果保持一致 node node2.network.com ping 172.16.1.1 compression bz2 compression_threshold 2 crm on # 添加此项才能使用v2版的heartbeat功能 将以上两个文件的修改同步至node2节点 [root@node1 ha.d]# /usr/lib64/heartbeat/ha_propagate Propagating HA configuration files to node node2.network.com. ha.cf 100% 10KB 10.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 [name] chkconfig --addchkconfig --del chkconfig [--level ]
5、启动heartbeat服务(请确保资源不能开机启动)
[root@node1 ha.d]# service heartbeat start Starting High-Availability services: [ OK ] [root@node1 ha.d]# ssh node2 'service heartbeat start' Starting High-Availability services: [ OK ] [root@node1 ha.d]# 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
[root@node1 ~]# grep "hacluster" /etc/passwd hacluster:x:101:103:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin [root@node1 ~]# 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、登录图形界面
[root@node1 ha.d]# hb_gui & # 必须得安装heartbeat软件包才能使用gui [1] 9228
点击登录-->输入密码点ok
登录成功后的界面
8、配置group资源和webip
右键Resources-->Add New Item
选择Item Type为group,点击OK
group资源ID修改为webservice,点击ok
ResourceID修改为webip,资源代理选择IPaddr,双击IPadd,下面填写此代理的相关参数
点击Add,到此一个webservice组和第一个资源webip添加完成
9、配置webstore
右键webservice-->Add New Item
Item Type选择native,点击OK
Resource ID修改为webstore,资源代理选择Filesystem,双击选择填写挂载设备,挂载点,文件系统类型
点击Add,到此第二个资源webstore添加完成
10、配置httpd
右键webservice-->Add New Item
Item Type选择native,点击OK
Resource ID修改为httpd,资源代理选择httpd,此LSB类型的脚本不需要添加额外的参数
点击Add,到此第三个资源httpd添加完成
11、给webservice资源组添加位置约束(并非必须)
右键Locations-->Add New Item
Item Type选择location,点击OK
位置约束ID自行定义,我这里是webservice_on_node1,Resource选择组资源webservice
定义Score分数,我这里是INF(正无穷),还可以点击Add Expression,自行定义其他的属性
定义完成之后显示如下
到此为止,一个排列约束定义完毕
12、启动webservice资源组
右键webservice-->start
启动成功,显示如下
浏览器访问http://172.16.1.110,显示如下
可以看到已然正常工作,此时让node1节点模拟故障,看资源是否会自动迁移
此时可以看到资源成功迁移至node2节点上了
再用浏览器访问一下,看能否实现高可用
可以看到,正常访问完全没有问题。到此为止,一个基于heartbeat的GUI配置完成,明天继续讲基于CLI的配置方式
注意:为避免出现各种问题,这里关闭了iptables和SElinux