ISCSI Target: node4
1.安装scsi-target-utils //服务端程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@node4 ~]
# yum install scsi-target-utils -y
[root@node4 ~]
# vgs
VG
#PV #LV #SN Attr VSize VFree
vgsrv 1 3 0 wz--n- 8.78g 4.69g
[root@node4 ~]
# lvcreate -L 1GB -n lv0 vgsrv
Logical volume
"lv0"
created
[root@node4 ~]
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
home vgsrv -wi-ao 256.00m
lv0 vgsrv -wi-a- 1.00g
root vgsrv -wi-ao 3.31g
swap vgsrv -wi-ao 544.00m
[root@node4 ~]
# ls /dev/vgsrv/lv0
/dev/vgsrv/lv0
|
2.编辑 /etc/tgt/targets.conf,复制38-40行,粘贴如下
[root@node4 ~]# vi /etc/tgt/targets.conf
1
2
3
|
<target iqn.2008-09.com.clovem:target1>
backing-store
/dev/vgsrv/lv0
<
/target
>
|
3. 启动tgtd服务,查看设备是否被导出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
[root@node4 ~]
# service tgtd start
Starting SCSI target daemon: [ OK ]
[root@node4 ~]
# tgt-admin --show
Target 1: iqn.2013-05.com.clovem:target1
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
Readonly: No
Backing store
type
: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store
type
: rdwr
Backing store path:
/dev/vgsrv/lv0
Backing store flags:
Account information:
ACL information:
ALL
|
4.查看Target1后面的LUN:1是我们导出的设备:/dev/vgsrv/lv0
ISCSI Initiator:desktop26
1
2
3
4
|
[root@desktop26 ~]
# rpm -q iscsi-initiator-utils
iscsi-initiator-utils-6.2.0.872-34.el6.x86_64
[root@desktop26 ~]
# which iscsiadm
/sbin/iscsiadm
|
1.启用发现并登录
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@desktop26 ~]
# ls /dev/sd*
/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
[root@desktop26 ~]
# iscsiadm -m discovery -t sendtargets -p 172.18.26.4:3260
172.18.26.4:3260,1 iqn.2013-05.com.clovem:target1
[root@desktop26 ~]
# iscsiadm -m node -T iqn.2013-05.com.clovem:target1 -l
Logging
in
to [iface: default, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260] (multiple)
Login to [iface: default, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260] successful.
[root@desktop26 ~]
# ls /dev/sd*
/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sdb
[root@desktop26 ~]
# ls /dev/disk/by-path/
ip-172.18.26.4:3260-iscsi-iqn.2013-05.com.clovem:target1-lun-1 pci-0000:00:07.1-scsi-1:0:1:0-part1
pci-0000:00:07.1-scsi-1:0:0:0 pci-0000:00:07.1-scsi-1:0:1:0-part2
pci-0000:00:07.1-scsi-1:0:1:0 pci-0000:00:07.1-scsi-1:0:1:0-part3
|
2. 通过iscsiadm命令查看是否导入成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@desktop26 ~]
# iscsiadm -m session -P1
Target: iqn.2013-05.com.clovem:target1
Current Portal: 172.18.26.4:3260,1
Persistent Portal: 172.18.26.4:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:59585542a2c
Iface IPaddress: 172.18.26.254
Iface HWaddress: <empty>
Iface Netdev: <empty>
SID: 2
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
|
3.修改Initiator端名,尽量做在发现跟登入前
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@desktop26 ~]
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2013-05.com.clovem:node1
[root@desktop26 ~]
# iscsiadm -m node -T iqn.2013-05.com.clovem:target1 -u
Logging out of session [sid: 10, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260]
Logout of [sid: 10, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260] successful.
[root@desktop26 ~]
# service iscsid stop
Stopping iscsid:
[root@desktop26 ~]
# iscsiadm -m discovery -t sendtargets -p 172.18.26.4:3260
Starting iscsid: [ OK ]
172.18.26.4:3260,1 iqn.2013-05.com.clovem:target1
[root@desktop26 ~]
# iscsiadm -m node -T iqn.2013-05.com.clovem:target1 -l
Logging
in
to [iface: default, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260] (multiple)
Login to [iface: default, target: iqn.2013-05.com.clovem:target1, portal: 172.18.26.4,3260] successful.
[root@desktop26 ~]
# iscsiadm -m session -P1
Target: iqn.2013-05.com.clovem:target1
Current Portal: 172.18.26.4:3260,1
Persistent Portal: 172.18.26.4:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.2013-05.com.clovem:node1
Iface IPaddress: 172.18.26.254
Iface HWaddress: <empty>
Iface Netdev: <empty>
SID: 11
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
|
现在可以看到Iface Initiatorname: iqn.2013-05.com.clovem:node1 ,修改成功,一般情况下面在导入设备之前就修改客户端设备名。
回到node4中查看状态,可以看到客户端设备名了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
[root@node4 ~]
# tgt-admin --show
Target 1: iqn.2013-05.com.clovem:target1
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 11
Initiator: iqn.2013-05.com.clovem:node1
Connection: 0
IP Address: 172.18.26.254
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Readonly: No
Backing store
type
: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store
type
: rdwr
Backing store path:
/dev/vgsrv/lv0
Backing store flags:
Account information:
ACL information:
ALL
|
定义服务端导出设备属性以及访问控制,修改/etc/tgt/target.conf
1
2
3
4
5
6
7
8
|
<target iqn.2013-05.com.clovem:target1>
< backing-store
/dev/vgsrv/lv0
>
vendor-
id
clovemfong, Inc.
scsi_id target1
scsi_sn s01
<
/backing-store
>
initiator-address 172.18.26.254
<
/target
>
|
重新加载配置文件:service tgtd force-reload //由于当前有客户端登入,需要强制重载配置文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
[root@node4 ~]
# tgt-admin --show
Target 1: iqn.2013-05.com.clovem:target1
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 1
Initiator: iqn.2013-05.com.clovem:node1
Connection: 0
IP Address: 172.18.26.254
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Readonly: No
Backing store
type
: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: target1
SCSI SN: s01
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store
type
: rdwr
Backing store path:
/dev/vgsrv/lv0
Backing store flags:
Account information:
ACL information:
172.18.26.254
|
如果ISCSI存储设备容量>=2TB,就不能够使用常规的fdisk 命令进行磁盘的分区了(其分区表格式为msdos),需要使用parted,其分区表格式为GPT
命令:
parted /dev/sdb print //查看分区
parted /dev/sdb mklabel gpt //转换格式(msdos gpt)
parted /dev/sdb mkpart primary 1m 100m //创建起始大小为1M,结束为100M的名为primary的分区
分区改名:
parted /dev/sdb name 2 ' "Linux FileSystem" ' //对2号分区改名
parted -s /dev/sdb mkfs 1 ext4 //将1号分区格式化为ext4文件系统,测试发现不支持ext4如此格式化,仅仅默认支持ext2,所以通过mkfs.ext4命令进行格式化即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@desktop26 ~]
# parted /dev/sdb mklabel gpt
Warning: The existing disk label on
/dev/sdb
will be destroyed and all data on this disk will be lost. Do you want to
continue
?
Yes
/No
? Yes
Information: You may need to update
/etc/fstab
.
[root@desktop26 ~]
# parted /dev/sdb mkpart rh436 200m 300m
Information: You may need to update
/etc/fstab
.
[root@desktop26 ~]
# parted /dev/sdb print
Model: IET VIRTUAL-DISK (scsi)
Disk
/dev/sdb
: 1074MB
Sector size (logical
/physical
): 512B
/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 200MB 300MB 99.6MB rh436
[root@desktop26 ~]
# mkfs.ext4 /dev/sdb1 > /dev/null 2>&1
[root@desktop26 ~]
# parted /dev/sdb print
Model: IET VIRTUAL-DISK (scsi)
Disk
/dev/sdb
: 1074MB
Sector size (logical
/physical
): 512B
/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 200MB 300MB 99.6MB ext4 rh436
[root@desktop26 ~]
# mkdir /rh436 ; mount /dev/sdb1 /rh436 ; df -H |grep rh436
/dev/sdb1
97M 5.8M 86M 7%
/rh436
|