天天看點

linux iscsi服務實作

1.使用mount将CD光牒位置/dev/cdrom内的檔案挂載到/mnt/cdrom位置上:

mount /dev/cdrom /mnt/cdrom

2.使用find 指令查找安裝包:

find -name iscsi*

3.安裝安裝包:

rpm -ivh  ./Server/iscsi-initiator-utils-6.2.0.868-0.18.el5.i386.rpm

運作此指令後,會生成一個目錄/etc/iscsi,該目錄下有兩個檔案:

Initiatorname.iscsi和iscsid.conf

4.啟動iscsi服務

service iscsi start     或              cd /etc/init.d/   and  ./iscsi start

5.搜尋盤陣:

運作以下指令搜尋target,即目标端:儲存設備

指令格式:[root@linux ~]#iscsiadm --mode discovery --type sendtargets --portal ipaddre

iscsiadm -m discovery -t sendtargets -p 100.1.1.5

6.顯示盤陣:

顯示存儲端target name

eg:

[root@localhost cdrom]# iscsiadm -m node

100.1.1.5:3260,1 iqn.2006-01.com.openfiler:tsn.63bb25fbfaa8

100.1.1.5:3260,1 iqn.2006-01.com.openfiler:tsn.959c083bcac2

[root@localhost cdrom]#

7.登入盤陣

指令格式:target登陸

[root@linux ~]#iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 --login

[root@localhost cdrom]# iscsiadm -m node -T iqn.2006-01.com.openfiler:tsn.959c083bcac2 -p 100.1.1.5:3260 -l

Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.959c083bcac2, portal: 100.1.1.5,3260]

Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.959c083bcac2, portal: 100.1.1.5,3260]: successful

經過以上幾步,fdisk–l就可以看到所挂接分區了!!!

(為確定重新開機後也能看到,再修改一下/etc/iscsi/iscsid.conf

[root@linux ~]# vi /etc/iscsi/iscsid.conf

iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 –login

添加到該檔案中的開始部分。

設定服務啟動chkconfig --level 35 iscsid .)

其實這個檔案大多數内容處于被注釋狀态,該指令添加位置應該影響不大.然後重新開機電腦後直接fdisk –l 依然可以看到所挂接的分區。至此iscsi所有操作完成,但挂載的分區不是linux所識别,必須使用FDISK進行磁盤分區。

8.設定分區

使用fdisk指令進行磁盤分區

fdisk是各種Linux發行版本中最常用的分區工具,是被定義為Expert級别的分區工具。我們可以通過fdisk來分區使用iscsi裝置。它還包括一個二級選單,首先輸入指令,然後出現問答式界面,使用者通過在這個界面中輸入指令參數來操作fdisk。

# fdisk /dev/hdb

運作後出現fdiak的指令提示符:

Command (m for help):

使用n指令建立一個分區,會出現選擇主分區(p primary partition)還是擴充分區(llogical)的提示,通常選用主分區。然後按照提示輸入分區号(Partion number(1-4):)、新分區起始的磁盤塊數(FirstCylinder)和分區的大小,可以是以MB為機關的數字(Last cylindet or +siza or +sizeM or+sizeK:)。例如:

[root@localhost ~]# fdisk /dev/sda      檢視磁盤資訊

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n    建立新分區

Command action

   e   extended                   擴充分區

   p   primary partition (1-4)  邏輯分區

p

Partition number (1-4): 1

First cylinder (1-1011, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-1011, default 1011):

Using default value 1011

Command (m for help): w        儲存分區資訊

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]#

9.檢驗新分區

[root@localhost ~]# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes

34 heads, 61 sectors/track, 1011 cylinders

Units = cylinders of 2074 * 512 = 1061888 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1        1011     1048376+  83  Linux

10.格式化分區

[root@localhost ~]# mkfs -t ext3 /dev/sda1

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

131072 inodes, 262094 blocks

13104 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=268435456

8 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376

Writing inode tables: done                           

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

11.設定加載點

檔案系統必須有一個挂載點,它隻是一個空的目錄,新檔案系統在這裡與系統目錄樹“相連”。

經過以上的操作,Linux伺服器已經連接配接到 iSCSI 儲存裝置, 并且如同Linux 本機上面的一個 SCSI 硬碟一樣。 使用的方式幾乎一模一樣。

假設iSCSI 主機挂載到 /mnt/cluster目錄下:

[root@localhost mnt]# mkdir  /mnt/cluster

[root@localhost mnt]# mount /dev/sda1 /mnt/cluster

[root@localhost mnt]# df

Filesystem        1K-blocks      used Available Use% Mounted on                                                                          /dev/mapper/VolGroup00-LogVol00

                       7491040   2571976   4532404  37% /

/dev/hda1               101086     10787     85080  12% /boot

tmpfs                   127852         0    127852   0% /dev/shm

/dev/sda1              1031888     17692    961780   2% /mnt/cluster

[root@localhost mnt]#

繼續閱讀