RHEL7 配置iSCSI模拟环境
2018-07-22 13:20 AlfredZhao 阅读(2980) 评论(4) 编辑 收藏 举报在之前文章《multipath多路径实验01-构建iSCSI模拟环境》中,已经介绍了如何构建iSCSI模拟环境(RHEL6),但在RHEL7中已经不适用,本文记录下新的配置方法。
环境:RHEL 7.3
1.LVM创建
在RHEL7.3中,对于lvm操作部分与之前RHEL6版本没有区别,还是创建pv,vg,lv的方法,命令参考如下:pvcreate /dev/sdb
vgcreate vg_storage /dev/sdb
lvcreate -L 1g -n lv_lun1 vg_storage
lvcreate -L 1g -n lv_lun2 vg_storage
lvcreate -L 1g -n lv_lun3 vg_storage
lvcreate -L 40g -n lv_lun4 vg_storage
lvcreate -L 10g -n lv_lun5 vg_storage
lvcreate -L 10g -n lv_lun6 vg_storage
lvcreate -L 10g -n lv_lun7 vg_storage
lvcreate -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 targetcli
systemctl status targetd
systemctl start targetd
systemctl enable targetd
systemctl list-unit-files|grep targetd
同时确认targetd服务启动状态和开启启动。
2.2 使用targetcli创建设备
targetcli进入命令行,cd到/backstores/block 目录下,创建设备:
create disk1 /dev/mapper/vg_storage-lv_lun1
create disk2 /dev/mapper/vg_storage-lv_lun2
create disk3 /dev/mapper/vg_storage-lv_lun3
create disk4 /dev/mapper/vg_storage-lv_lun4
create disk5 /dev/mapper/vg_storage-lv_lun5
create disk6 /dev/mapper/vg_storage-lv_lun6
create disk7 /dev/mapper/vg_storage-lv_lun7
create disk8 /dev/mapper/vg_storage-lv_lun8
创建完成,可以成功看到:
/backstores/block> ls
o- 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 /iscsi
create
cd /iscsi/iqn.20...0be/tpg1/luns
create /backstores/block/disk1
create /backstores/block/disk2
create /backstores/block/disk3
create /backstores/block/disk4
create /backstores/block/disk5
create /backstores/block/disk6
create /backstores/block/disk7
create /backstores/block/disk8
实际执行过程如下:
/backstores/block> cd /iscsi
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
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: 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创建acls
cd到acls目录下,创建client;然后cd到portals目录下创建portals, 参考命令如下:
cd /iscsi/iqn.20...0be/tpg1/acls
create iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be:client
cd /iscsi/iqn.20...0be/tpg1/portals
delete 0.0.0.0 3260
create 10.10.1.21
create 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> ls
o- 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/tcp
firewall-cmd --reload
--关闭防火墙:
systemctl disable firewalld
systemctl stop firewalld
3.客户端配置
3.1 使用yum安装iscsi-initiator-utils
yum -y install iscsi-initiator-utils
3.2 编辑/etc/iscsi/initiatorname.iscsi
vi /etc/iscsi/initiatorname.iscsi
#InitiatorName=iqn.1994-05.com.redhat:babc7da33c48
InitiatorName=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.21
10.10.1.21:3260,1 iqn.2003-01.org.linux-iscsi.storage-b.x8664:sn.46b1dc2750be
10.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 --login
iscsiadm -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 -l
Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001b841
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 167772159 82836480 8e Linux LVM
Disk /dev/mapper/rhel-root: 51.3 GB, 51308920832 bytes, 100212736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/rhel-home: 25.1 GB, 25052577792 bytes, 48930816 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdd: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sde: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdg: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdf: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdh: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdi: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdj: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdl: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdk: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdn: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdm: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdo: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdp: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk /dev/sdq: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
[root@db90 ~]#
由于是两条链路,所以fdisk看到的存储LUN是两倍,后续再使用多路径软件聚合即可使用。