2012/05/06

CentOS6 iSCSI target and initiator 的設定

CentOS6 iSCSI target and initiator 的設定

流程:
1.需要有各儲存裝置 (以 lvm  的裝置示範)
2.安裝 target 服務
3.啟動服務
4.來到 inititor 端,將 target 的分享掛載起來


1.需要有各儲存裝置 (以 lvm  的裝置示範)
[root@server1 ~]# lvcreate -l 3 -n iscsi10  vgsrv
  Logical volume "iscsi10" created

 --- Logical volume ---
  LV Name                /dev/vgsrv/iscsi10
  VG Name                vgsrv
  LV UUID                VcQj9X-yhOD-wMDY-Sh2b-9Z8X-r0Cj-h08rB0
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                96.00 MiB
  Current LE             3
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

2.安裝 target 服務

 # 安裝 scsi-target-utils
[root@server1 ~]# yum install scsi-target-utils

# 修改 targets 設定
[root@server1 ~]# vim /etc/tgt/targets.conf
# 在最後面加入這一段 
# target 名稱自取,通常用這樣的格式即可
iqn.2012-05.world.server:target0>
# 設定儲存裝置來源
  backing-store /dev/vgsrv/iscsi10
# 設定可存取的 initiator 位置
  initiator-address 192.168.123.132
# 登入的學生帳號密碼
  incominguser student PaSsWoRd

3.啟動服務
# 重新啟動 tgtd 服務
[root@server1 ~]# /etc/init.d/tgtd restart
# tgtd 預設開機啟動
[root@server1 ~]# chkconfig tgtd on 
# show tgtadm 顯示設定檔狀況並驗證
[root@server1 ~]# tgtadm --mode target --op show
Target 1: iqn.2012-05.world.server:target0
    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: 101 MB, Block size: 512
            Online: Yes
            Removable media: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vgsrv/iscsi10
            Backing store flags:
    Account information:
        student  # 登入帳號
    ACL information:
        192.168.123.132  # 可使用的主機

4.來到 inititor 端,將 target 的分享掛載起來

[root@desktop1 ~]# iscsiadm -m discovery -t st -p 192.168.123.194
Starting iscsid:                                           [  OK  ]
192.168.123.194:3260,1 iqn.2012-05.world.server:target0

# 因為 target 有設定密碼,所以需要設定這段.
[root@desktop1 ~]# vim /etc/iscsi/iscsid.conf
# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
node.session.auth.authmethod = CHAP

# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = student
node.session.auth.password = password
... 省略 ...

# 掛載 iscsi target
[root@desktop1 ~]# iscsiadm -m node -T iqn.2012-05.world.server:target0 -p 192.168.123.194 -l
Logging in to [iface: default, target: iqn.2012-05.world.server:target0, portal: 192.168.123.194,3260]
Login to [iface: default, target: iqn.2012-05.world.server:target0, portal: 192.168.123.194,3260] successful.

# 找尋裝置代號
[root@desktop1 ~]# tail /var/log/messages
May  6 00:34:21 desktop1 kernel: scsi 4:0:0:0: Attached scsi generic sg2 type 12
May  6 00:34:21 desktop1 kernel: scsi 4:0:0:1: Direct-Access     IET      VIRTUAL-DISK     0001 PQ: 0 ANSI: 5
May  6 00:34:21 desktop1 kernel: sd 4:0:0:1: Attached scsi generic sg3 type 0
May  6 00:34:21 desktop1 kernel: sd 4:0:0:1: [sdb] 196608 512-byte logical blocks: (100 MB/96.0 MiB)
May  6 00:34:21 desktop1 kernel: sd 4:0:0:1: [sdb] Write Protect is off
May  6 00:34:21 desktop1 kernel: sd 4:0:0:1: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
May  6 00:34:21 desktop1 kernel: sdb: unknown partition table
May  6 00:34:21 desktop1 kernel: sd 4:0:0:1: [sdb] Attached SCSI disk

#  預設開機啟動掛載
[root@desktop1 ~]# chkconfig iscsi on
[root@desktop1 ~]# chkconfig iscsid on

因為裝置是 /dev/sdb 所以這個就是我們可以操作的硬碟資訊。

沒有留言: