前言
最近在做无盘集群,使用到iPXE+TFTP+iSCSI的方案,其中iSCSI是基于ZFS的volume的,这里记录一下部署流程。
服务端部署
首先确定target名称:iqn.2021-10.cn.cloudraft.pve.us01:node.02
命名规范:iqn.-.:
<yyyy> – The year in 4-digit format. i.e. 2021, 2018
<mm> – The numeric month in 2-digit format. Should be in the range 01-12. i.e. 01 (for January), 08 (for August), 12 (December)
<fqdn-reverse-format> – The fully qualified domain name in reverse format. i.e. iscsi.linuxhint.com should be written as com.linuxhint.iscsi.
<unique-identifier> – It can be anything unique in your setup. For small home and office setup, you may use the ZFS pool name and volume name (i.e., pool1.vol1, pool1.vol2) or the department/branch name (i.e., engineering.pc1, account.pc2, engineering.us-1, account.uk-2) of the clients that will use these shared volumes. That should be unique enough. In a large company, you may use a unique UUID for each target.
准备依赖环境
apt install open-iscsi tgt -y
新建target
tgtadm --lld iscsi --op new --mode target --tid 2 --targetname iqn.2021-10.cn.cloudraft.pve.us01:node.02
tgtadm --lld iscsi --op show --mode target
root@PVE-US01-01:~# tgtadm --lld iscsi --op show --mode target
Target 2: iqn.2021-10.cn.cloudraft.pve.us01:node.02
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00020000
SCSI SN: beaf20
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:
Account information:
ACL information:
新建存储设备
zfs create -V 32G rpool/node-02
绑定存储设备
tgtadm --lld iscsi --op new --mode logicalunit --tid 2 --lun 1 --backing-store /dev/rpool/node-02
root@PVE-US01-01:~# tgtadm --lld iscsi --op show --mode target
Target 2: iqn.2021-10.cn.cloudraft.pve.us01:node.02
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00020000
SCSI SN: beaf20
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 00020001
SCSI SN: beaf21
Size: 34360 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/rpool/node-02
Backing store flags:
Account information:
ACL information:
设置允许访问的ip地址
tgtadm --lld iscsi --op bind --mode target --tid 2 --initiator-address 192.168.1.2
保存设置
tgt-admin --dump | tee /etc/tgt/targets.conf
重新载入tgt服务
service tgt reload
查看tgt服务状态
root@PVE-US01-01:~# ss -tlpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
....
LISTEN 0 4096 [::]:3260 [::]:* users:(("tgtd",pid=1062978,fd=7))
....
客户端部署
安装依赖环境
apt install open-iscsi
读取iSCSI信息
iscsiadm --mode discovery --type sendtargets --portal 192.168.1.1
root@static:~# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.1
192.168.1.1:3260,1 iqn.2021-10.cn.cloudraft.pve.us01:node.02
连接iSCSI磁盘
iscsiadm --mode node --targetname iqn.2021-10.cn.cloudraft.pve.us01:node.02 -p 192.168.1.1 --login
root@static:~# iscsiadm --mode node --targetname iqn.2021-10.cn.cloudraft.pve.us01:node.02 -p 192.168.1.1 --login
Logging in to [iface: default, target: iqn.2021-10.cn.cloudraft.pve.us01:node.02, portal: 192.168.1.1,3260]
Login to [iface: default, target: iqn.2021-10.cn.cloudraft.pve.us01:node.02, portal: 192.168.1.1,3260] successful.
root@static:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 32G 0 disk
└─sda1 8:1 0 32G 0 part /
sdb 8:16 0 32G 0 disk