新买了一台浪潮AS530N的存储设备,支持iscsi,折腾过程中发现不能随便写主机名,需要遵守iqn格式,于是学习了一下,随笔记录一下。
在iSCSI网络中,每个iSCSI元素都有一个不变且唯一的名字,归属于一个地址,用于访问,不管这个元素的物理位置在哪。
iSCSI名字有IQN和EUI两种格式,IQN比较常见。
IQN
(iSCSI qualified name)最多支持255个字符,格式如下:
iqn.yyyy-mm.naming-authority:unique
name
yyyy-mm
是公司域名注册的年月
naming-authority 是域名的逆转格式,例如:
iqn.1998-01.com.vmware.iscsi
这个说明vmware.com这个域名,是1998.01注册的,iscsi是子域名,即iscsi.vmware.com的逆转格式。
unique
name
可以是你想用的任何名字,例如主机名,但必须确保冒号后边的名字是唯一的,例如:
iqn.1998-01.com.vmware.iscsi:name1
iqn.1998-01.com.vmware.iscsi:name2
iqn.1998-01.com.vmware.iscsi:name999
下表也可以参考
Type | . | Date | . | Naming Auth | : | String defined by example.com Naming Authority |
---|---|---|---|---|---|---|
iqn | . | 1992-01 | . | com.example | : | storage:diskarrays-sn-a8675309 |
iqn | . | 1992-01 | . | com.example | ||
iqn | . | 1992-01 | . | com.example | : | storage.tape1.sys1.xyz |
iqn | . | 1992-01 | . | com.example | : | storage.disk2.sys1.xyz |
看了一篇老外的文档,关于如何在CentOS7中自动挂在iscsi磁盘,摘干货如下。
1.安装iscsi启动器
# yum install -y
iscsi-initiator-utils
2.配置启动器的IQN名字
# vi /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2014-08.com.example:client
3.配置要连接的target的用户名和密码,用户名就是启动器名字
# vi /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP
node.session.auth.username =
iqn.2014-08.com.example:client
node.session.auth.password = password
4.启动iscsi服务
# systemctl start
iscsi
注意:这一步是必须的,为了确保启动器机器重启时,可以自动卸载iscsi磁盘,注意不要搞混iscsid和iscsi服务。
5.发现iscsi target
# iscsiadm --mode discovery --type sendtargets --portal
192.168.1.81
192.168.1.81:3260,1 iqn.2014-08.com.example:t1
6.登录
# iscsiadm --mode node --targetname iqn.2014-08.com.example:t1
--portal 192.168.1.81 --login
Logging in to [iface: default, target:
iqn.2014-08.com.example:t1, portal: 192.168.1.81,3260]
(multiple)
Login to [iface: default, target: iqn.2014-08.com.example:t1,
portal: 192.168.1.81,3260] successful.
7.查看是否认到iscsi磁盘
# lsblk --scsi
NAME HCTL
TYPE VENDOR MODEL
REV
TRAN
sda 2:0:0:0
disk LIO-ORG shareddata
4.0
iscsi
8.确认iscsi磁盘处于“可写”状态,即RO那一列是0,如果为1,则是只读状态
# lsblk | egrep "NAME|sda"
NAME
MAJ:MIN RM SIZE RO TYPE
MOUNTPOINT
sda
8:0
0 100M
0 disk
9.在iscsi磁盘上创建文件系统
# parted /dev/sda mklabel gpt yes
# mkfs.ext4 -T largefile /dev/sda
mke2fs 1.42.9 (28-Dec-2013)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=4096 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information:
done
10.确认iscsi磁盘的UUID
# blkid | grep "/dev/sda"
/dev/sda: UUID="4a184c70-20ad-4d91-a0b1-c2cf0eb1986f"
TYPE="ext4"
11.使用UUID方式挂载磁盘,写入/etc/fstab,mount options字段中,注明是_netdev
UUID=4a184c70-20ad-4d91-a0b1-c2cf0eb1986f /mnt
ext4
_netdev 0
0
12. 测试磁盘挂载是否成功,是否可写。
# mount -a
# touch /mnt/testFile
13.可以查看iscsi session状态
# iscsiadm -m session -P 3
iSCSI Transport Class version 2.0-870
version 6.2.0.873-28
Target: iqn.2014-08.com.example:t1 (non-flash)
Current Portal: 192.168.1.81:3260,1
Persistent Portal: 192.168.1.81:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.2014-08.com.example:client
Iface IPaddress: 192.168.1.10
Iface HWaddress:
Iface Netdev:
SID: 1
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
*********
Timeouts:
*********
Recovery Timeout: 120
Target Reset Timeout: 30
LUN Reset Timeout: 30
Abort Timeout: 15
*****
CHAP:
*****
username: usr
password: ********
username_in:
password_in: ********
************************
Negotiated iSCSI params:
************************
HeaderDigest: None
DataDigest: None
MaxRecvDataSegmentLength: 262144
MaxXmitDataSegmentLength: 262144
FirstBurstLength: 65536
MaxBurstLength: 262144
ImmediateData: Yes
InitialR2T: Yes
MaxOutstandingR2T: 1
************************
Attached SCSI devices:
************************
Host Number: 2 State: running
scsi2 Channel 00 Id 0 Lun: 0
Attached scsi disk sda State: running
参考文档:
https://en.wikipedia.org/wiki/ISCSI
https://www.certdepot.net/rhel7-configure-iscsi-target-initiator-persistently/
https://www.synology.com/zh-cn/knowledgebase/DSM/tutorial/Virtualization/How_to_set_up_and_use_iSCSI_target_on_Linux