在开始做实验之前,首先统一实验环境,准备2台虚拟机
首先在Server端进行操作
安装服务
[root@localhost ~]# yum -y install targetd targetcli
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包 targetd-0.8.6-1.el7.noarch 已安装并且是最新版本
软件包 targetcli-2.1.53-1.el7_9.noarch 已安装并且是最新版本
无须任何处理
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl enable target
[root@localhost ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
Active: active (exited) since 四 2022-04-28 20:27:00 CST; 6min ago
Main PID: 1184 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/target.service
4月 28 20:26:58 localhost.localdomain systemd[1]: Starting Restore LIO kernel targ....
4月 28 20:27:00 localhost.localdomain target[1184]: Could not create StorageObject...d
4月 28 20:27:00 localhost.localdomain target[1184]: Could not find matching Storag...d
4月 28 20:27:00 localhost.localdomain target[1184]: Could not find matching TPG LU...d
4月 28 20:27:00 localhost.localdomain systemd[1]: Started Restore LIO kernel targe....
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
设置防火墙
[root@localhost ~]# firewall-cmd --add-port=3260/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-ports
3260/tcp
执行targetcli工具
[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
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
基本思路:
先把准备共享的块做出来,创建一个target,在target上创建LUN,一个LUN连接一个块。 // 注意,执行完targetcli命令以后,出错,是因为缺少包导致的,需要下载一个包。
Server端
1、指定要发布的磁盘(块设备LUN)
/> /backstores/block create server0.disk1 /dev/sdc
Created block storage object server0.disk1 using /dev/sdc.
2、创建iqn名字即创建ISCSI对象
/> /iscsi create iqn.2020-05.com.bdqn:disk1
Created target iqn.2020-05.com.bdqn:disk1.
Created TPG 1. Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
3、设置ACL即将ISCSI对象与客户端IP或主机名绑定
/> /iscsi/iqn.2020-05.com.bdqn:disk1/tpg1/acls create iqn.202005.com.bdqn:client1
Created Node ACL for iqn.2020-05.com.bdqn:client1
4、创建LUN并绑定块
/> /iscsi/iqn.2020-05.com.bdqn:disk1/tpg1/luns create
/backstores/block/server0.disk1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-05.com.bdqn:client1