1. 程式人生 > >Configure iscsi Storage on Linux

Configure iscsi Storage on Linux

ISCSI

Internet SCSI (iSCSI) is a network protocol s that allows you to use of the SCSI protocol over TCP/IP networks. It is good alternative to Fibre Channel-based SANs. You can easily manage, mount and format iSCSI Volume under Linux. It allows access to SAN storage over Ethernet.

Open-iSCSI Project

Open-iSCSI project is a high-performance, transport independent, multi-platform implementation of iSCSI. Open-iSCSI is partitioned into user and kernel parts.

Instructions are tested on:

  • [a] RHEL 5
  • [b] CentOS 5
  • [c] Fedora 7
  • [d] Debian / Ubuntu Linux

Install Required Package

iscsi-initiator-utils RPM package - The iscsi package provides the server daemon for the iSCSI protocol, as well as the utility programs used to manage it. iSCSI is a protocol for distributed disk access using SCSI commands sent over Internet Protocol networks. This package is available under Redhat Enterprise Linux / CentOS / Fedora Linux and can be installed using yum command:

# yum install iscsi-initiator-utils

A note about Debian / Ubuntu Linux

If you are using Debian / Ubuntu Linux install open-iscsi package, enter:

$ sudo apt-get install open-iscsi

CentOS / Red Hat Linux: Install and manage iSCSI Volume

iSCSI Configuration

There are three steps needed to set up a system to use iSCSI storage:

  • iSCSI startup using the init script or manual startup. You need to edit and configure iSCSI via /etc/iscsi/iscsid.conf file
  • Discover targets.
  • Automate target logins for future system reboots.

You also need to obtain iSCSI username, password and storage server IP address (target host)

Step # 1: Configure iSCSI

Open /etc/iscsi/iscsid.conf with vi text editor:

# vi /etc/iscsi/iscsid.conf

Setup username and password:

node.session.auth.username = My_ISCSI_USR_NAME
node.session.auth.password = MyPassword
discovery.sendtargets.auth.username = My_ISCSI_USR_NAME
discovery.sendtargets.auth.password = MyPassword

Where,

  • node.session.* is used to set a CHAP username and password for initiator authentication by the target(s).
  • discovery.sendtargets.* is used to set a discovery session CHAP username and password for the initiator authentication by the target(s)

You may also need to tweak and set other options. Refer to man page for more information. Now start the iscsi service:

# /etc/init.d/iscsid start

Step # 2: Discover targets

Now use iscsiadm command, which is a command-line tool allowing discovery and login to iSCSI targets, as well as access and management of the open-iscsi database. If your storage server IP address is 192.168.1.5, enter:

# iscsiadm -m discovery -t sendtargets -p 192.168.1.5

# /etc/init.d/iscsid restart

Now there should be a block device under /dev directory. To obtain new device name, type:

# fdisk -l

or

# tail -f /var/log/messages

Output:

Oct 10 12:42:20 ora9is2 kernel:   Vendor: EQLOGIC   Model: 100E-00           Rev: 3.2
Oct 10 12:42:20 ora9is2 kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: 41963520 512-byte hdwr sectors (21485 MB)
Oct 10 12:42:20 ora9is2 kernel: sdd: Write Protect is off
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: drive cache: write through
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: 41963520 512-byte hdwr sectors (21485 MB)
Oct 10 12:42:20 ora9is2 kernel: sdd: Write Protect is off
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: drive cache: write through
Oct 10 12:42:20 ora9is2 kernel:  sdd: unknown partition table
Oct 10 12:42:20 ora9is2 kernel: sd 3:0:0:0: Attached scsi disk sdd
Oct 10 12:42:20 ora9is2 kernel: sd 3:0:0:0: Attached scsi generic sg3 type 0
Oct 10 12:42:20 ora9is2 kernel: rtc: lost some interrupts at 2048Hz.
Oct 10 12:42:20 ora9is2 iscsid: connection0:0 is operational now

/dev/sdd is my new block device.

Step # 3: Format and Mount iSCSI Volume

You can now partition and create a filesystem on the target using usual fdisk and mkfs.ext3 commands:

# fdisk /dev/sdd
# mke2fs -j -m 0 -O dir_index /dev/sdd1

OR

# mkfs.ext3 /dev/sdd1

Tip: If your volume is large size like 1TB, run mkfs.ext3 in background using nohup:

# nohup mkfs.ext3 /dev/sdd1 &

Mount new partition:

# mkdir /mnt/iscsi
# mount /dev/sdd1 /mnt/iscsi

Step #4: Mount iSCSI drive automatically at boot time

First make sure iscsi service turned on at boot time:

# chkconfig iscsi on

Open /etc/fstab file and append config directive:

/dev/sdd1 /mnt/iscsi ext3 _netdev 0 0

Save and close the file.

測試

1.關於多重聯機

多重聯機即一個或多個客戶端連線一塊SAN分配的儲存單元,不過為避免資料受損,必須確認在叢集 架構下使用才行。

在測試過程中,使用新購置的兩臺ERP測試伺服器共享一塊網路儲存,發現存在以下問題:

多寫

mount 均採用 mount -o acl,rw /dev/sdb5 /data 進行掛載;寫資料時,都是使用root寫入;

  • a. 多臺客戶端可以同時掛載,但掛載後,寫入的資料僅有自身可以看到,其他客戶端不可見;
  • b. 多臺客戶端可以同時掛載時,各客戶端均有寫入資料時,當時資料沒有丟失,但是重新掛載網路裝置時,會出現資料丟失的情況(只能看到最後寫入的資料);

一寫多讀

  • a. 多個客戶端同時掛載,僅一個客戶端寫資料,其他讀;在寫入時,其他客戶端暫時不可見,必須重新掛載;
  • b. 關於AIX和Oracle Linux之間共享該網路儲存(一寫一讀),Oracle Linux掛載jfs2檔案系統時不識別,新增jfs相關的軟體包後掛載失敗;在CentOS 6.2上,新增jfs2軟體包後可以掛載jfs2檔案系統。對比後,發現Oracle Linux啟動的核心為uek核心,可能和當前系統執行的核心相關。

2.其他

另外,測試了下使用SAN儲存搭建NFS,多客戶端可以同時讀寫,但速率很低。

Reference

blog comments powered by Disqus