Ubuntu Server 20.04搭建iSCSI-Target服务

参考资料:

https://www.server-world.info/en/note?os=Ubuntu_20.04&p=iscsi&f=2 https://ubuntu.com/server/docs/service-iscsi

  1. 安装iSCSI Target服务
apt install tgt -y
  1. 创建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
  1. 创建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>
  1. 重启服务并查看配置
# 重启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
  1. 设置防火墙
# 添加防火墙策略
ufw allow iscsi-target
# 重启防火墙
ufw reload
  1. 使用iSCSI发起程序测试是否正常发现目标并连接

连接成功后可以正常初始化

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章