在RHEL7中,已经使用targetcli软件替换了scsi-target-utils,相对于scsi-target-utils软件,targetcli更加方便易用。具体如下:
1、创建逻辑卷:
[root@server ~]# lvcreate -n vv01 -L +500G datavg [root@server ~]# lvcreate -n vv02 -L +500G datavg [root@server ~]# lvcreate -n vv03 -L +500G datavg
2、安装targetcli软件并启动服务:
[root@server ~]# yum -y install targetcli [root@server ~]# systemctl start target [root@server ~]# systemctl enable target [root@server ~]# systemctl status target
3、创建共享存储:
[root@server ~]# targetcli /backstores/block [root@server ~]# targetcli /backstores/block> create sharedisk01 /dev/datavg/vv01 /backstores/block> create sharedisk02 /dev/datavg/vv02 /backstores/block> create sharedisk03 /dev/datavg/vv03 /backstores/block> ls o- block ........................................................... [Storage Objects: 3] o- sharedisk01 .................................................. [/dev/datavg/vv01 (500.0GiB) write-thru deactivated] o- sharedisk02 ............................................................. [/dev/datavg/vv02 (500.0GiB) write-thru deactivated] o- sharedisk03 ............................................................. [/dev/datavg/vv03 (500.0GiB) write-thru deactivated]
4、创建IQN名称:
/backstores/block> cd / /> cd iscsi /iscsi> create iqn.2015-09.com.he:lun1 Created target iqn.2015-09.com.he:lun1. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260.
target服务默认监听系统中所有IP的3260端口。如果想使其监听某一接口ip的3260端口,则运行下面的命令:
/iscsi> cd iqn.2015-09.com.he:lun1/tpg1 /iscsi/iqn.20....he:lun1/tpg1> portals/ create 172.16.250.100 Using default IP port 3260 Created network portal 172.16.250.100:3260. /iscsi/iqn.2015-09.com.he:lun1/tpg1>
5、创建LUN映射:
/iscsi/iqn.2015-09.com.he:lun1/tpg1> luns/ create /backstores/block/sharedisk01 Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.1991-05.com.microsoft:win10 /iscsi/iqn.2015-09.com.he:lun1/tpg1> luns/ create /backstores/block/sharedisk02 Created LUN 1. Created LUN 1->1 mapping in node ACL iqn.1991-05.com.microsoft:win10 /iscsi/iqn.2015-09.com.he:lun1/tpg1> luns/ create /backstores/block/sharedisk03 Created LUN 2. Created LUN 2->2 mapping in node ACL iqn.1991-05.com.microsoft:win10
默认情况下,添加的lun是可读可写的,如果添加只读lun,则使用下面的命令:
/> set global auto_add_mapped_luns=false Parameter auto_add_mapped_luns is now 'false'.
6、添加ACLs:
此ACL需要客户端的initiator name。
在Linux下,可以查看/etc/iscsi/initiatorname.iscsi文件获得initiator名称;
在Windows下,通过iSCSI 发起程序中的配置选项卡获得initiator名称;
在Solaris下,通过iscsiadm list initiator-node获得initiator名称。
默认的initiator名称可以随便更改。这里windows 10的initiator名称为:iqn.1991-05.com.microsoft:win10。
/iscsi/iqn.2015-09.com.he:lun1/tpg1> acls/ create iqn.1991-05.com.microsoft:win10 Created Node ACL for iqn.1991-05.com.microsoft:win10 /iscsi/iqn.2015-09.com.he:lun1/tpg1> ls o- tpg1 .................................................................................................... [no-gen-acls, no-auth] o- acls ............................................................................................................... [ACLs: 1] | o- iqn.1991-05.com.microsoft:win10 ........................................................................... [Mapped LUNs: 3] | o- mapped_lun0 ................................................................................ [lun0 block/sharedisk01 (rw)] | o- mapped_lun1 ................................................................................ [lun1 block/sharedisk02 (rw)] | o- mapped_lun2 ................................................................................ [lun2 block/sharedisk03 (rw)] o- luns ............................................................................................................... [LUNs: 3] | o- lun0 ................................................................................ [block/sharedisk01 (/dev/datavg/vv01)] | o- lun1 ................................................................................ [block/sharedisk02 (/dev/datavg/vv02)] | o- lun2 ................................................................................ [block/sharedisk03 (/dev/datavg/vv03)] o- portals ......................................................................................................... [Portals: 1] o- 0.0.0.0:3260 .......................................................................................................... [OK]
7、保存配置并退出:
直接在targetcli中输入exit,系统默认会保存配置文件并退出。
/iscsi/iqn.2015-09.com.he:lun1/tpg1> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json
参考文献:
1.http://linux-iscsi.org/wiki/Targetcli
2.docs.redhat.com
本文出自 “candon123” 博客,谢绝转载!