####环境:
192.168.10.91 target v1.0.24
192.168.10.92 initiator
192.168.10.93 initiator
####安装iscsi target
- 安装软件包
# yum install scsi-target-utils -y # service tgtd start && chkconfig tgtd on
- 创建target
# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname t1
# tgtadm --lld iscsi --mode target --op new --tid 2 --targetname t2
- 为2个target分配空间,测试使用dd创建的文件会报错,用block设备就好了
# lvcreate -L 200M -n target-t1 vg_ops1
# lvcreate -L 300M -n target-t2 vg_ops1
# lvcreate -L 400M -n target-t1-2 vg_ops1
# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/mapper/vg_ops1-target--t1
# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/mapper/vg_ops1-target--t1--2
# tgtadm --lld iscsi --mode logicalunit --op new --tid 2 --lun 1 --backing-store /dev/mapper/vg_ops1-target--t2
- (可选)创建用户密码并为target添加用户,user1使用target 1,user2使用target 2
# tgtadm --lld iscsi --mode account --op new --user user1 --password password1
# tgtadm --lld iscsi --mode account --op new --user user2 --password password2
# tgtadm --lld iscsi --mode account --op bind --tid 1 --user user1
# tgtadm --lld iscsi --mode account --op bind --tid 2 --user user2
- 为target创建分配acl,要都可用可把ip替换为ALL
# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.10.92
# tgtadm --lld iscsi --mode target --op bind --tid 2 --initiator-address 192.168.10.93
- 查看target状态
# tgtadm --lld iscsi --mode target --op show
Target 1: t1
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
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 210 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/mapper/vg_ops1-target--t1
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 419 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/mapper/vg_ops1-target--t1--2
Backing store flags:
Account information:
user1
ACL information:
192.168.10.92
Target 2: t2
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
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00020001
SCSI SN: beaf21
Size: 315 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/mapper/vg_ops1-target--t2
Backing store flags:
Account information:
user2
ACL information:
192.168.10.93
####挂载iscsi
- 安装iscsi-initiator
# yum install iscsi-initiator-utils -y
- 查看iscsi target
[root@ops2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.91:3260
192.168.10.91:3260,1 t1
[root@ops3 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.91:3260
192.168.10.91:3260,1 t2
- 登陆iscsi target
192.168.10.92:
# iscsiadm -m node -T t1 -p 192.168.10.91:3260 -o update -n node.startup -v automatic #开机启动
# iscsiadm -m node -T t1 -p 192.168.10.91:3260 -o update -n node.session.auth.authmethod -v CHAP
# iscsiadm -m node -T t1 -p 192.168.10.91:3260 -o update -n node.session.auth.username -v user1
# iscsiadm -m node -T t1 -p 192.168.10.91:3260 -o update -n node.session.auth.password -v password1
# iscsiadm -m node -T t1 -p 192.168.10.91:3260 -l
Logging in to [iface: default, target: t1, portal: 192.168.10.91,3260] (multiple)
Login to [iface: default, target: t1, portal: 192.168.10.91,3260] successful.
192.168.10.93:
# iscsiadm -m node -T t2 -p 192.168.10.91:3260 -o update -n node.session.auth.username -v user2
# iscsiadm -m node -T t2 -p 192.168.10.91:3260 -o update -n node.session.auth.password -v password2
# iscsiadm -m node -T t2 -p 192.168.10.91:3260 -l
Logging in to [iface: default, target: t2, portal: 192.168.10.91,3260] (multiple)
Login to [iface: default, target: t2, portal: 192.168.10.91,3260] successful.
- 查询磁盘iscsi信息,查找硬盘是哪个机器上挂过来的
# udevadm info --query=all --name=/dev/sdc
P: /devices/platform/host9/session7/target9:0:0/9:0:0:2/block/sdc
N: sdc
W: 45
S: block/8:32
S: disk/by-id/scsi-1IET_00010002
S: disk/by-path/ip-192.168.10.91:3260-iscsi-t1-lun-2
E: UDEV_LOG=3
E: DEVPATH=/devices/platform/host9/session7/target9:0:0/9:0:0:2/block/sdc
E: MAJOR=8
E: MINOR=32
E: DEVNAME=/dev/sdc
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: ID_SCSI=1
E: ID_VENDOR=IET
E: ID_VENDOR_ENC=IET\x20\x20\x20\x20\x20
E: ID_MODEL=VIRTUAL-DISK
E: ID_MODEL_ENC=VIRTUAL-DISK
E: ID_REVISION=0001
E: ID_TYPE=disk
E: ID_SERIAL_RAW=1IET 00010002
E: ID_SERIAL=1IET_00010002
E: ID_SERIAL_SHORT=IET_00010002
E: ID_SCSI_SERIAL=beaf12
E: ID_BUS=scsi
E: ID_PATH=ip-192.168.10.91:3260-iscsi-t1-lun-2
E: LVM_SBIN_PATH=/sbin
E: DEVLINKS=/dev/block/8:32 /dev/disk/by-id/scsi-1IET_00010002 /dev/disk/by-path/ip-192.168.10.91:3260-iscsi-t1-lun-2