iSCSI+OCFS2构建企业廉价共享存储方案推荐

——————————————-

一、前言

二、环境

三、配置

1.target配置

2.node1配置

3.node2配置

四、测试

五、附:

1.iscsiadm用法

2.o2cb_ctl用法

——————————————-

一、前言

1、简介

iSCSI介绍请参看另一篇博客《关于iSCSI的一些介绍》。

OCFS2是下一代的ORACLE集群文件系统,它已经被设计成为一种为通用的文件系统。OCFS2能使运行在集群中所有节点并发的通过标准文件系统接口来访问存储备。

2、下载

OCFS2的发行版包括了2个安装包,一个称为核心模块,另一个叫工具包。

核心模块链接下载:

http://oss.oracle.com/projects/ocfs2/files/

工具包链接下载:

http://oss.oracle.com/projects/ocfs2-tools/files/

首先要下载相应的软件包,对于核心模块,下载时要考虑它的发行号,适用的平台,操作系统内核版本以及内核的类型(比如SMP,HUGEMEM,PSMP等),对于工具包,只要符合发行版本和平台就可以了。工具包又分为两部分,ocfs2-tools命令行工具,ocfs2console图形工具,用户可以选择不安装这部分,但它的确可以令操作简单化。

3、安装(每个节点都安装)

以RedHat安装为例:

操作系统:Red Hat Enterprise Linux Server release 5.4

操作系统内核版本:2.6.18-164.el5

OCFS2核心模块安装包:

ocfs2-2.6.18-164.el5-1.4.7-1.el5.i686.rpm

OCFS2工具安装包:

ocfs2-tools-1.4.4-1.el5.i386.rpm

ocfs2console-1.4.4-1.el5.i386.rpm

二、环境

1.系统:RedHat5.4 32位

2.拓扑图

3.地址规划

target

eth1 192.168.3.100/24

node1

eth1 192.168.2.10/24

eth2 192.168.3.10/24

node2

eth1 192.168.2.20/24

eth2 192.168.3.20/24

三、配置

1.target端配置

1-1.添加一块硬盘(用于node1和node2的共享磁盘)

#fdisk/dev/sdc//先分区,不要格式化及挂载。Command(mforhelp):nCommandactioneextendedpprimarypartition(1-4)Partitionnumber(1-4):1Firstcylinder(1-261,default1):Usingdefaultvalue1Lastcylinderor+sizeor+sizeMor+sizeK(1-261,default261):Usingdefaultvalue261Command(mforhelp):wThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.#fdisk-l//查看分区DeviceBootStartEndBlocksIdSystem/dev/sdc11261209645183Linux

1-2.安装scsi-target

#mkdir/media/rhel///创建光盘挂载点#mount/dev/cdrom/media/rhel/#cd/media/rhel/ClusterStorage/#rpm-ivhperl-Config-General-2.40-1.el5.noarch.rpm//依赖包#rpm-ivhscsi-target-utils-0.0-5.20080917snap.el5.i386.rpm//安装scsi-target,作为发起者#servicetgtdstartStartingSCSItargetdaemon:[OK]创建一个新的target:#tgtadm--lldiscsi--opnew--modetarget--tid1--targetnameiqn.2014-03.com.a.target:disk用刚创建的分区/dev/sdc1创建为LUN,号码为1:#tgtadm--lldiscsi--opnew--modelogicalunit--tid1--lun1--backing-store/dev/sdc1开放给192.168.3.0/24网络中的所有主机访问:#tgtadm--lldiscsi--opbind--modetarget--tid1--initiator-address192.168.3.0/24显示所有创建的target:#tgtadm--lldiscsi--opshow--modetargetTarget1:iqn.2014-03.com.a.target:diskSysteminformation:Driver:iscsiState:readyI_Tnexusinformation:LUNinformation:LUN:0Type:controllerSCSIID:deadbeaf1:0SCSISN:beaf10Size:0MBOnline:YesRemovablemedia:NoBackingstore:NobackingstoreLUN:1Type:diskSCSIID:deadbeaf1:1SCSISN:beaf11Size:2147MBOnline:YesRemovablemedia:NoBackingstore:/dev/sdc1Accountinformation:ACLinformation:192.168.3.0/24显示target的详细信息:#tgtadm--lldiscsi--opshow--modetarget--tid1#vim/etc/tgt/targets.conf//查看配置文档6 targetiqn.2014-03.com.a.target:disk 7#ListoffilestoexportasLUNs8backing-store/dev/sdc1910#Authentication:11#ifno"incominguser"isspecified,itisnotused12#incominguserbackupsecretpass121314#Accesscontrol:15#defaultstoALLifno"initiator-address"isspecified16initiator-address192.168.3.0/2417 /target 

2.node1配置

2-1.修改主机名

#vim/etc/sysconfig/networkHOSTNAME=node1.a.com#hostnamenode1.a.com#vim/etc/hosts//相互通信192.168.2.10node1.a.comnode1192.168.2.20node2.a.comnode2

2-2.安装iscsi-initiator

#cd/media/rhel/Server///挂载光盘#rpm-ivhiscsi-initiator-utils-6.2.0.871-0.10.el5.i386.rpm#vim/etc/iscsi/initiatorname.iscsiInitiatorName=iqn.2014-03.com.a.node1#serviceiscsistartiscsidisstoppedTurningoffnetworkshutdown.StartingiSCSIdaemon:[OK][OK]SettingupiSCSItargets:iscsiadm:Norecordsfound![OK]

2-3.连接target服务器端

#iscsiadm--modediscovery--typesendtargets--portal192.168.3.100192.168.3.100:3260,1iqn.2014-03.com.a.target:disk#maniscsiadm//查看命令的使用#iscsiadm--modenode--targetnameiqn.2014-03.com.a.target:disk--portal192.168.3.100:3260--login//登陆,如登陆失败可以使用--logout登出再登陆。#fdisk-lDeviceBootStartEndBlocksIdSystem/dev/sda1*138305203+83Linux/dev/sda239914703647083Linux/dev/sda39151044104422582Linuxswap/SolarisDisk/dev/sdb:2146MB,2146765824bytes67heads,62sectors/track,1009cylindersUnits=cylindersof4154*512=2126848bytesDisk/dev/sdbdoesn'tcontainavalidpartitiontable

2-4.安装ocfs2相关包

-rw-r--r--1rootroot324174Mar1520:49ocfs2-2.6.18-164.el5-1.4.7-1.el5.i686.rpm-rw-r--r--1rootroot338927Mar1520:49ocfs2console-1.4.4-1.el5.i386.rpm-rw-r--r--1rootroot1559206Mar1520:56ocfs2-tools-1.4.4-1.el5.i386.rpm#rpm-ivh*.rpm#scp*.rpmnode2:/root///复制ocfs2相关包到节点2上。#o2cb_ctl-C-nocfs2-tcluster-i#serviceo2cbenableWritingO2CBconfiguration:OKLoadingfilesystem"configfs":OKMountingconfigfsfilesystemat/sys/kernel/config:OKLoadingfilesystem"ocfs2_dlmfs":OKCreatingdirectory'/dlm':OKMountingocfs2_dlmfsfilesystemat/dlm:OKCheckingO2CBclusterconfiguration:Failed//一个错误,缺少配置文档,下面开始配置。#o2cb_ctl-C-nocfs2-tcluster-i//创建ocfs2集群文件夹Clusterocfs2created#cd/etc/ocfs2/#ll-rw-r--r--1rootroot40Mar1520:59cluster.conf#vimcluster.conf//仅查看,不写入任何东西将node1的配置写入配置文档中。#o2cb_ctl-C-nnode1.a.com-tnode-anumber=0-aip_address=192.168.2.10-aip_port=7777-acluster=ocfs2将node2的配置写入配置文档中。#o2cb_ctl-C-nnode2.a.com-tnode-anumber=1-aip_address=192.168.2.20-aip_port=7777-acluster=ocfs2#vimcluster.conf//再次查看#serviceo2cbrestartStoppingO2CBclusterocfs2:OKUnmountingocfs2_dlmfsfilesystem:OKUnloadingmodule"ocfs2_dlmfs":OKUnmountingconfigfsfilesystem:OKUnloadingmodule"configfs":OKLoadingfilesystem"configfs":OKMountingconfigfsfilesystemat/sys/kernel/config:OKLoadingfilesystem"ocfs2_dlmfs":OKMountingocfs2_dlmfsfilesystemat/dlm:OKStartingO2CBclusterocfs2:OK

2-5.挂载服务器端存储

#fdisk/dev/sdbDevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabelBuildinganewDOSdisklabel.Changeswillremaininmemoryonly,untilyoudecidetowritethem.Afterthat,ofcourse,thepreviouscontentwon'tberecoverable.Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)Command(mforhelp):nCommandactioneextendedpprimarypartition(1-4)Partitionnumber(1-4):1Firstcylinder(1-1009,default1):Usingdefaultvalue1Lastcylinderor+sizeor+sizeMor+sizeK(1-1009,default1009):Usingdefaultvalue1009Command(mforhelp):wThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.#fdisk-lDeviceBootStartEndBlocksIdSystem/dev/sda1*138305203+83Linux/dev/sda239914703647083Linux/dev/sda39151044104422582Linuxswap/SolarisDeviceBootStartEndBlocksIdSystem/dev/sdb111009209566283Linux#mkfs-tocfs2-N2/dev/sdb1//格式化#mkdir/mnt/1//创建挂载点#mount/dev/sdb1/mnt/1//挂载#mount/dev/sdb1on/mnt/1typeocfs2(rw,_netdev,heartbeat=local)

3.node2配置

#hostnamenode2.a.com#vim/etc/sysconfig/networkHOSTNAME=node2.a.com#hostnamenode2.a.com#vim/etc/hosts192.168.2.10node1.a.comnode1192.168.2.20node2.a.comnode2#ll-rw-r--r--1rootroot324174Mar1520:57ocfs2-2.6.18-164.el5-1.4.7-1.el5.i686.rpm-rw-r--r--1rootroot338927Mar1520:57ocfs2console-1.4.4-1.el5.i386.rpm-rw-r--r--1rootroot1559206Mar1520:57ocfs2-tools-1.4.4-1.el5.i386.rpm#rpm-ivh*.rpm#serviceo2cbenable#o2cb_ctl-C-nocfs2-tcluster-iClusterocfs2created#o2cb_ctl-C-nnode1.a.com-tnode-anumber=0-aip_address=192.168.2.10-aip_port=7777-acluster=ocfs2#o2cb_ctl-C-nnode2.a.com-tnode-anumber=1-aip_address=192.168.2.20-aip_port=7777-acluster=ocfs2#cd/etc/ocfs2/#ll-rw-r--r--1rootroot238Mar1521:06cluster.conf#vimcluster.conf#serviceo2cbrestart#serviceo2cbstatus#cd/media/rhel/Server/#rpm-ivhiscsi-initiator-utils-6.2.0.871-0.10.el5.i386.rpm#vim/etc/iscsi/initiatorname.iscsiInitiatorName=iqn.2014-03.com.a.node2#serviceiscsistart#iscsiadm--modediscovery--typesendtargets--portal192.168.3.100192.168.3.100:3260,1iqn.2014-03.com.a.target:disk#iscsiadm--modenode--targetnameiqn.2014-03.com.a.target:disk--portal192.168.3.100:3260--login#fdisk-lDeviceBootStartEndBlocksIdSystem/dev/sdb111009209566283Linux#mkdir/mnt/1//node1中已格式化,直接挂载即可。#mount/dev/sdb1/mnt/1#mount/dev/sdb1on/mnt/1typeocfs2(rw,_netdev,heartbeat=local)PS:如无法挂载,重新退出并登录再挂载(如下)#iscsiadm--modenode--targetnameiqn.2014-03.com.a.target:disk--portal192.168.3.100:3260--logout#iscsiadm--modenode--targetnameiqn.2014-03.com.a.target:disk--portal192.168.3.100:3260--login

四、测试

4-1.node2测试

#cd/mnt/1#touchf1//新建f1文本文件#ll-rw-r--r--1rootroot0Mar1521:28f1drwxr-xr-x2rootroot3896Mar1521:11lost+found#vimf1//编辑f1,保持编辑状态,不退出

4-2.node1测试

#cd/mnt/1#ll//f1已同步-rw-r--r--1rootroot0Mar1521:28f1drwxr-xr-x2rootroot3896Mar1521:11lost+found#vimf1//无法编辑,已被锁住,因为node2正在编辑。

现在两个客户端就共享使用了iscsi设备,并且可以同时往挂载的分区中写入数据了,可以实现实时同步!

五、附:

1.iscsiadm命令使用方法:

iscsiadm -m discovery [ -d debug_level ] [ -P printlevel ] [ -t type -p ip:port [ -l ] ]

-d –debug=debug_level 显示debug信息,级别为0-8;

-l –login 登录

-t –type=type 这里可以使用的类型为sendtargets, fw, 和 iSNS

-p –portal=ip[:port] 指定target服务的IP和端口

-m –mode op 可用的mode有discovery,node,fw,host iface和session

-T –targetname=targetname 用于指定要访问的target的名字

-u –logout 登出

2.o2cb_ctl命令使用方法:

o2cb_ctl -C -n object -t类型(-i)[-a attribute ]

OPTIONS:

-C Create an object in the OCFS2 Cluster Configuration.

-D Delete an object from the existing OCFS2 Cluster Configuration.

-I Print information about the OCFS2 Cluster Configuration.

-H Change an object or objects in the existing OCFS2 Cluster Configuration.

-h Displays help and exit.

-V Print version and exit.

OTHER OPTIONS:

-a attribute

With -C, attribute is in format “parameter=value”, where the parameter is a valid parameter that can be set in the file /etc/ocfs2/cluster.conf. With -I, attribute may be “parameter”, indicating an attribute to be listed in the output, or it may be “parameter==value”, indicating that only objects matching “parameter=value” are to be displayed.

-i

Valid only with -C. When creating something (node or cluster), it will also install it in the live cluster. If the parameter is not specified, then only update the /etc/ocfs2/cluster.conf.

-n object

object is usually the node name or cluster name. In the /etc/ocfs2/cluster.conf file, it would be the value of the name parameter for any of the sections (cluster or node).

-o

Valid only with -I. Using this parameter, if one asks o2cb_ctl to list all nodes, it will output it in a format suitable for shell parsing.

-t type

type can be cluster, node or heartbeat.

-u

Valid only with -D. When deleting something (node or cluster), it will also remove it from the live cluster. If the parameter is not specified, then only update the /etc/ocfs2/cluster.conf.

-z

Valid only with -I. This is the default. If one asks o2cb_ctl to list all nodes, it will give a verbose listing.

EXAMPLES

Add node5 to an offline cluster:

$ o2cb_ctl -C -n node5 -t node -a number=5 -a ip_address=192.168.0.5 -a ip_port=7777 -a cluster=mycluster

Add node10 to an online cluster:

$ o2cb_ctl -C -i -n node10 -t node -a number=10 -a ip_address=192.168.1.10 -a ip_port=7777 -a cluster=mycluster

Note the -i argument.

Query the IP address of node5:

$ o2cb_ctl -I -n node5 -a ip_address

Change the IP address of node5:

$ o2cb_ctl -H -n node5 -a ip_address=192.168.1.5

就会犯错误,就会有无数次让自己跌倒的机会出现,

iSCSI+OCFS2构建企业廉价共享存储方案推荐

相关文章:

你感兴趣的文章:

标签云: