iSCSI分为提供存储设备的服务端和使用存储的客户端
iSCSI target:存储设备服务端,存放磁盘或RAID的设备。目的在于提供给其他主机使用
iSCSI initiator:使用target存储服务的客户端
SAN和NAS
一、存储服务端上安装配置iSCSI target
1、在存储服务器上安装scsi-target-utils软件(rhel7为targetcli)
[root@node1~]#yuminstallscsi-target-utils
2、启动iscsi服务
[root@node1~]#/etc/init.d/tgtdstart [root@node1~]#chkconfigtgtdon #监听端口为3260 [root@node1~]#netstat-tuanlp|greptgtd tcp000.0.0.0:32600.0.0.0:*LISTEN1248/tgtd tcp00:::3260:::*LISTEN1248/tgtd
3、scsi-target-utils的相关配置文件
#/etc/tgt/targets.conf主配置文件,设置要共享的磁盘格式与块设备等 #/usr/sbin/tgt-admin查询、删除target等功能的设置工具 #/usr/sbin/tgt-setup-lun建立target以及设置共享的磁盘与可使用的客户端等的程序 #/usr/sbin/tgtadmiscsitarget管理程序(可使用配置文件取代) #/usr/sbin/tgtd提供iSCSItarget服务的主程序 #/usr/sbin/tgtimg搭建共享镜像文件设备程序
4、建立分区配置iSCSI存储设备
================================================================== #创建一个容量为1G的普通分区 [root@node1~]#fdisk/dev/sdb Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) p Partitionnumber(1-4):1 Firstcylinder(1-652,default1): Usingdefaultvalue1 Lastcylinder,+cylindersor+size{K,M,G}(1-652,default652):+1G Command(mforhelp):p Disk/dev/sdb:5368MB,5368709120bytes 255heads,63sectors/track,652cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x85d4a809 DeviceBootStartEndBlocksIdSystem /dev/sdb111321060258+83Linux Command(mforhelp):w Thepartitiontablehasbeenaltered! Callingioctl()tore-readpartitiontable. Syncingdisks. [root@node1~]#ll/dev/sdb* brw-rw----1rootdisk8,16Sep100:23/dev/sdb brw-rw----1rootdisk8,17Sep100:23/dev/sdb1 ================================================================== #创建一个容量为1GLVM分区 Command(mforhelp):n Commandaction eextended pprimarypartition(1-4) p Partitionnumber(1-4):2 Firstcylinder(133-652,default133): Usingdefaultvalue133 Lastcylinder,G}(133-652,default652):+1G Command(mforhelp):t Partitionnumber(1-4):2 Hexcode(typeLtolistcodes):8e Changedsystemtypeofpartition2to8e(LinuxLVM) Command(mforhelp):p Disk/dev/sdb:5368MB,652cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x85d4a809 DeviceBootStartEndBlocksIdSystem /dev/sdb111321060258+83Linux /dev/sdb213326410602908eLinuxLVM [root@node1~]#ll/dev/sdb sdbsdb1sdb2 [root@node1~]#ll/dev/sdb* brw-rw----1rootdisk8,16Sep100:27/dev/sdb brw-rw----1rootdisk8,17Sep100:27/dev/sdb1 brw-rw----1rootdisk8,18Sep100:27/dev/sdb2 [root@node1~]#pvcreate/dev/sdb2 Physicalvolume"/dev/sdb2"successfullycreated [root@node1~]#vgcreate-s8MVolGroup00/dev/sdb2 Volumegroup"VolGroup00"successfullycreated [root@node1~]#lvcreate-L800M-niscsi00VolGroup00 Logicalvolume"iscsi00"created [root@node1~]#lvscan ACTIVE'/dev/VolGroup00/iscsi00'[800.00MiB]inherit ACTIVE'/dev/VolGroup/lv_root'[8.57GiB]inherit ACTIVE'/dev/VolGroup/lv_swap'[960.00MiB]inherit [root@node1~]#lvdisplay ---Logicalvolume--- LVPath/dev/VolGroup00/iscsi00 LVNameiscsi00 VGNameVolGroup00 LVUUID2G9zLo-kWmj-ydMH-luer-wM0i-4bdl-UJwJov LVWriteAccessread/write LVCreationhost,timenode1,2016-09-0100:31:14+0800 LVStatusavailable #open0 LVSize800.00MiB CurrentLE100 Segments1 Allocationinherit Readaheadsectorsauto -currentlysetto256 Blockdevice253:2
5、共享iSCSI target文件名
iqn.YYYY-mm.<域名的反转写法>:共享名 如:iqn.2015-06.org.haungming:viscsidisk
6、配置/etc/tgt/targets.conf,设置共享存储设备的路径相关属性
#SampletargetwithoneLUNonly.Defaultstoallowaccessforallinitiators: #<targetiqn.2008-09.com.example:server.target1> #backing-store/dev/LVM/somedevice #</target> <targetiqn.2016-09.org.huangming:viscsidisk> backing-store/dev/sdb1 backing-store/dev/VolGroup00/iscsi00 initiator-address10.0.0.12 initiator-address10.0.0.0/24 incominguserviscsiuserviscsipasswd write-cacheoff </target> #backing-store:虚拟的设备 #initiator-address:允许使用的客户端 #incominguser:配置通过用户和密码访问 #write-cache:不使用缓存,直接访问存储设备
7、重启tgtd服务
[root@node1~]#/etc/init.d/tgtdrestart StoppingSCSItargetdaemon:[OK] StartingSCSItargetdaemon:[OK]
8、查看iscsi target共享存储的相关信息,使用tgt-admin --show命令
[root@node1~]#tgt-admin--show Target1:iqn.2016-09.org.huangming:viscsidisk Systeminformation: Driver:iscsi State:ready I_Tnexusinformation: LUNinformation: LUN:0 Type:controller SCSIID:IET00010000 SCSISN:beaf10 Size:0MB,Blocksize:1 Online:Yes Removablemedia:No Preventremoval:No Readonly:No Backingstoretype:null Backingstorepath:None Backingstoreflags: LUN:1 Type:disk SCSIID:IET00010001 SCSISN:beaf11 Size:839MB,Blocksize:512 Online:Yes Removablemedia:No Preventremoval:No Readonly:No Backingstoretype:rdwr Backingstorepath:/dev/VolGroup00/iscsi00 Backingstoreflags: LUN:2 Type:disk SCSIID:IET00010002 SCSISN:beaf12 Size:1086MB,Blocksize:512 Online:Yes Removablemedia:No Preventremoval:No Readonly:No Backingstoretype:rdwr Backingstorepath:/dev/sdb1 Backingstoreflags: Accountinformation: viscsiuser ACLinformation: 10.0.0.12/24
9、防火墙设置
[root@node1~]#iptables-AINPUT-ptcp-s10.0.0.12/24--dport3260-jACCEPT
二、客户端iSCSI initiator的配置
1、安装iscsi-initiator-utils
[root@node1~]#yuminstalliscsi-initiator-utils
2、iscsi-initiator-utils的主要配置文件
#/etc/iscsi/iscsi.conf主要配置文件,用来连接到iscsitarget的设置 #/sbin/iscsid启动iSCSIinitiator的主要服务程序 #/sbin/iscsiadm用来管理iSCSIinitiator的主要设置程序 #/etc/init.d/iscsid让本机模拟成为iSCSIinitiator的主要服务 #/etc/init.d/iscsiiscsi启动脚本
3、配置iscsi initiator,修改/etc/iscsi/iscsid.conf文件
#去掉注释,并设置iscsitarget提供的验证用户和密码 node.session.auth.username=viscsiuser node.session.auth.password=viscsipasswd discovery.sendtargets.auth.username=viscsiuser discovery.sendtargets.auth.password=viscsipasswd
4、检测iscsi target服务端提供的共享存储设备信息
[root@node2~]#iscsiadm-mdiscovery-tsendtargets-p10.0.0.11:3260 10.0.0.11:3260,1iqn.2016-09.org.huangming:viscsidisk #查看检查结果 [root@node2~]#ll-R/var/lib/iscsi/nodes/ /var/lib/iscsi/nodes/: total4 drw-------.3rootroot4096Sep317:46iqn.2016-09.org.huangming:viscsidisk /var/lib/iscsi/nodes/iqn.2016-09.org.huangming:viscsidisk: total4 drw-------.2rootroot4096Sep317:4610.0.0.11,3260,1 /var/lib/iscsi/nodes/iqn.2016-09.org.huangming:viscsidisk/10.0.0.11,1: total4 -rw-------.1rootroot2126Sep317:46default #启动iscsi服务 [root@node2~]#/etc/init.d/iscsirestart Stoppingiscsi:[OK] Startingiscsi:[OK] #设置iscsi和iscsid开机启动 [root@node2~]#chkconfigiscsion [root@node2~]#chkconfigiscsidon
5、登陆iscsi target
#显示target数据 [root@node2~]#iscsiadm-mnode 10.0.0.11:3260,1iqn.2016-09.org.huangming:viscsidisk #登陆target [root@node2~]#iscsiadm-mnode-Tiqn.2016-09.org.huangming:viscsidisk--login #查看获得的iscsi磁盘信息 [root@node2~]#fdisk-l Disk/dev/sda:10.7GB,10737418240bytes 255heads,1305cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x000ba502 DeviceBootStartEndBlocksIdSystem /dev/sda1*16451200083Linux Partition1doesnotendoncylinderboundary. /dev/sda264130699727368eLinuxLVM Disk/dev/mapper/VolGroup-lv_root:9202MB,9202302976bytes 255heads,1118cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000 Disk/dev/mapper/VolGroup-lv_swap:1006MB,1006632960bytes 255heads,122cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000 Disk/dev/sdb:838MB,838860800bytes 26heads,62sectors/track,1016cylinders Units=cylindersof1612*512=825344bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000 Disk/dev/sdc:1085MB,1085704704bytes 34heads,61sectors/track,1022cylinders Units=cylindersof2074*512=1061888bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000
6、建立分区
[root@node2~]#fdisk/dev/sdc [root@node2~]#mkfs.ext4/dev/sdc1 [root@node2~]#mkdir/viscsidisk [root@node2~]#mount/dev/sdc1/viscsidisk/ [root@node2~]#df-Th FilesystemTypeSizeUsedAvailUse%Mountedon /dev/mapper/VolGroup-lv_rootext48.4G972M7.0G13%/ tmpfstmpfs491M0491M0%/dev/shm /dev/sda1ext4477M51M401M12%/boot /dev/sdc1ext4987M1.3M934M1%/viscsidisk
#--logout注销target,但是并没有删除/var/lib/iscsi/nodes内的数据 #-odelete删除后面接的那台target连接信息/var/lib/iscsi/nodes/* #-oupdate更新相关信息 #-onew增加一个新的target信息 [root@node2~]#iscsiadm-mnode 10.0.0.11:3260,1iqn.2016-09.org.huangming:viscsidisk [root@node2~]#iscsiadm-mnode-Tiqn.2016-09.org.huangming:viscsidisk--logout Loggingoutofsession[sid:4,target:iqn.2016-09.org.huangming:viscsidisk,portal:10.0.0.11,3260] logoutof[sid:4,3260]successful. [root@node2~]#ls/viscsidisk/ ls:readingdirectory/viscsidisk/:Input/outputerror #delete删除连接 [root@node2~]#iscsiadm-mnode-odelete-Tiqn.2016-09.org.huangming:viscsidisk [root@node2~]#iscsiadm-mnode iscsiadm:Norecordsfound [root@node2~]#fdisk-l Disk/dev/sda:10.7GB,122cylinders Units=cylindersof16065*512=8225280bytes Sectorsize(logical/physical):512bytes/512bytes I/Osize(minimum/optimal):512bytes/512bytes Diskidentifier:0x00000000
8、重新检测并添加target数据
[root@node2~]#iscsiadm-mdiscovery-tsendtargets-p10.0.0.11 10.0.0.11:3260,1iqn.2016-09.org.huangming:viscsidisk [root@node2~]#iscsiadm-mnode 10.0.0.11:3260,1iqn.2016-09.org.huangming:viscsidisk [root@node2~]#ll/var/lib/iscsi/nodes/ total4 drw-------.3rootroot4096Sep318:24iqn.2016-09.org.huangming:viscsidisk #重新连接 [root@node2~]#iscsiadm-mnode-Tiqn.2016-09.org.huangming:viscsidisk--login Logginginto[iface:default,3260](multiple) Loginto[iface:default,3260]successful. #删除target连接之后,再重新连接,磁盘中的数据不会丢失