【原创】使用 Linux IO (LIO) 创建 SCSI target

1. 简介

Linux中三种SCSI target的介绍之LIO

2. 服务端 ISCSI Target 操作

# 1. 安装 targetcli,配置开机启动
yum install targetcli
systemctl start target
systemctl enable target

# 2. 执行 targetcli 命令创建 ISCSI target

[root@node01 disk]# targetcli  # 进入 targetcli 命令行
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls #查看当前内容
o- / ................................................................ [...
  o- backstores ..................................................... [...
  | o- block ......................................... [Storage Objects: 0
  | o- fileio ........................................ [Storage Objects: 0
  | o- pscsi ......................................... [Storage Objects: 0
  | o- ramdisk ....................................... [Storage Objects: 0
  o- iscsi ................................................... [Targets: 0
  o- loopback ................................................ [Targets: 0
/> cd backstores/fileio # 进入文件存储后端
/backstores/fileio> create disk01 /disk/disk01.img 30GB  # 创建文件存储 lun,此 lun 为 /disk/ 目录下的一个文件
Created fileio disk01 with size 32212254720
/backstores/fileio> cd /iscsi # 进入 iscsi 后端
/iscsi> create # 创建 IQN 号
Created target iqn.2003-01.org.linux-iscsi.node01.x8664:sn.c7a462828ce.
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.node01.x8664:sn.c7a4628228ce  [TPs: 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.2003-01.org.linux-iscsi.node01.x8664:sn.c7a4628228c/tpg1/luns # 进入 ISCSI target 后端
/iscsi/iqn.20...8ce/tpg1/luns> create /backstores/fileio/disk01 # 创建 iscsi 卷
Created LUN 0.
/iscsi/iqn.20...8ce/tpg1/luns> cd ..
/iscsi/iqn.20...628228ce/tpg1>  set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1 # 设置任意 ISCSI Initiator 可连接
Parameter demo_mode_write_protect is now '0'.  # 此项指设置为 demo 模式,即无需要配置 ACL 权限控制列表即可连接
Parameter authentication is now '0'. # 此项为关闭密码认证
Parameter generate_node_acls is now '1'. # 此项为将 Initiator 自动添加进 ACL 认证列表,与上一项必须同时配置
Parameter cache_dynamic_acls is now '1'. # 此项为记录 ACL 信息,方便 SCSI 保持连接,设置成 demo 模式后,默认即为 1。此时是手动再次配置。
/iscsi/iqn.20...628228ce/tpg1> cd /
/> ls  # 此时整个LIO 配置如下,其中 portals 在添加 iscsi lun 后会自动创建一个可接受任何 IP 的 3260 端口
o- / ............................................................... [...]
  o- backstores .................................................... [...]
  | o- block ........................................ [Storage Objects: 0]
  | o- fileio ....................................... [Storage Objects: 1]
  | | o- disk01 ........ [/disk/disk01.img (30.0GiB) write-back activated]
  | |   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.2003-01.org.linux-iscsi.node01.x8664:sn.c7a4628228ce  [TPGs: 1]
  |   o- tpg1 ........................................ [gen-acls, no-auth]
  |     o- acls ................................................ [ACLs: 0]
  |     o- luns ................................................ [LUNs: 1]
  |     | o- lun0 .. [fileio/disk01 (/disk/disk01.img) (default_tg_pt_gp)]
  |     o- portals .......................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ........................................... [OK]
  o- loopback ............................................... [Targets: 0]
/> saveconfig # 保存配置
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
/> exit # 退出,默认退出时会自动保存配置
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@node01 disk]#

# 3. 重启 target 服务,若不重启,则系统重启后 targetcli 配置会还原
systemctl restart target

配置参考:http://linux-iscsi.org/wiki/ISCSI

3. 客户端 ISCSI Initiator 操作

# 1. 安装 iscsi-initiator 包
 yum install iscsi-initiator-utils

# 2. 执行 iscsiadm 命令i添加 iscsi lun

[root@node01 ~]#  iscsiadm -m discovery -t st -p 127.0.0.1 # 扫描 ISCSI Target
127.0.0.1:3260,1 iqn.2003-01.org.linux-iscsi.node01.x8664:sn.56b68820eec4
[root@node01 ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.node01.x8664:sn.56b68820eec4 -l # 挂载 ISCSI lun
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.node01.x8664:sn.56b68820eec4, portal: 127.0.0.1,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.node01.x8664:sn.56b68820eec4, portal: 127.0.0.1,3260] successful.

常见iscsiadm命令
1.发现iscsi存储: iscsiadm -m discovery -t st -p ISCSI_IP
2.查看iscsi发现记录 iscsiadm -m node
iscsiadm -m session
3.删除iscsi发现记录 iscsiadm -m node -o delete -T LUN_NAME -p ISCSI_IP
4.登录iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -l
5.登出iscsi存储 iscsiadm -m node -T LUN_NAME -p ISCSI_IP -u
6.刷新已连接的 session 以识别新 lun :iscsiadm -m session -R
iscsiadm -m discovery -t sendtargets -p 192.168.218.76:3260
iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.ceph01.x8664:sn.9cb14e3c5e32 -p 192.168.218.76:3260 -l
iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.ceph01.x8664:sn.9cb14e3c5e32 -p 192.168.218.76:3260 -u

你可能感兴趣的:(linux,RHEL7)