如何创建LIO Target

1480阅读 0评论2014-10-11 taohorse
分类:服务器与存储

这里介绍如何使用targetcli命令进行lio target的配置

1.进入targetcli名ing行
# targetcli

2.创建底层存储
/> cd backstores/iblock
 
/backstores/iblock> ls
o- iblock ....................................................................................................... [0 Storage Object]
 
/backstores/iblock> create name=iscsi0 dev=/dev/vmdata/iscsi0
Generating a wwn serial.
Created iblock storage object iscsi0 using /dev/vmdata/iscsi0.
Entering new node /backstores/iblock/iscsi0
 
/backstores/iblock/iscsi0> ls
o- iscsi0 ......................................................................................... [/dev/vmdata/iscsi0 deactivated]

××这里使用块设备来创建底层设备,也可以使用文件来创建,如果使用文件,则进入backstores/fileio目录创建。使用命令:
[root@atlas-pc ~]# dd if=/dev/zero of=/dev/vmdata/iscsi0 bs=4M count=256
# targetcli
>cd backstores/fileio
/backstores/fileio>  create name=iscsi0 file_or_dev=/dev/vmdata/iscsi0 size=1G

3.创建target

/backstores/iblock/iscsi0> cd /iscsi
 
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793.
Selected TPG Tag 1.
Successfully created TPG 1.
Entering new node /iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1
 
/iscsi/iqn.20...66a0793/tpgt1> ls
o- tpgt1 ................................................................................................................. [enabled]
  o- acls .................................................................................................................. [0 ACL]
  o- luns .................................................................................................................. [0 LUN]
  o- portals ............................................................................................................ [0 Portal]

4.创建lun
/iscsi/iqn.20...66a0793/tpgt1> cd luns
 
/iscsi/iqn.20...93/tpgt1/luns> create /backstores/iblock/iscsi0
Selected LUN 0.
Successfully created LUN 0.
Entering new node /iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1/luns/lun0
 
/iscsi/iqn.20...gt1/luns/lun0> ls
o- lun0 ....................................................................................... [iblock/iscsi0 (/dev/vmdata/iscsi0)]

5.创建portal

/iscsi/iqn.20...66a0793/tpgt1> cd portals
/iscsi/iqn.20...tpgt1/portals> ls
o- portals .............................................................................................................. [0 Portal]
 
/iscsi/iqn.20...tpgt1/portals> create 192.168.122.1 3260
Successfully created network portal 192.168.122.1:3260.
Entering new node /iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1/portals/192.168.122.1:3260
 
/iscsi/iqn.20...68.122.1:3260> cd ..
/iscsi/iqn.20...tpgt1/portals> create 192.168.122.1 3261
Successfully created network portal 192.168.122.1:3261.
Entering new node /iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1/portals/192.168.122.1:32616.创建acls

6.添加访问许可(acls)

/iscsi/iqn.20...66a0793/tpgt1> cd acls
 
/iscsi/iqn.20...93/tpgt1/acls> create iqn.1993-08.org.debian:01:50d4b3301a24
Successfully created Node ACL for iqn.1993-08.org.debian:01:50d4b3301a24
Created mapped LUN 0.
Entering new node /iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1/acls/iqn.1993-08.org.debian:01:50d4b3301a24
/iscsi/iqn.20...:50d4b3301a24> ls
o- iqn.1993-08.org.debian:01:50d4b3301a24 ........................................................................... [1 Mapped LUN]
  o- mapped_lun0 ....................................................................................................... [lun0 (rw)]

**create后的参数为initiator的名字,可以在客户机的/etc/iscsi/initiatorname.iscsi文件中找到

7.设置授权属性

这里设置为可以无密码访问
/> cd iscsi/iqn.2003-01.org.linux-iscsi.l99.x8664:sn.936bc66a0793/tpgt1/
/iscsi/iqn.20...66a0793/tpgt1> set attribute authentication=0
Parameter authentication is now '0'.
/iscsi/iqn.20...66a0793/tpgt1>

8.保存配置

/iscsi> cd /
 
/> saveconfig
WARNING: Saving l99 current configuration to disk will overwrite your boot settings.
The current target configuration will become the default boot config.
Are you sure? Type 'yes': yes
Making backup of qla2xxx/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Successfully updated default config /etc/target/qla2xxx_start.sh
Making backup of srpt/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Successfully updated default config /etc/target/srpt_start.sh
Making backup of loopback/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Successfully updated default config /etc/target/loopback_start.sh
Making backup of fc/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Successfully updated default config /etc/target/fc_start.sh
Making backup of LIO-Target/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Generated LIO-Target config: /etc/target/backup/lio_backup-2013-12-02_16:42:36.209861.sh
Making backup of Target_Core_Mod/ConfigFS with timestamp: 2013-12-02_16:42:36.209861
Generated Target_Core_Mod config: /etc/target/backup/tcm_backup-2013-12-02_16:42:36.209861.sh
Successfully updated default config /etc/target/lio_start.sh
Successfully updated default config /etc/target/tcm_start.sh
/> exit






上一篇:equal_range用法
下一篇:kvm下模拟网卡故障