一、创建 LVM
[[email protected] ~]# pvcreate /dev/sdc1 [[email protected] ~]# vgcreate vglabstor1 /dev/sdc1 Volume group "vglabstor1" successfully created [[email protected] ~]# lvcreate -l 100%FREE -n lvlabstor1 vglabstor1 Logical volume "lvlabstor1" created. [[email protected] ~]# lvscan ACTIVE '/dev/cl/swap' [2.00 GiB] inherit ACTIVE '/dev/cl/root' [46.50 GiB] inherit ACTIVE '/dev/vglabstor1/lvlabstor1' [80.00 GiB] inherit [[email protected] ~]# mkfs.xfs /dev/vglabstor1/lvlabstor1 meta-data=/dev/vglabstor1/lvlabstor1 isize=512 agcount=4, agsize=5242624 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=20970496, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=10239, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [[email protected] ~]# mkdir /labstor1 [[email protected] ~]# mount /dev/vglabstor1/lvlabstor1 /labstor1/
二、安装配置 iscsi target
1.安装 targetcli
[[email protected] ~]# uname -r 3.10.0-514.el7.x86_64 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [[email protected] ~]# yum install targetcli
2.配置 targetcli
[[email protected] ~]# targetcli targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /backstores> cd fileio /backstores/fileio> create disk01 /labstor1/disk01.img 1G Created fileio disk01 with size 1073741824 /backstores/fileio> create disk02 /labstor1/disk02.img 30G Created fileio disk02 with size 32212254720 /backstores/fileio> ls / o- / ...................................................................................................................... [...] o- backstores ........................................................................................................... [...] | o- block ............................................................................................... [Storage Objects: 0] | o- fileio .............................................................................................. [Storage Objects: 2] | | o- disk01 .......................................................... [/labstor1/disk01.img (1.0GiB) write-back deactivated] | | | o- alua ................................................................................................ [ALUA Groups: 1] | | | o- default_tg_pt_gp .................................................................... [ALUA state: Active/optimized] | | o- disk02 ......................................................... [/labstor1/disk02.img (30.0GiB) write-back deactivated] | | o- alua ................................................................................................ [ALUA Groups: 1] | | o- default_tg_pt_gp .................................................................... [ALUA state: Active/optimized] | o- pscsi ............................................................................................... [Storage Objects: 0] | o- ramdisk ............................................................................................. [Storage Objects: 0] o- iscsi ......................................................................................................... [Targets: 1] | o- iqn.2018-05.storage.kvm.com:stor1 .............................................................................. [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] o- loopback ...................................................................................................... [Targets: 0] /backstores/fileio> cd /iscsi/ /iscsi> ls o- iscsi ........................................................................................................... [Targets: 1] o- iqn.2018-05.storage.kvm.com:stor1 ................................................................................ [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> cd iqn.2018-05.storage.kvm.com:stor1/tpg1/luns /iscsi/iqn.20...or1/tpg1/luns> create /backstores/fileio/disk01 Created LUN 0. /iscsi/iqn.20...or1/tpg1/luns> create /backstores/fileio/disk02 Created LUN 1. /iscsi/iqn.20...or1/tpg1/luns> ls o- luns ............................................................................................................... [LUNs: 2] o- lun0 ............................................................. [fileio/disk01 (/labstor1/disk01.img) (default_tg_pt_gp)] o- lun1 ............................................................. [fileio/disk02 (/labstor1/disk02.img) (default_tg_pt_gp)] /iscsi/iqn.20...or1/tpg1/acls> create iqn.1994-05.com.redhat:kvm Created Node ACL for iqn.1994-05.com.redhat:kvm Created mapped LUN 1. Created mapped LUN 0. /iscsi/iqn.20...or1/tpg1/acls> create iqn.1994-05.com.redhat:node2 Created Node ACL for iqn.1994-05.com.redhat:node2 Created mapped LUN 1. Created mapped LUN 0. /iscsi/iqn.20...or1/tpg1/acls> ls o- acls ............................................................................................................... [ACLs: 2] o- iqn.1994-05.com.redhat:kvm ................................................................................ [Mapped LUNs: 2] | o- mapped_lun0 .................................................................................... [lun0 fileio/disk01 (rw)] | o- mapped_lun1 .................................................................................... [lun1 fileio/disk02 (rw)] o- iqn.1994-05.com.redhat:node2 .............................................................................. [Mapped LUNs: 2] o- mapped_lun0 .................................................................................... [lun0 fileio/disk01 (rw)] o- mapped_lun1 .................................................................................... [lun1 fileio/disk02 (rw)
三、客户端 initiator 连接 target
1.检查软件是否安装及查看 initiatorname 名称
[[email protected] ~]# rpm -qa |grep iscsi libiscsi-1.9.0-7.el7.x86_64 libvirt-daemon-driver-storage-iscsi-3.9.0-14.el7_5.2.x86_64 iscsi-initiator-utils-6.2.0.873-35.el7.x86_64 iscsi-initiator-utils-iscsiuio-6.2.0.873-35.el7.x86_64 [[email protected] ~]# rpm -qa |grep iscsi libiscsi-1.9.0-7.el7.x86_64 iscsi-initiator-utils-iscsiuio-6.2.0.874-4.el7.x86_64 iscsi-initiator-utils-6.2.0.874-4.el7.x86_64 libvirt-daemon-driver-storage-iscsi-3.2.0-14.el7_4.9.x86_64 [[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:node2 [[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:kvm
2.检查是否可以发现
[[email protected] ~]# iscsiadm --mode discovery --type sendtargets --portal 172.16.216.167 172.16.216.167:3260,1 iqn.2018-05.storage.kvm.com:stor1
3.测试挂载设备
[[email protected] ~]# iscsiadm -d2 -m node --login #<--登陆节点 iscsiadm: Max file limits 1024 4096 iscsiadm: libvirt-iface-08137b06: Creating session 1/1 Logging in to [iface: libvirt-iface-08137b06, target: iqn.2018-05.storage.kvm.com:stor1, portal: 172.16.216.167,3260] (multiple) Login to [iface: libvirt-iface-08137b06, target: iqn.2018-05.storage.kvm.com:stor1, portal: 172.16.216.167,3260] successful. [[email protected] ~]# iscsiadm -m node #<--查看iscsi发现记录 172.16.216.167:3260,1 iqn.2018-05.storage.kvm.com:stor1
4.断开与 target 的连接
[[email protected] ~]# iscsiadm -d2 -m node --logout #<--退出节点
原文地址:http://blog.51cto.com/stuart/2122381
时间: 2024-10-09 23:30:10