参考
iSCSI代表Internet小型计算机系统接口是一种存储区域网络协议,可用于共享块设备,例如HDD / SSD分区或LVM分区,或网络上的块文件。iSCSI以客户端-服务器模型工作,并依赖TCP / IP网络在发起方客户端和目标之间发送SCSI命令。iSCSI Target是iSCSI服务器上的一项服务,可提供对共享存储的访问,而iSCSI Initiator是连接到目标并访问共享存储的iSCSI客户端。
步骤
target端
- 配置iSCSI目标
首先,您需要在iSCSI服务器上创建LUN(逻辑单元号)设备。LUN是作为物理SCSI设备一部分的后端存储设备。映射到iSCSI Target的所有LUN实际上都已附加到客户端的操作系统。因此,启动器可以在iSCSI LUN上建立和管理文件系统。
| vi /etc/tgt/conf.d/iscsi.conf |
内容如下:
| <target iqn.2023-02.pendl.com:lun1> |
| backing-store /dev/nvme0n1 |
| initiator-address 192.168.159.144 |
| </target> |
配置完毕,重启tgt:
查看状态
可以看到如下信息:
| ● tgt.service - (i)SCSI target daemon |
| Loaded: loaded (/lib/systemd/system/tgt.service; enabled; vendor preset: enabled) |
| Active: active (running) since Sun 2023-02-12 18:19:15 PST; 9min ago |
| Docs: man:tgtd(8) |
| Process: 11366 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v offline (code=exited, status=0/SUCCESS) |
| Process: 11367 ExecStartPost=/usr/sbin/tgt-admin -e -c /etc/tgt/targets.conf (code=exited, status=0/SUCCESS) |
| Process: 11395 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v ready (code=exited, status=0/SUCCESS) |
| Main PID: 11365 (tgtd) |
| Status: "Starting event loop..." |
| Tasks: 17 |
| Memory: 3.0M |
| CGroup: /system.slice/tgt.service |
| └─11365 /usr/sbin/tgtd -f |
| |
| Feb 12 18:19:15 ubuntu systemd[1]: Starting (i)SCSI target daemon... |
| Feb 12 18:19:15 ubuntu tgtd[11365]: tgtd: iser_ib_init(3431) Failed to initialize RDMA; load kernel modules? |
| Feb 12 18:19:15 ubuntu tgtd[11365]: tgtd: work_timer_start(146) use timer_fd based scheduler |
| Feb 12 18:19:15 ubuntu tgtd[11365]: tgtd: bs_init(387) use signalfd notification |
| Feb 12 18:19:15 ubuntu tgtd[11365]: tgtd: device_mgmt(246) sz:18 params:path=/dev/nvme0n1 |
| Feb 12 18:19:15 ubuntu tgtd[11365]: tgtd: bs_thread_open(409) 16 |
| Feb 12 18:19:15 ubuntu systemd[1]: Started (i)SCSI target daemon. |
| tgtadm --mode target --op show |
可以看到如下信息:
| Target 1: iqn.2023-02.pendl.com:lun1 |
| 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: 21475 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: /dev/nvme0n1 |
| Backing store flags: |
| Account information: |
| ACL information: |
| 192.168.159.144 |
Initiator端
| apt-get install open-iscsi |
| |
| 192.168.159.144:3260,1 iqn.2023-02.pendl.com:lun1 |
节点配置文件将存放于目录 /etc/iscsi/nodes/ 中,并且每个LUN都有一个对应的配置目录。
比如:/etc/iscsi/nodes/iqn.2023-02.pendl.com:lun1/192.168.159.144,3260,1/default
在上述发现命令执行完毕后将在 /etc/iscsi/nodes/ 中自动生成指向iscsi target的IP的配置目录。
如果要更新服务端target的配置需要将 /etc/iscsi/nodes/ 下的配置目录删除,然后再执行iscsiadm -m discovery … 发现命令,以生成新的配置。
- 添加iSCSI Target LUN名称
vim /etc/iscsi/initiatorname.iscsi
| |
| InitiatorName=iqn.2023-02.pendl.com:client |
| |
| systemctl restart open-iscsi iscsid |
| |
| |
| systemctl status open-iscsi |
| iscsiadm -m session -o show |
| |
| |
| iscsiadm -m discovery -t sendtargets -p 192.168.91.151 |
| 或者 |
| iscsiadm -m node --login |
| |
| |
| iscsiadm -m node -T iqn.2021-03.bee.com:lun1 -p 192.168.91.151 -l |
| |
| |
| iscsiadm -m node -T iqn.2021-03.bee.com:lun1 -p 192.168.91.151 -u |
| |
| |
| fdisk -l |
| cat /proc/partitions |
| lsblk |
| |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
2014-02-13 解决Kscope中文乱码问题