理论基础:
User → HA → Lb → web → sql → 分布式filesystem ->磁盘I/O
用户 高可用 负载均衡 应用 数据库 mfs/hadoop
磁盘I/O是硬伤,前面的各个厂商基本都可以做到最好,虽然可以考虑换成固态硬盘,但是固态的价格就目前来看相对比较昂贵,实际情况下显然不现实。
红帽集群套件 RHCS
红帽集群套件管理器 RHCSM
集群配置管理工具 conga
luci :8084<-web<-user
/\ vip
/ \ service(web)
ricci <--> ricci filesystem
HA
cman 核心套件
rgmanage 集群资源管理器
lvm2-cluster lvm支持
sg3_utils 支持scsi
gfs2-utils 分布式文件系统支持
注:ricci只负责与luci连接进行集群配置
真正的集群服务为:
cman
rgmanage
modclusterd
clvmd
server33 <-> server34
\ /
\ /
\ HA /
share storage
当server33的网卡坏了,server33和server34都会认为对方挂掉了,双方同时接管资源,用户在访问的时候因为server33的网卡坏的,无法访问,只能访问server34,因此在用户看来,服务是没有问题的。
当server33昏迷后,此时server34接管资源,但是当server33恢复后,还占据着原来的资源,此时用户访问时就不知道该访问哪台主机了。因此需要第三方设备来解决此问题,即Fence!
Fence
/ \
/ \
一整套资源:
/ HA \ vip
server33 <-> server34
service
\ /
stroage
\ /
\ /
share storage
server33和server34连接着Fence,当有其中一方挂掉之后,虽然双方都会认为对方挂掉了,但是另一方仍然可以连接到Fence,可以通过向fence所在主机发送请求将对方主机进行断电处理,自己接管资源。当故障主机恢复后,将成为备份主机,不再是master,也不会争抢资源。
存储方式
SAN存储(iscsi):服务端共享出设备,在客户端上进行分区,格式化才能使用。即文件系统在客户端上
NAS存储(NFS):在服务端上进行分区,格式化。客户端上只需进行mount操作即可使用。
配置:
系统环境: rhel6 x86_64 iptables and selinux disabled
主机: 192.168.122.119 server19.example.com
192.168.122.25 server25.example.com
192.168.122.1 desktop36.example.com
yum仓库配置:
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=ftp://192.168.122.1/pub/yum
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[HighAvailability]
name=Instructor
Server Repository
baseurl=ftp://192.168.122.1/pub/yum/HighAvailability
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1
[LoadBalancer]
name=Instructor
Server Repository
baseurl=ftp://192.168.122.1/pub/yum/LoadBalancer
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1
[ResilientStorage]
name=Instructor
Server Repository
baseurl=ftp://192.168.122.1/pub/yum/ResilientStorage
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1
[ScalableFileSystem]
name=Instructor
Server Repository
baseurl=ftp://192.168.122.1/pub/yum/ScalableFileSystem
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1
#启动luci
以下步骤在server19和server25上实施:
[[email protected]
~]# yum install ricci -y
[[email protected]
~]# passwd ricci
[[email protected]
~]# chkconfig ricci on
[ro[email protected]
~]# /etc/init.d/ricci start
以下步骤在desktop36上实施:
[[email protected]
~]# yum install luci -y
[[email protected]
~]# /etc/init.d/luci start
启动成功系统会给出一个网址,访问此网址(例如上图网址为http://desktop36.example.com:8084),访问时注意在desktop36的/etc/hosts中写上解析.
下载证书,并以desktop36的root身份登录,会显示homebase页面
注:luci登录时可以使用luci所在电脑上的本机用户登录,但是只有root用户才可以管理集群
#创建集群
选择Manage Clusters
选择Create
按照如下图配置创建集群
注:集群名称小于15个字符
选择Download Packages有两层含义:
1.当节点上没有安装集群软件包的时候,会自动安装相关软件包
2.当节点上已经安装了集群软件包的时候,会自动检查更新并安装
创建成功后出现类似如下页面:
#配置Fence设备
以下步骤在desktop36上实施:
[[email protected] ~]# yum list fence*
[[email protected] ~]# yum install fence-virtd.x86_64 fence-virtd-libvirt.x86_64 fence-virtd-multicast.x86_64 -y
[[email protected] ~]# fence_virtd -c
Module search path [/usr/lib64/fence-virt]:
Available
backends:
libvirt 0.1
Available
listeners:
multicast 1.1
Listener
modules are responsible for accepting requests
from
fencing clients.
Listener
module [multicast]:
The
multicast listener module is designed for use environments
where
the guests and hosts may communicate over a network using
multicast.
The
multicast address is the address that a client will use to
send
fencing requests to fence_virtd.
Multicast
IP Address [225.0.0.12]:
Using
ipv4 as family.
Multicast
IP Port [1229]:
Setting
a preferred interface causes fence_virtd to listen only
on
that interface. Normally, it listens on the default network
interface.
In environments where the virtual machines are
using
the host machine as a gateway, this *must* be set
(typically
to virbr0).
Set
to ‘none‘ for no interface.
Interface
[none]: virbr0
The
key file is the shared key information which is used to
authenticate
fencing requests. The contents of this file must
be
distributed to each physical host and virtual machine within
a
cluster.
Key
File [/etc/cluster/fence_xvm.key]:
Backend
modules are responsible for routing requests to
the
appropriate hypervisor or management layer.
Backend
module [checkpoint]: libvirt
The
libvirt backend module is designed for single desktops or
servers.
Do not use in environments where virtual machines
may
be migrated between hosts.
Libvirt
URI [qemu:///system]:
Configuration
complete.
===
Begin Configuration ===
backends
{
libvirt
{
uri
= "qemu:///system";
}
}
listeners
{
multicast
{
interface
= "virbr0";
port
= "1229";
family
= "ipv4";
address
= "225.0.0.12";
key_file
= "/etc/cluster/fence_xvm.key";
}
}
fence_virtd
{
module_path
= "/usr/lib64/fence-virt";
backend
= "libvirt";
listener
= "multicast";
}
===
End Configuration ===
Replace
/etc/fence_virt.conf with the above [y/N]? y
注:以上设置除“Interface”处填写虚拟机通信接口和Backend
module填写libvirt外,其他选项均可回车保持默认。
[[email protected]
~]# mkdir /etc/cluster
[[email protected]
~]# dd if=/dev/urandom of=/etc/cluster/fence_xvm.key bs=128 count=1
[[email protected]
~]# scp /etc/cluster/fence_xvm.key [email protected]:/etc/cluster/
[[email protected]
~]# scp /etc/cluster/fence_xvm.key [email protected]:/etc/cluster/
[[email protected]
~]# /etc/init.d/fence_virtd start
[[email protected]
~]# netstat -anuple | grep fence
udp
0 0 0.0.0.0:1229 0.0.0.0:*
0 823705 6320/fence_virtd
注:可查看到1229端口说明fence_virtd启动成功.
测试:
server19的domain为vm1,server25的domain为vm2
在server19上执行
fence_xvm
-H vm2,若server25重启说明配置成功
在server25上执行
fence_xvm
-H vm1,若server19重启说明配置成功
选择Fence
Devices
选择add
按照下列图片进行配置
选择Nodes
按照下列图片对每一个node进行配置
选择Add
Fence Method
选择Add
Fence Instance
注:此处所填写的Domain与Virtual
Machine Manager中此虚拟机的名称一致.
测试:
在server19上执行
echo
c > /proc/sysrq-trigger,若server19重启说明配置成功
在server25上执行
echo
c > /proc/sysrq-trigger,若server25重启说明配置成功
#在集群中添加集群服务(以apache为例)
以下步骤在server19和server25上实施:
[[email protected]
~]# yum install httpd -y
[[email protected]
~]# echo `hostname` > /var/www/html/index.html
注:无需手动将apache启动起来,将由集群来管理服务.
选择Failover
Domains
选择add
按如下图配置
注意:Priority值越低优先级越高,所以以上配置说明192.168.122.119为主节点
选择Resources
选择add
按如下图配置添加IP
Address和Script
注:此IP必须是无人使用的.
选择Service Groups
选择add
按如下图配置
选择Add Resouce添加刚才所设置的IP Address和Script并点击Submit
访问192.168.122.147若正常则说明配置成功.
测试:
可通过执行
watch
clustat查看当前集群服务由哪个node接管着(假设刚开始由server19接管)
1.将server19上的httpd服务关闭,查看集群服务是否会由server25接管.
2.在server25上执行ifconfig
eth0 down模拟网线断掉,看server25是否被执行断电操作,并且集群服务由server19接管
3.在server19上执行echo
c >
/proc/sysrq-trigger模拟内核崩溃,看server19是否被执行断电操作,集群服务被server25接管,且当server19重启后服务自动切换回server19上.
#配置共享存储
以下步骤在desktop36上实施:
先划分出一个分区,类型为Linux
LVM.
[[email protected]
Desktop]# pvcreate /dev/sdb8
[[email protected]
Desktop]# vgcreate vg_rhelserver6 /dev/sdb8
[[email protected]
Desktop]# lvcreate -L 3G -n koendemo vg_rhelserver6
[[email protected]
Desktop]# yum search all iscsi
[[email protected]
Desktop]# yum install scsi-target-utils.x86_64 -y
[[email protected]
Desktop]# vim /etc/tgt/targets.conf
<target
iqn.2013-07.com.example:server.target1>
backing-store
/dev/vg_rhelserver6/koendemo
initiator-address 192.168.122.119
initiator-address 192.168.122.25
</target>
[[email protected]
Desktop]# /etc/init.d/tgtd start
通过执行tgtadm
--lld iscsi --op show --mode target能查看到次设备说明配置成功
以下步骤在server19和server25上实施:
[[email protected]
~]# yum install iscsi-initiator-utils.x86_64 -y
[[email protected]
~]# iscsiadm -m discovery -t st -p 192.168.122.1
[[email protected]
~]# iscsiadm -m node -l
执行fdisk
-l可查看到此设备说明成功.
[[email protected]
~]# lvmconf --enable-cluster
[[email protected]
~]# /etc/init.d/clvmd restart
以下步骤在server19或server25上实施:
[[email protected]
~]# fdisk -cu /dev/sdb
将此设备划分分区,一般只划分一个分区,类型为Linux
LVM,若划分多个分区为保险期间要注意备份分区表.
[[email protected]
~]# pvcreate /dev/sdb1
[[email protected]
~]# vgcreate -c y koenvg /dev/sdb1
执行vgdisplay查看koenvg的Clustered参数是否为yes.
[[email protected]
~]# lvcreate -L 1G -n koenlv koenvg
[[email protected]
~]# mkfs.gfs2 -p lock_dlm -t koen_007:gfs2 -j 3 /dev/koenvg/koenlv
-p
定义为 DLM
锁方式,如果不加此参数,当在两个系统中同时挂载此分区时就会像
EXT3 格式一
样,两个系统的信息不能同步
-t
koen_007 DLM 锁所在的表名字,就是你的集群的名字gfs
分区的卷标
-j
GFS 分区中最多支持多少个节点同时挂载,这个可以在使用中动态调整
,通常设定值为节点数+1
mount
-t gfs /dev/koenvg/koenlv /var/www/html (自动挂载可以写入/etc/fstab,
或添加为集群资源,由集群加载)
其他集群节点相同操作,只是不要执行格式化
访问https://desktop36.example.com:8084
选择Service Groups
将集群服务先关闭(Disable)
选择Resources
选择add
按如下图配置
选择Service Groups
选择Add
Resouce添加刚才所设置的GFS2并点击Submit
将集群服务启动.
测试:集群服务启动后,当服务在哪个节点上运行时,GFS2设备就挂载在哪个节点的/var/www/html目录下.
附:当集群服务出现故障,无法启动(可用clusvcadm
-d apache模拟),gfs2文件系统无法挂载时,如何恢复gfs2文件系统中的数据
以下步骤在任意一个节点上实施:
[[email protected]
~]# dd if=/dev/koenvg/koenlv of=gfs2.img
[[email protected]
~]# yum install gfs2-utils.x86_64 -y
[[email protected]
~]# mount -o loop,lockproto=lock_nolock gfs2.img /mnt/
这样即可查看gfs2文件系统中的数据并对其进行备份
注:建议将dd截得的块(即此处的gfs2.img)scp到非集群节点上进行挂载.
附:gfs2的拉伸
以下步骤在任意一个节点上实施:
[[email protected]
~]# lvextend -L +1000M /dev/koenvg/koenlv
[[email protected]
~]# gfs2_grow /dev/koenvg/koenlv
附:当要添加节点到集群中时,如何给gfs2文件系统添加日志数目.
以下步骤在当前gfs2文件系统所挂节点上实施:
[[email protected]
~]# gfs2_jadd
-j 2 /dev/koenvg/koenlv
Filesystem:
/var/www/html
Old
Journals 3
New
Journals 5
注:出现类似如上输出说明添加成功.
[[email protected]
~]# gfs2_tool journals /dev/koenvg/koenlv
(可通过此条命令查看日志数,日志数有几个,说明可以有几个节点同时挂载此gfs2文件系统)
附:如何将此集群服务彻底关闭
访问https://desktop36.example.com:8084
选择Service
Groups
将集群服务先关闭(Disable)
选择Nodes
将所有节点选中,点击Leave
Cluster
以下步骤在server19和server25上实施:
[[email protected]
~]# /etc/init.d/cman stop
[[email protected]
~]# chkconfig cman off
[[email protected]
~]# /etc/init.d/rgmanager stop
[[email protected]
~]# chkconfig rgmanager off
[[email protected]
~]# /etc/init.d/modclusterd stop
[[email protected]
~]# chkconfig modclusterd off
[[email protected]
~]# /etc/init.d/ricci stop
[[email protected]
~]# chkconfig ricci off
[[email protected]
~]# /etc/init.d/iscsi stop
[[email protected]
~]# chkconfig iscsi off
[[email protected]
~]# /etc/init.d/iscsid stop
[[email protected]
~]# chkconfig iscsid off
以下步骤在desktop36上实施:
[[email protected]
~]# /etc/init.d/fence_virtd stop
[[email protected]
~]# chkconfig fence_virtd off
[[email protected]
~]# /etc/init.d/luci stop
[[email protected]
~]# chkconfig luci off