您现在的位置是:网站首页> 内容页

RHEL7 配置iSCSI模拟环境

  • 云顶www.7610.com
  • 2019-03-21
  • 406人已阅读
简介在之前文章《multipath多路径实验01-构建iSCSI模拟环境》中,已经介绍了如何构建iSCSI模拟环境(RHEL6),但在RHEL7中已经不适用,本文记录下新的配置方法。环境:

在之前文章《multipath多路径实验01-构建iSCSI模拟环境》中,已经介绍了如何构建iSCSI模拟环境(RHEL6),但在RHEL7中已经不适用,本文记录下新的配置方法。环境:RHEL 7.3

1.LVM创建2.服务端配置3.客户端配置

1.LVM创建

在RHEL7.3中,对于lvm操作部分与之前RHEL6版本没有区别,还是创建pv,vg,lv的方法,命令参考如下:

pvcreate /dev/sdbvgcreate vg_storage /dev/sdblvcreate -L 1g -n lv_lun1 vg_storagelvcreate -L 1g -n lv_lun2 vg_storagelvcreate -L 1g -n lv_lun3 vg_storagelvcreate -L 40g -n lv_lun4 vg_storagelvcreate -L 10g -n lv_lun5 vg_storagelvcreate -L 10g -n lv_lun6 vg_storagelvcreate -L 10g -n lv_lun7 vg_storagelvcreate -L 16g -n lv_lun8 vg_storage

最终可以看到新建的lv信息:

[root@Storage-B yum.repos.d]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home rhel -wi-ao---- 23.33g root rhel -wi-ao---- 47.79g swap rhel -wi-ao---- 7.88g lv_lun1 vg_storage -wi-a----- 1.00g lv_lun2 vg_storage -wi-a----- 1.00g lv_lun3 vg_storage -wi-a----- 1.00g lv_lun4 vg_storage -wi-a----- 40.00g lv_lun5 vg_storage -wi-a----- 10.00g lv_lun6 vg_storage -wi-a----- 10.00g lv_lun7 vg_storage -wi-a----- 10.00g lv_lun8 vg_storage -wi-a----- 16.00g

2.服务端配置

之前在RHEL6中安装的iscsi服务端rpm包的名字是:scsi-target-utils,这在RHEL7中变成了targetd、targetcli这两个包。2.1 使用yum安装targetd和targetcli

yum -y install targetd targetclisystemctl status targetdsystemctl start targetdsystemctl enable targetdsystemctl list-unit-files|grep targetd

同时确认targetd服务启动状态和开启启动。

2.2 使用targetcli创建设备targetcli进入命令行,cd到/backstores/block 目录下,创建设备:

create disk1 /dev/mapper/vg_storage-lv_lun1create disk2 /dev/mapper/vg_storage-lv_lun2create disk3 /dev/mapper/vg_storage-lv_lun3create disk4 /dev/mapper/vg_storage-lv_lun4create disk5 /dev/mapper/vg_storage-lv_lun5create disk6 /dev/mapper/vg_storage-lv_lun6create disk7 /dev/mapper/vg_storage-lv_lun7create disk8 /dev/mapper/vg_storage-lv_lun8

创建完成,可以成功看到:

/backstores/block> lso- block ...................................................................................................... [Storage Objects: 8] o- disk1 ........................................................ [/dev/mapper/vg_storage-lv_lun1 (1.0GiB) write-thru deactivated] o- disk2 ........................................................ [/dev/mapper/vg_storage-lv_lun2 (1.0GiB) write-thru deactivated] o- disk3 ........................................................ [/dev/mapper/vg_storage-lv_lun3 (1.0GiB) write-thru deactivated] o- disk4 ....................................................... [/dev/mapper/vg_storage-lv_lun4 (40.0GiB) write-thru deactivated] o- disk5 ....................................................... [/dev/mapper/vg_storage-lv_lun5 (10.0GiB) write-thru deactivated] o- disk6 ....................................................... [/dev/mapper/vg_storage-lv_lun6 (10.0GiB) write-thru deactivated] o- disk7 ....................................................... [/dev/mapper/vg_storage-lv_lun7 (10.0GiB) write-thru deactivated] o- disk8 ....................................................... [/dev/mapper/vg_storage-lv_lun8 (16.0GiB) write-thru deactivated]

2.3 使用targetcli创建iqn和LUN然后cd到/iscsi目录下,创建iqn;cd到/iscsi/iqn.20...0be/tpg1/luns下创建LUN,参考命令如下:

cd /iscsicreatecd /iscsi/iqn.20...0be/tpg1/lunscreate /backstores/block/disk1create /backstores/block/disk2create /backstores/block/disk3create /backstores/block/disk4create /backstores/block/disk5create /backstores/block/disk6create /backstores/block/disk7create /backstores/block/disk8

实际执行过程如下:

/backstores/block> cd /iscsi/iscsi> lso- iscsi .............................................................................................................. [Targets: 0]/iscsi> createCreated target iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be.Created TPG 1.Global pref auto_add_default_portal=trueCreated default portal listening on all IPs (0.0.0.0), port 3260./iscsi> lso- iscsi .............................................................................................................. [Targets: 1] o- iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be ......................................................... [TPGs: 1] o- tpg1 ................................................................................................. [no-gen-acls, no-auth] o- acls ............................................................................................................ [ACLs: 0] o- luns ............................................................................................................ [LUNs: 0] o- portals ...................................................................................................... [Portals: 1] o- 0.0.0.0:3260 ....................................................................................................... [OK]/iscsi/iqn.20...0be/tpg1/luns> ls o- luns .................................................................................................................. [LUNs: 8] o- lun0 ........................................................................... [block/disk1 (/dev/mapper/vg_storage-lv_lun1)] o- lun1 ........................................................................... [block/disk2 (/dev/mapper/vg_storage-lv_lun2)] o- lun2 ........................................................................... [block/disk3 (/dev/mapper/vg_storage-lv_lun3)] o- lun3 ........................................................................... [block/disk4 (/dev/mapper/vg_storage-lv_lun4)] o- lun4 ........................................................................... [block/disk5 (/dev/mapper/vg_storage-lv_lun5)] o- lun5 ........................................................................... [block/disk6 (/dev/mapper/vg_storage-lv_lun6)] o- lun6 ........................................................................... [block/disk7 (/dev/mapper/vg_storage-lv_lun7)] o- lun7 ........................................................................... [block/disk8 (/dev/mapper/vg_storage-lv_lun8)]/iscsi/iqn.20...0be/tpg1/luns>

2.4 使用targetcli创建aclscd到acls目录下,创建client;然后cd到portals目录下创建portals, 参考命令如下:

cd /iscsi/iqn.20...0be/tpg1/aclscreate iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be:clientcd /iscsi/iqn.20...0be/tpg1/portalsdelete 0.0.0.0 3260create 10.10.1.21create 10.10.2.21

实际执行过程如下:

/iscsi/iqn.20.../tpg1/portals> pwd/iscsi/iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be/tpg1/portals/iscsi/iqn.20.../tpg1/portals> lso- portals ............................................................................................................ [Portals: 2] o- 10.10.1.21:3260 .......................................................................................................... [OK] o- 10.10.2.21:3260 .......................................................................................................... [OK]

2.5 使用targetcli查看当前配置信息在/下执行ls,或者ls /查看当前配置信息:

/iscsi/iqn.20.../tpg1/portals> ls /o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 8] | | o- disk1 ...................................................... [/dev/mapper/vg_storage-lv_lun1 (1.0GiB) write-thru activated] | | o- disk2 ...................................................... [/dev/mapper/vg_storage-lv_lun2 (1.0GiB) write-thru activated] | | o- disk3 ...................................................... [/dev/mapper/vg_storage-lv_lun3 (1.0GiB) write-thru activated] | | o- disk4 ..................................................... [/dev/mapper/vg_storage-lv_lun4 (40.0GiB) write-thru activated] | | o- disk5 ..................................................... [/dev/mapper/vg_storage-lv_lun5 (10.0GiB) write-thru activated] | | o- disk6 ..................................................... [/dev/mapper/vg_storage-lv_lun6 (10.0GiB) write-thru activated] | | o- disk7 ..................................................... [/dev/mapper/vg_storage-lv_lun7 (10.0GiB) write-thru activated] | | o- disk8 ..................................................... [/dev/mapper/vg_storage-lv_lun8 (16.0GiB) write-thru activated] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 1] | o- iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be ....................................................... [TPGs: 1] | o- tpg1 ............................................................................................... [no-gen-acls, no-auth] | o- acls .......................................................................................................... [ACLs: 1] | | o- iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be:client ................................... [Mapped LUNs: 8] | | o- mapped_lun0 ................................................................................. [lun0 block/disk1 (rw)] | | o- mapped_lun1 ................................................................................. [lun1 block/disk2 (rw)] | | o- mapped_lun2 ................................................................................. [lun2 block/disk3 (rw)] | | o- mapped_lun3 ................................................................................. [lun3 block/disk4 (rw)] | | o- mapped_lun4 ................................................................................. [lun4 block/disk5 (rw)] | | o- mapped_lun5 ................................................................................. [lun5 block/disk6 (rw)] | | o- mapped_lun6 ................................................................................. [lun6 block/disk7 (rw)] | | o- mapped_lun7 ................................................................................. [lun7 block/disk8 (rw)] | o- luns .......................................................................................................... [LUNs: 8] | | o- lun0 ................................................................... [block/disk1 (/dev/mapper/vg_storage-lv_lun1)] | | o- lun1 ................................................................... [block/disk2 (/dev/mapper/vg_storage-lv_lun2)] | | o- lun2 ................................................................... [block/disk3 (/dev/mapper/vg_storage-lv_lun3)] | | o- lun3 ................................................................... [block/disk4 (/dev/mapper/vg_storage-lv_lun4)] | | o- lun4 ................................................................... [block/disk5 (/dev/mapper/vg_storage-lv_lun5)] | | o- lun5 ................................................................... [block/disk6 (/dev/mapper/vg_storage-lv_lun6)] | | o- lun6 ................................................................... [block/disk7 (/dev/mapper/vg_storage-lv_lun7)] | | o- lun7 ................................................................... [block/disk8 (/dev/mapper/vg_storage-lv_lun8)] | o- portals .................................................................................................... [Portals: 2] | o- 10.10.1.21:3260 .................................................................................................. [OK] | o- 10.10.2.21:3260 .................................................................................................. [OK] o- loopback ......................................................................................................... [Targets: 0]/iscsi/iqn.20.../tpg1/portals>

最后配置防火墙策略,或者直接关闭防火墙,建议后者,视具体要求而定。

--防火墙添加放行tcp 3260端口:firewall-cmd --permanent --add-port=3260/tcpfirewall-cmd --reload--关闭防火墙:systemctl disable firewalldsystemctl stop firewalld

3.客户端配置

3.1 使用yum安装iscsi-initiator-utils

yum -y install iscsi-initiator-utils

3.2 编辑/etc/iscsi/initiatorname.iscsivi /etc/iscsi/initiatorname.iscsi

#InitiatorName=iqn.1994-05.com.redhat:babc7da33c48InitiatorName=iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be:client

注释之前的示例,添加一行实际的配置。

3.3 使用iscsiadm发现可用存储设备并登陆连接iscsiadm -m discovery -t st -p 10.10.1.21

[root@db92 yum.repos.d]# iscsiadm -m discovery -t st -p 10.10.1.2110.10.1.21:3260,1 iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be10.10.2.21:3260,1 iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be

登陆连接:

iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be -p 10.10.1.21 --loginiscsiadm -m node -T iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be -p 10.10.2.21 --login

此时使用fdisk -l 查看已经正常显示所有设备:

[root@db90 ~]# fdisk -lDisk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0001b841 Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 167772159 82836480 8e Linux LVMDisk /dev/mapper/rhel-root: 51.3 GB, 51308920832 bytes, 100212736 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rhel-home: 25.1 GB, 25052577792 bytes, 48930816 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdd: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sde: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdg: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdf: 42.9 GB, 42949672960 bytes, 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdh: 1073 MB, 1073741824 bytes, 2097152 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdi: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdj: 42.9 GB, 42949672960 bytes, 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdl: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdk: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdn: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdm: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdo: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdp: 17.2 GB, 17179869184 bytes, 33554432 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytesDisk /dev/sdq: 17.2 GB, 17179869184 bytes, 33554432 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 33550336 bytes[root@db90 ~]#

由于是两条链路,所以fdisk看到的存储LUN是两倍,后续再使用多路径软件聚合即可使用。

, 1, 0, 9);

文章评论

Top