ラベル iSCSI の投稿を表示しています。 すべての投稿を表示
ラベル iSCSI の投稿を表示しています。 すべての投稿を表示

金曜日, 10月 30, 2009

RHEL, CentOS でのiSCSIイニシエーターの設定

[概要]
Red Hat EL (RHEL) 5.xとCentOS 5.xを使用したiSCSIのイニシエーターとして使用する際の設定を説明しています。

[詳細]
RHEL 5.xとCentOS 5.xには、iSCSI イニシエーターのパッケージiscsi-initiator-utilsが添付されています。このパッケージはLinuxでのiSCSIのソフトウェア・イニシエータの機能を提供します。既出のiSCSIターゲットの構築とあわせて、iSCSIネットワークの構築に手順を記載していきます。
  1. パッケージのインストール
    iscsi-initiator-utilsパッケージをインストールします。
    rpm -Uvh マウントポイント/ClusterStorage/iscsi-initiator-utils*.rpm

  2. 設定ファイルの編集
    "/etc/iscsi/iscsid.conf"の下記の部分を編集します。赤字の場所はターゲットで設定されている値を指定します。
    node.session.auth.username = foo
    node.session.auth.password = bar
    discovery.sendtargets.auth.username = foo
    discovery.sendtargets.auth.password = bar

  3. サービスの起動
    iscsi イニシエーターのサービスを起動します。
    "iSCSI ターゲットを設定中"に"No records found!"と表示されますが、まだ、ターゲットを登録していないので、正常なメッセージです。
    [root@lin01 ~]# service iscsi start
    iscsid は停止しています
    Turning off network shutdown. Starting iSCSI daemon: [ OK ]
    [ OK ]
    iSCSI ターゲットを設定中: iscsiadm: No records found!
    [ OK ]

  4. ターゲットの登録
    iSCSIのターゲットを登録します。赤字のIPアドレスにiSCSIのターゲットのIPアドレスを指定してください。その後、iscsi イニシエーターのサービスを再起動します。
    今回は、"iSCSI ターゲットを設定中"の後に接続したターゲットが表示されるはずです。
    [root@lin01 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.3
    192.168.1.3:3260,1 qn.2001-04.com.jp-lin03-sdb:tgtd
    192.168.1.3:3260,1 qn.2001-04.com.jp-lin03-file:tgtd

    [root@lin01 ~]# service iscsi restart
    Stopping iSCSI daemon:
    iscsid が停止していますが PID ファイルが残っています [ OK ]
    Turning off network shutdown. Starting iSCSI daemon: [ OK ]
    [ OK ]
    iSCSI ターゲットを設定中: Logging in to [iface: default, target: iqn.2007-04.com.jp-lin03:tgtd, portal: 192.168.1.3,3260]
    Login to [iface: default, target: iqn.2007-04.com.jp-lin03:tgtd, portal: 192.168.1.3,3260]: successful
    [ OK ]

  5. デバイスの確認
    dmsageコマンドや"/proc/partitions"で、デバイスが登録されたことを確認します。
    下の出力例では、"/dev/sdf,/dev/sdg,/dev/sdh"として、登録されています。
    [root@lin01 ~]# dmsage
    scsi4 : iSCSI Initiator over TCP/IP
    scsi5 : iSCSI Initiator over TCP/IP
    Vendor: IET Model: Controller Rev: 0001
    Type: RAID ANSI SCSI revision: 05
    scsi 4:0:0:0: Attached scsi generic sg4 type 12
    Vendor: IET Model: VIRTUAL-DISK Rev: 0001
    Type: Direct-Access ANSI SCSI revision: 05
    SCSI device sdf: 58605057 512-byte hdwr sectors (30006 MB)
    sdf: Write Protect is off
    sdf: Mode Sense: 79 00 00 08
    SCSI device sdf: drive cache: write back
    SCSI device sdf: 58605057 512-byte hdwr sectors (30006 MB)
    sdf: Write Protect is off
    sdf: Mode Sense: 79 00 00 08
    SCSI device sdf: drive cache: write back
    sdf: unknown partition table
    sd 4:0:0:1: Attached scsi disk sdf
    sd 4:0:0:1: Attached scsi generic sg5 type 0
    Vendor: IET Model: VIRTUAL-DISK Rev: 0001
    Type: Direct-Access ANSI SCSI revision: 05
    SCSI device sdg: 51697170 512-byte hdwr sectors (26469 MB)
    sdg: Write Protect is off
    sdg: Mode Sense: 79 00 00 08
    SCSI device sdg: drive cache: write back
    SCSI device sdg: 51697170 512-byte hdwr sectors (26469 MB)
    sdg: Write Protect is off
    sdg: Mode Sense: 79 00 00 08
    SCSI device sdg: drive cache: write back
    sdg: unknown partition table
    sd 4:0:0:2: Attached scsi disk sdg
    sd 4:0:0:2: Attached scsi generic sg6 type 0
    Vendor: IET Model: Controller Rev: 0001
    Type: RAID ANSI SCSI revision: 05
    scsi 5:0:0:0: Attached scsi generic sg7 type 12
    Vendor: IET Model: VIRTUAL-DISK Rev: 0001
    Type: Direct-Access ANSI SCSI revision: 05
    SCSI device sdh: 81920000 512-byte hdwr sectors (41943 MB)
    sdh: Write Protect is off
    sdh: Mode Sense: 79 00 00 08
    SCSI device sdh: drive cache: write back
    SCSI device sdh: 81920000 512-byte hdwr sectors (41943 MB)
    sdh: Write Protect is off
    sdh: Mode Sense: 79 00 00 08
    SCSI device sdh: drive cache: write back
    sdh: unknown partition table
    sd 5:0:0:1: Attached scsi disk sdh
    sd 5:0:0:1: Attached scsi generic sg8 type 0

  6. パーティション、ファイルシステムの作成
    これ以降はiSCSIであることを意識せずに、通常のディスクと同様にパーティションとファイルシステムを作成すれば、mountして使用することが出来ます。


以上で、RHEL, CentOS でのiSCSIイニシエーターの設定の説明は終わりです。

火曜日, 9月 29, 2009

RHEL5, CentOS 5でのiSCSIターゲットの設定

[概要]
Red Hat EL (RHEL) 5.xとCentOS 5.xを使用したiSCSIのターゲットの作成を説明しています。

[詳細]
RHEL 5.xとCentOS 5.xには、iSCSI ターゲットとなるためのパッケージscsi-target-utilsが添付されています。このパッケージを利用してLinuxマシンをiSCSIのターゲットとして運用する方法を説明します。

  1. パッケージのインストール
    • RHEL 5.x
      Cluster Storageのパッケージグループに属していますので、次のようにパッケージのパスを指定してください。
      rpm -ivh マウントポイント/ClusterStorage/scsi-target-utils*

    • CentOS 5.x
      rpm -ivh マウントポイント/CentOS/scsi-target-utils*

  2. ターゲットの作成

    ターゲットの管理は、tgtadmというコマンドを使って行いますが、多くのオプションがあり初心者にはちょっと扱いづらいところがあります。
    tgtadmを直接使わずに、簡単にセットアップするためにいくつかのコマンドが用意されています。ターゲットの追加は"tgt-setup-lun"、ターゲットの変更や状態の表示は"tgt-admin"で行うことが出来ます。
    ただ、これらのコマンドでの実行だけでは、マシンの起動と同時にiSCSIのターゲットは動作しません。起動時に動作させるためには/etc/tgt/targets.confに、ターゲットの設定を記述し、サービスtgtdを自動起動するように設定します。
    まず、/etc/tgt/targets.confの記述方法について説明します。
    1. /etc/tgt/targets.confの書式
      /etc/tgt/targets.confは、ターゲットごとに"<target ターゲット名>"と"</target>"の間に設定を記述します。
      • backing-store
        iSCSIデバイスとなるディスク、もしくは、パーティション、ファイルを指定します。backing-storeを複数指定すると、イニシエータ(クライアント)からは複数のLUNとして表示されます。
        backing-store /dev/sdb1
        backing-store /opt/disk.img

      • initiator-address
        接続を許可するイニシエータのIPアドレスを記載します。複数のイニシエータに接続を許可する場合はinitiator-addressを列挙します。
        逆にinitiator-addressが無い場合には、すべてのイニシエータからの接続を許可します。
        initiator-address 192.168.1.152
        initiator-address 192.168.1.154

      • incominguser
        ターゲットへ接続するイニシエータ対して認証を要求するよう設定します。
        incominguser foo bar

      • outgoinguser
        イニシエータの要求する認証に、ターゲットが返答するよう設定します。
        outgoinguser foo bar


      <target qn.2001-04.com.jp-lin03-sdb:tgtd>
      # List of files to export as LUNs
      backing-store /dev/sdb1
      backing-store /dev/sdb4

      # Authentication :
      # if no "incominguser" is specified, it is not used
      #incominguser backup secretpass12

      # Access control :
      # defaults to ALL if no "initiator-address" is specified
      initiator-address 192.168.1.152
      initiator-address 192.168.1.154
      </target>
      <target qn.2001-04.com.jp-lin03-file:tgtd>
      # List of files to export as LUNs
      backing-store /opt/disk.img

      # Authentication :
      # if no "incominguser" is specified, it is not used
      incominguser foo bar

      # Access control :
      # defaults to ALL if no "initiator-address" is specified
      #initiator-address 192.168.1.151
      </target>


      上記の例では、"qn.2001-04.com.jp-lin03-sdb:tgtd"と"qn.2001-04.com.jp-lin03-file:tgtd"という2つのターゲットを定義しています。"qn.2001-04.com.jp-lin03-sdb:tgtd"は、"/dev/sdb1"と"/dev/sdb4"のそれぞれをLUNとして定義し、"192.168.1.152"と"192.168.1.154"からのアクセスを許可しています。次に、"qn.2001-04.com.jp-lin03-file:tgtd"は、"/opt/disk.img"というレギュラーファイルをLUNとして、すべてのイニシエーターからのアクセスを許可していますが接続に対してユーザ名"foo"、パスワード"bar"という認証を要求します。


  3. サービスの自動起動の設定
    [root@localhost]~# chkconfig tgtd on

  4. tgtdサービスの起動
    [root@localhost]~# service tgtd start

  5. 動作確認
    "tgt-admin -s"もしくは、"tgtadm --lld iscsi --mode target --op show"を使用して、動作確認を行います。
    各ターゲットのLUN 0はSCSIのコントローラとなるので、ディスクが割り当てられるのは、LUN 1から見ていきます。

    LUNについてのチェックは、指定した数のディスクが存在するか、"Backing store"に正しいデバイスが指定されているか、"Online"が"Yes"になっているかを見ます。他には" Account information"で指定したユーザが表示されているか、"ACL information"では指定したIPアドレスが表示されているかをチェックしてください。

    [root@localhost ~]# tgt-admin -s
    Target 1: qn.2001-04.com.jp-lin03-sdb:tgtd
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: deadbeaf3:0
    SCSI SN: beaf30
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store: No backing store
    LUN: 1
    Type: disk
    SCSI ID: deadbeaf3:1
    SCSI SN: beaf31
    Size: 30006 MB
    Online: Yes
    Removable media: No
    Backing store: /dev/sdb1
    LUN: 2
    Type: disk
    SCSI ID: deadbeaf3:2
    SCSI SN: beaf32
    Size: 26469 MB
    Online: Yes
    Removable media: No
    Backing store: /dev/sdb4
    Account information:
    ACL information:
    100.100.100.152
    100.100.100.154
    Target 2: qn.2001-04.com.jp-lin03-file:tgtd
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: deadbeaf1:0
    SCSI SN: beaf10
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store: No backing store
    LUN: 1
    Type: disk
    SCSI ID: deadbeaf1:1
    SCSI SN: beaf11
    Size: 41943 MB
    Online: Yes
    Removable media: No
    Backing store: /opt/disk.img
    Account information:
    foo
    ACL information:
    ALL

以上で、iSCSIのターゲットの設定は終了です。