參考資料:
https://www.server-world.info/en/note?os=Ubuntu_20.04&p=iscsi&f=2 https://ubuntu.com/server/docs/service-iscsi
- 安裝iSCSI Target服務
apt install tgt -y
- 創建target文件,用於客戶端連接
# 創建文件目錄
mkdir /data/iscsi_disks/
# 創建target硬盤,使用/dev/zero初始化,固定大小100G
dd if=/dev/zero of=/data/iscsi_disks/disk01.img count=0 bs=1 seek=100G
# 輸出
seek=100G
0+0 records in
0+0 records out
0 bytes copied, 0.000295657 s, 0.0 kB/s
# 查看文件
ll /data/iscsi_disks
# 輸出
total 8
drwxr-xr-x 2 root root 4096 Dec 1 12:58 ./
drwxr-xr-x 4 root root 4096 Dec 1 12:58 ../
-rw-r--r-- 1 root root 107374182400 Dec 1 12:58 disk01.img
- 創建target連接配置
iSCSI 限定名採用 iqn.(year)-(month).(reverse of domain name):(any name you like) 的形式。
yyyy-mm :表示“年份-月份“,是公司成立的年份和月份,這裏的公司一般爲安裝軟件的這個公司,當然了可以隨意選個時間
(reverse of domain name :域名或主機名。
unique name:任何名稱,如主機的名稱或sn號。必須確保在冒號後面分配的任何名稱都是唯一的。
例如:iqn.2021-12.node1:target01
# 注意不能添加特殊符號
nano /etc/tgt/conf.d/target01.conf
# 配置如下
# create new
# if you set some devices, add <target>-</target> and set the same way with follows
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
<target iqn.2021-12.node1:target01>
# provided devicce as a iSCSI target
backing-store /data/iscsi_disks/disk01.img
# iSCSI Initiator's IQN you allow to connect
# initiator-name iqn.2020-05.world.srv:node01.initiator01
# authentication info ( set anyone you like for "username", "password" )
# incominguser username password
# CHAP認證用戶名及密碼
incominguser test 12345678
</target>
- 重啓服務並查看配置
# 重啓target服務
systemctl restart tgt
# 查看配置
tgtadm --mode target --op show
# 輸出
Target 1: iqn.2021-12.node1:target01
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 107374 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /data/iscsi_disks/disk01.img
Backing store flags:
Account information:
test
ACL information:
ALL
- 設置防火牆
# 添加防火牆策略
ufw allow iscsi-target
# 重啓防火牆
ufw reload
- 使用iSCSI發起程序測試是否正常發現目標並連接
連接成功後可以正常初始化