LB+HA+ISCSI 集群系统项目实践
实验目的:深入理解集群原理,熟练使用开源软件假设集群项目
实验环境:Red Hat Enterprise Linux Server release 5.4
实验说明:该实验已经假定您熟悉LB和HA两种集群架构,并可以熟练架设,该实验加上了集群存储,形成了一个完整的集群环境,在做LB的时候采用LVS DR 方式,因为在实际工作中,DR方式用的比较多,在上两个实验中已经比较了DR和NAT方式的区别。
实验内容:
系统架构图例:
一、 设置LB集群(LVS DR方式,请参考:LVS(Linux Virtual Server)集群项目实践)
二、设置HA集群(请参考:HA 高可用集群项目实践)
注意:如果根据我的实验假设了上面两个集群环境,请修改环境为下面的环境
三、一些环境的设置
(一)设置每个集群成员的主机名
(二)修改hosts文件,解析IP地址和主机名
[root@node1 ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.0.12 node1.unixhot.com node1
192.168.0.200 node2.unixhot.com node2
192.168.0.201 real01.unixhot.com real01
192.168.0.202 real02.unixhot.com real01
192.168.0.129 node3.unixhot.com node3
[root@node1 ~]# scp /etc/hosts 192.168.0.200:/etc/hosts
[root@node1 ~]# scp /etc/hosts 192.168.0.201:/etc/hosts
[root@node1 ~]# scp /etc/hosts 192.168.0.202:/etc/hosts
[root@node1 ~]# scp /etc/hosts 192.168.0.129:/etc/hosts
三、ISCSI 的集群存储解决方案
ISCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。更详细的技术文档请参考本站专发的文档([url]http://www.unixhot.com[/url])
(一)服务器端创建共享存储(node3 做共享存储服务器)
启动服务,并设置开机自动启动。
装包 cd 到clusterStorage rpm –ivh scsi-target-utils..rpm
[root@node3 cluster]# /etc/init.d/tgtd start
[root@node3 ~]# chkconfig tgtd on
2.在服务器端创建并共享存储。
[root@node3 ~]# tgtadm --lld iscsi --op new --mode target --tid 1
-T iqn.2009-04-29.com.unixhot.apache:disk1
[root@node3 ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
[root@node3 ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL //target的访问控制,-I 表示允许指定的ip ,网段,访问。ALL表示允许所有。
[root@node3 ~]# tgtadm --lld iscsi --op new --mode target --tid 2
-T iqn. 2009-04-29.com.unixhot.mysql:disk2
[root@node3 ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 2 --lun 1
-b /dev/sdb2
[root@node3 ~]# tgtadm --lld iscsi --op bind —mode target —tid 2 -I ALL
(ALL 可以替换为IP地址 或域)
3.查看target。
[root@node3 ~]# tgtadm --lld iscsi --op show --mode target
4.其它命令(在target下加入一个分区)
tgtadm —lld iscsi —op new —mode logicalunit —tid 1 —lun 2 -b /dev/sda11
(二)客户端配置(两个Real Server的配置)
[root@real01 ~]# rpm -ivh iscsi-initiator-utils-6.2.0.868-0.18.el5.i386.rpm
[root@real01 ~]# service iscsi start
[root@real01 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.129:3260 //发现target
[root@real01 ~]# service iscsi restart
[root@real01 ~]# chkconfig iscsi on
[root@real01 ~]# chkconfig iscsid on
[root@real01 ~]# fdisk -l (发现可以看到两个硬盘 /dev/sdb 和 /dev/sdc)
[root@real02 ~]# rpm -ivh iscsi-initiator-utils-6.2.0.868-0.18.el5.i386.rpm
[root@real02~]# service iscsi start
[root@real02 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.129:3260
[root@real02 ~]# service iscsi restart
[root@real02 ~]# chkconfig iscsi on
[root@real02 ~]# chkconfig iscsid on
[root@real02 ~]# fdisk -l (发现可以看到两个硬盘 /dev/sdb 和 /dev/sdc)
(三)创建分区,使用UDEV机制,区分硬盘
下面要做的就是在两个硬盘上创建分区,并创建LVM,在创建LVM之前,有一个问题要解决,就是共享存储的设备名在每个真实机上是不一样的,真实机是根据识别硬盘的顺序,用sdb和sdc来表示,也就是说共享存储的两块硬盘,在两台真实机上可能设备名是不同的。为了能够正确的创建LVM,必须使用udev机制,根据分区的特点,设置一个符号连接的设备文件,在做LVM时可以直接使用该符号连接设备,所以我们下面在分区的时候,就要有特点,可以开始和结束的磁柱不同。
[root@real01 ~]# vim /etc/udev/rules.d/10-testclass.rules
在创建LVM之前,有一个问题要解决,就是共享存储的设备名在每个真实机上是不一样的,为了能够正确的创建LVM,必须使用udev机制,根据分区的特点,设置一个符号连接的设备文件,在做LVM时可以直接使用该符号连接设备
1.给sdb分区
[root@real01 ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1017, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1017, default 1017): 1016
Command (m for help): p
Disk /dev/sdb: 4005 MB, 4005679104 bytes
124 heads, 62 sectors/track, 1017 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1016 3905473 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@real01 ~]# partprobe /dev/sdb
2.给sdc分区
[root@real01 ~]# fdisk /dev/sdc
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1023, default 1): 2
Last cylinder or +size or +sizeM or +sizeK (2-1023, default 1023):
Using default value 1023
Command (m for help): p
Disk /dev/sdc: 4581 MB, 4581480960 bytes
141 heads, 62 sectors/track, 1023 cylinders
Units = cylinders of 8742 * 512 = 4475904 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 2 1023 4467162 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@real01 ~]# partprobe /dev/sdc
3.查看分区信息[root@real01 ~]# udevinfo -a -p /sys/block/sdb/sdb1
4.查看分区信息[root@real01 ~]# udevinfo -a -p /sys/block/sdc/sdc1
5.根据上面查看的两个信息编辑规则
[root@real01 ~]# vim /etc/udev/rules.d/10-iscsi.rules
SUBSYSTEM=="block", SYSFS{size}=="7811008", SYSFS{start}=="7688", SYMLINK+="disk1"
SUBSYSTEM=="block", SYSFS{size}=="8899356", SYSFS{start}=="17484", SYMLINK+="disk2"
(根据每个人实验分区不同,请修改相应的数值)
4.启动udev服务
[root@real01 rules.d]# start_udev
5.查看udev是否产生块设备
[root@real01 ~]# ls -l /dev/disk{1,2}
lrwxrwxrwx 1 root root 4 Apr 29 10:48 /dev/disk1 -> sdb1
lrwxrwxrwx 1 root root 4 Apr 29 10:48 /dev/disk2 -> sdc1
6.把udev规则复制到real02上
[root@real01 ~]# scp /etc/udev/rules.d/10-iscsi.rules 192.168.0.122:/etc/udev/rules.d/
7.在real02上执行
[root@real02 ~]# partprobe
[root@real01 ~]# ls -l /dev/disk{1,2} (发现同样可以看到disk1和disk2,但对应的硬盘却不同,这就是我们为什么使用udev机制,但它们实际上的硬盘是相同的,只是系统识别的名称不同罢了)
lrwxrwxrwx 1 root root 4 Apr 30 21:24 /dev/disk1 -> sdc1
lrwxrwxrwx 1 root root 4 Apr 30 21:24 /dev/disk2 -> sdb1
(四)创建LVM
1.由于在集群的环境,在一台真实机创建了LVM在另一台真实机上是看不到,RedHat提供了LVM2-cluster这个工具包,解决了这个问题,但是它必须跑在cman的环境下,所以需要我们空跑一个cman。
1. 创建LVM
[root@real01 ~]# pvcreate /dev/disk{1,2}
[root@real01 ~]# vgcreate unixhotvg /dev/disk{1,2}
[root@real01 ~]# lvcreate -n unixhotlv -L 2G unixhotvg
2.用system-config-cluster创建一个集群,加入节点为两个真实机,不添加任何资源。
[root@real01 ~]# /etc/init.d/cman start
[root@real02 ~]# /etc/init.d/cman start
3.安装并启动clvmd服务
[root@real01 ~]# rpm -ivh lvm2-cluster-2.02.40-7.el5.i386.rpm
[root@real01 ~]# lvmconf --enable-cluster
[root@real01 ~]# /etc/init.d/clvmd start
[root@real02 ~]#rpm -ivh lvm2-cluste-2.02.40-7.el5.i386.rpm
[root@real02 ~]#lvmconf --enable-clvster
[root@real02 ~]# /etc/init.d/clvmd start
4.在两台真实机上测试
[root@real01 ~]# lvscan
ACTIVE '/dev/unixhotvg/unixhotlv' [2.00 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [7.03 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [864.00 MB] inherit
[root@real02 ~]# lvscan
ACTIVE '/dev/unixhotvg/unixhotlv' [2.00 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [7.03 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [864.00 MB] inherit
(五)格式化文件系统为GFS
1.安装软件包
[root@real01 ~]# rpm -ivh gfs2-utils-0.1.53-1.el5.i386.rpm在光盘的Server 目录
[root@real01 ~]# rpm -ivh gfs-utils-0.1.18-1.el5.i386.rpm 在ClusterStorage 目录
[root@real01 ~]# rpm -ivh kmod-gfs-0.1.31-3.el5.i686.rpm
[root@real02 ~]# rpm -ivh gfs2-utils-0.1.53-1.el5.i386.rpm
[root@real02 ~]# rpm -ivh gfs-utils-0.1.18-1.el5.i386.rpm
[root@real02 ~]# rpm -ivh kmod-gfs-0.1.31-3.el5.i686.rpm
2.格式化文件系统 (在任意一台真实机上格式化即可使用)
[root@real01 ~]# mkfs.gfs2 -t apache:mygfs2 -p lock_dlm -j 2 -J 32 /dev/unixhotvg/unixhotlv
命令解释:j:日志个数有几个主机挂载了就要几个日志, -J:日志大小,最小时32M, -p:锁类型, -t:指定集群内gfs标签名,apache是集群名称。
This will destroy any data on /dev/unixhotvg/unixhotlv.
Are you sure you want to proceed? [y/n] y
Device: /dev/unixhotvg/unixhotlv
Blocksize: 4096
Device Size 2.00 GB (524288 blocks)
Filesystem Size: 2.00 GB (524288 blocks)
Journals: 2
Resource Groups: 8
Locking Protocol: "lock_dlm"
Lock Table: "apache:mygfs2"
3.挂载文件系统
[root@real01 ~]# vim /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/unixhotvg/unixhotlv /var/www/html gfs2 defaults 0 0
[root@real01 ~]# mount /dev/unixhotvg/unixhotlv /var/www/html
4.测试挂载是否正常
[root@real01 html]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
none on /sys/kernel/config type configfs (rw)
/dev/mapper/unixhotvg-unixhotlv on /var/www/html type gfs2 (rw,hostdata=jid=0:id=196609:first=1)
5.real02上设置挂载。注意:在挂载前将测试用的index.html和test.html先移动到其它目录,挂载好再移动回来。
GOOD LUCK!
6.附加命令GFS2文件系统的扩展
在线扩展日志和空间
[root@real01 ~]#lvextend -L +5G /dev/vgtest/lvtest (先扩展LV)
[root@real01 ~]#gfs2_grow -j 2 /var/ww/html 挂载目录的路径 (扩展日志)
[root@real01 ~]#gfs2_grow /var/www/html (在线扩展大小)