iscsi target 配置及使用

####環境:node

192.168.10.91 target v1.0.24session

192.168.10.92 initiatorapp

192.168.10.93 initiator測試

####安裝iscsi targetcode

  • 安裝軟件包

# yum install scsi-target-utils -y # service tgtd start && chkconfig tgtd onorm

  • 建立target

# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname t1ip

# tgtadm --lld iscsi --mode target --op new --tid 2 --targetname t2rem

  • 爲2個target分配空間,測試使用dd建立的文件會報錯,用block設備就行了

# lvcreate -L 200M -n target-t1 vg_ops1get

# lvcreate -L 300M -n target-t2 vg_ops1it

# 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
相關文章
相關標籤/搜索