Skip to main content

iSCSI 发起程序


配置 iSCSI 发起程序。
此示例基于如下环境。
+------------------------+ | +------------------------+
| [iSCSI 目标] |10.0.0.30 | 10.0.0.51| [iSCSI 启动器] |
| dlp.srv.world +----------+----------+ node01.srv.world |
| | | |
+----------+ +----------+

[1] 配置 iSCSI Initiator 以连接到 iSCSI Target

[root@node01 ~]# dnf -y install iscsi-initiator-utils
[root@node01 ~]# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2021-03.world.srv:node01.initiator01
[root@node01 ~]# vi /etc/iscsi/iscsid.conf
# line 58 : uncomment
node.session.auth.authmethod = CHAP
# line 69,70 : uncomment and specify the username and password you set on the iSCSI target server
node.session.auth.username = username
node.session.auth.password = password
# discover target
[root@node01 ~]# iscsiadm -m discovery -t sendtargets -p 10.0.0.30
[  894.285096] Loading iSCSI transport class v2.0-870.
[  894.308086] iscsi: registered transport (tcp)
10.0.0.30:3260,1 iqn.2021-03.world.srv:dlp.target01

# confirm status after discovery
[root@node01 ~]# iscsiadm -m node -o show
# BEGIN RECORD 2.1.2
node.name = iqn.2021-03.world.srv:dlp.target01
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.iscsi_ifacename = default
.....
.....
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.DataDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD

# login to the target
[root@node01 ~]# iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2021-03.world.srv:dlp.target01, portal: 10.0.0.30,3260]
Login to [iface: default, target: iqn.2021-03.world.srv:dlp.target01, portal: 10.0.0.30,3260] successful.

# confirm the established session
[root@node01 ~]# iscsiadm -m session -o show
tcp: [1] 10.0.0.30:3260,1 iqn.2021-03.world.srv:dlp.target01 (non-flash)
# confirm the partitions
[root@node01 ~]# cat /proc/partitions
major minor  #blocks  name

 252        0   31457280 sda
 252        1    1048576 sda1
 252        2   30407680 sda2
 252       16   83886080 sdb
 252       17   83885056 sdb1
 253        0   27258880 dm-0
 253        1    3145728 dm-1
   8        0   10485760 sdc
# added new device provided from the target server as [sdc]

[2] 设置 iSCSI 设备后,在 Initiator 上进行配置以像下面一样使用它

# create label
[root@node01 ~]# parted --script /dev/sdc "mklabel gpt"
# create partiton
[root@node01 ~]# parted --script /dev/sdc "mkpart primary 0% 100%"
# format with XFS
[root@node01 ~]# mkfs.xfs -i size=1024 -s size=4096 /dev/sdc1
meta-data=/dev/sdc1 isize=1024 agcount=4, agsize=654336 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=2617344, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

[root@node01 ~]# mount /dev/sdc1 /mnt
[root@node01 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/cs-root xfs 26G 2.3G 24G 9% /
/dev/sda1 xfs 1014M 259M 756M 26% /boot
tmpfs tmpfs 374M 0 374M 0% /run/user/0
/dev/sdc1 xfs 10G 99M 9.9G 1% /mnt