Linux ·

基于CentOS6.7下的RHCS共享存储集群搭建

一、测试虚机说明:

 

主机名

IP地址

系统

备注

共享存储

storage

192.168.1.120

CentOS6.7

IP地址为static,本地YUM源已经配好,新增了一个磁盘/dev/sdb作为共享存储。

节点1

node11

192.168.1.123

centOS6.7

IP地址为static,本地YUM源已经配好

节点2

node22

192.168.1.124

centOS6.7

IP地址为static,本地YUM源已经配好

本地yum源配置请参考如下链接:

RHEL7 本地yum源配置 http://www.linuxidc.com/Linux/2017-01/139140.htm

CentOS 6配置本地Yum源(http方式) http://www.linuxidc.com/Linux/2017-02/140204.htm

CentOS 7 使用阿里云的yum源、PIP源 http://www.linuxidc.com/Linux/2017-01/13966.htm

CentOS 7更改yum源与更新系统 http://www.linuxidc.com/Linux/2017-01/140067.htm

RedHat7.0配置本地yum源  http://www.linuxidc.com/Linux/2017-01/139148.htm 

二、准备工作:

1. 在三台虚机上配置各节点的名称

[root@storage /]# vi /etc/hosts

[root@storage /]# cat /etc/hosts

127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4

::1        localhost localhost.localdomain localhost6 localhost6.localdomain6

 

192.168.1.120 storage

192.168.1.123 node11

192.168.1.124 node22

 

2. 三台虚机都关闭防火墙和selinux

[root@storage /]# service iptables stop

[root@storage /]# chkconfig iptables off

将SELINUX属性值改成disabled:

[root@storage /]# vi /etc/selinux/config

 

3. 三台虚机禁用NetworkManager,要不然后面cman启动会有问题

[root@storage /]# service NetworkManager stop

[root@storage /]# chkconfig NetworkManager off

 

4. 设置三台虚机(主要是两个节点机)的开机启动时的网卡配置,保证网络是在cman等服务启动之前就有效

[root@storage rc.d]# vi rc.net

将网卡配置内容写成一个脚本,这里我们取名rc.net,rc.net内容如下:

[root@storage rc.d]# cat rc.net

#!/bin/bash

 

ifconfig eth0 down

ifconfig eth0 192.168.1.120

ifconfig eth0 netmask 255.255.255.0

ifconfig eth0 up

route add -net 0.0.0.0 gw 192.168.1.1

记得一定要赋予权限:

[root@storage rc.d]# chmod a+x rc.net

将该脚本文件链接到rc5.d中,并且保证启动时优先于等会要安装的cman、cmanager等服务:

[root@storage rc5.d]# ln -s /etc/rc.d/rc.net S10rcnet

 

三、 共享存储虚机上安装并配置target

1. 安装target

[root@storage /]# yum install -y scsi-target-utils

2. 配置target

方法一:修改/etc/tgt/targets.conf配置文件。

方法二:执行操作命令,这里我们采取的是方法二。

配置target名称:

tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2015-11-05:storage

配置共享磁盘:

tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb

配置允许的网段:

tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.0/24

配置认证的用户名和密码:

tgtadm --lld iscsi --op new --mode account --user wgtx --password 1158

tgtadm --lld iscsi --op bind --mode account --tid 1 --user wgtx

最后还要记得把这些命令写在rc.local里,保证开机生效。

3. 启动target并设置为开机自启动

[root@storage /]# service tgtd start

[root@storage /]# chkconfig tgtd on

4.最后我们可以查看下配置的target

[root@storage /]# tgtadm --lld iscsi --mode target --op show

将会显示如下信息:

Target 1: iqn.2015-11-05:storage

    System information:

        Driver: iscsi

        State: ready

    I_T nexus information:

        I_T nexus: 9

            Initiator: iqn.2015-11.com.redhat:node22

            Connection: 0

                IP Address: 192.168.1.124

        I_T nexus: 11

            Initiator: iqn.2015-11.com.redhat:node11

            Connection: 0

                IP Address: 192.168.1.123

    LUN information:

        LUN: 0

            Type: controller

            SCSI ID: IET    00010000

            SCSI SN: beaf10

            Size: 0 MB, Block size: 1

            Online: Yes

            Removable media: No

            Prevent removal: No

            Readonly: No

            Backing store type: null

            Backing store path: None

            Backing store flags:

        LUN: 1

            Type: disk

            SCSI ID: IET    00010001

            SCSI SN: beaf11

            Size: 10737 MB, Block size: 512

            Online: Yes

            Removable media: No

            Prevent removal: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb

            Backing store flags:

    Account information:

        wgtx

    ACL information:

        192.168.1.0/24

 

四、在两个节点上安装initiator

1. 安装initiator

[root@node11 /]# yum install –y iscsi-initiator-utils

2. 配置initiator

[root@node11 /]# vi /etc/iscsi/initiatorname.iscsi

我的配置内容如下:

InitiatorName=iqn.2015-11.com.redhat:node11

接着修改iscsid.conf 配置文件:

[root@node11 /]# vi /etc/iscsi/iscsid.conf

主要是修改下面三项内容,把前面屏蔽取消,并修改好我们前面设置的访问target的用户名和密码:

# To enable CHAP authentication set node.session.auth.authmethod

# to CHAP. The default is None.

node.session.auth.authmethod = CHAP

 

# To set a CHAP username and password for initiator

# authentication by the target(s), uncomment the following lines:

node.session.auth.username = wgtx

node.session.auth.password = 1158

3. 在节点上发现一下target

[root@node11 /]# iscsiadm -m discovery -t st -p 192.168.1.120:3260

显示如下信息:

192.168.1.120:3260,1 iqn.2015-11-05:storage

这里iscsi会自己启动起来。

4. 各节点登录一下target并查看一下磁盘

[root@node11 /]# iscsiadm -m node -T iqn.2015-11-05:storage -p 192.168.1.120 –l

登录成功会显示successful的信息。

[root@node11 /]# fdisk -l

我们现在就可以看到多出来了一块磁盘:

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0006265d

 

  Device Boot      Start        End      Blocks  Id  System

/dev/sda1  *          1          64      512000  83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        130      524288  82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3            130        2611    19934208  83  Linux

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

5.别忘了设置iscsi开机自启

[root@node11 /]# chkconfig iscsi on

 

五、配置集群

1. 在storage上安装并启用luci集群管理

[root@storage /]# yum install –y luci

[root@storage /]# chkconfig luci on

[root@storage /]# service luci start

启动luci后,会显示一个地址,我们这里是https://storage:8084/,通过浏览器对其访问,注意,登录的用户名是root,密码就是系统root的密码。

2. 两台节点上分别安装ricci、rgmanager、cman

[root@storage /]# yum install ricci rgmanager cman –y

[root@storage /]# chkconfig ricci on

[root@storage /]# chkconfig rgmanager on

[root@storage /]# chkconfig cman on

[root@storage /]# service ricci start

[root@storage /]# service rgmanager start

[root@storage /]# service cman start

启动cman如出现错误:

Starting cman... xmlconfig cannot find /etc/cluster/cluster.conf [FAILED]

这是因为节点还没有加入集群,没有产生配置文件/etc/cluster/cluster.conf,

我们也可以现在不启动cman,节点成功加入集群后,cman可以自动起起来。

下一步设置两台节点的ricci用户密码,我们设置与root相同的密码:

[root@storage /]# passwd ricci

3. 在storage上通过luci管理界面进行集群配置

1)点击Manager Clusters---> Create 创建一个集群

按输入框要求,输入集群名称,添加每个节点的主机名、密码,Ricci Hostname和RicciPort都默认, 勾选Use Locally Installed Packages,我好像Reboot Nodes Before Joining Cluster、Enable Shared Storage Support都没有勾选,后来又参考了下文档,大家还是把Enable Shared Storage Support勾选上吧,最后点击Create Cluster创建集群。

2)在各节点上查看下集群情况

[root@node11 /]# clustat

可以看到各节点状态都是online,说明配置成功。

 

六、创建GFS2集群文件系统

1. 在两个节点上分别安装lvm2-cluster、gfs2-utils

[root@node11 /]# yum install –y lvm2-cluster gfs2-utils

[root@node11 /]# chkconfig clvmd on

启动集群:

[root@node11 /]# lvmconf –enable-cluster

重新加载集群:

[root@node11 /]# service clvmd restart

2. 在节点上创建LVM卷

[root@node11 /]# pvcreate /dev/sdb

[root@node11 /]# vgcreate vg1 /dev/sdb

[root@node11 /]# lvcreate –l 100%FREE –n lv1 vg1

创建好LVM卷后,我们可以通过下面命令查看下lv状态:

[root@node11 /]# lvdisplay

另一个节点上执行下lvmconf –enable-cluster命令,查看lvdisplay,也可以看到相应的信息,不需要另外去create LVM。

3. 格式化成gfs2文件系统

在其中的一个节点执行:

[root@node11 /]# mkfs.gfs2 -p lock_dlm -t myclusterCH:clusterdata -j 3 /dev/vg1/lv1

-p:定义为 DLM锁方式,如果不加此参数,挂载的分区就像ext4格式,信息不能同步。

-t:集群名和自定义文件系统标志名,也可以是共享卷名

-j:GFS分区中最多支持多少个节点同时挂载,通常设定值为节点数+1

4. 在两个节点上分别挂载

[root@node11 /]# mkdir /mnt/clusterdata

[root@node11 /]# mount –t gfs2 /dev/vg1/lv1 /mnt/clusterdata

这样我们在两个节点里的clusterdata里进行文件新增修改,都会同步了。

5. 设置两节点开机自动登录target

[root@node11 rc.d]# vi rc.loginsdb

将登录target内容写成一个脚本,这里我们取名rc.loginsdb,rc.loginsdb内容如下:

[root@node11 rc.d]# cat rc.loginsdb

#!/bin/bash

 

iscsiadm -m node -T iqn.2015-11-05:storage -p 192.168.1.120 -l

记得一定要赋予权限:

[root@node11 rc.d]# chmod a+x rc.loginsdb

将该脚本文件链接到rc.loginsdb中,并且保证启动时优先于等会要安装的cman、cmanager等服务:

[root@node11 rc.d]# ln -s /etc/rc.d/rc.loginsdb S14loginsdb

6. 最后,记得设置一下两节点开机自动挂载

在rc.local里添加上:

mount –t gfs2 /dev/vg1/lv1 /mnt/clusterdata

参与评论