叢集例項:配置ISCSI客戶端(LINUX)

zhouxianwang發表於2013-11-27

1.1.1 安裝rpm包
將iscsi包cp到本地盤,並在該包所在的目錄下執行命令
[root@linux ~]# rpm –ivh iscsi-initiator-utils-6.2.0.742-0.5.el5.i386.rpm

執行此命令後,會生成一個目錄/etc/iscsi,該目錄下有兩個檔案:
Initiatorname.iscsi和iscsid.conf
1.1.2 啟動ISCSI服務
安裝完iscsi服務預設是關閉的,需要手工啟動
[root@linux ~]# cd /etc/init.d
[root@linux ~]# ./iscsi start

1.1.3 搜尋盤陣
執行以下命令搜尋target,即目標端:7612i儲存
[root@linux ~]#iscsiadm --mode discovery --type sendtargets --portal 192.168.1.221

以上IP即是7612i的iscsi口的IP,其它固定。
1.1.4 顯示盤陣
顯示儲存端target name
[root@linux ~]# iscsiadm --mode node

顯示結果與在7612i串列埠 iscsi management→iscsi node名字相同
1.1.5 登陸盤陣
target登陸
[root@linux ~]#iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 --login

    其中targetname即是步驟4中結果。(注:橫杆是中槓)
(注:3,4,5實施中是在/etc/iscsi下執行,是否可以在別的路徑執行,可自行測試。以上3個命令格式是從man iscsiadm查出)
1.1.6 設定自動啟動盤陣服務
經過以上幾步,fdisk –l就可以看到所掛接分割槽了,為確保重啟後也能看到,再修改一下/etc/iscsi/iscsid.conf,將第5步的命令iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 --login
[root@linux ~]# vi /etc/iscsi/iscsid.conf
iscsiadm --mode node --targetname targetname --portal 192.168.1.221:3260 –login

新增到該檔案中的開始部分
*****************
# Startup settings
#*****************   這個欄下面即可。
其實這個檔案大多數內容處於被註釋狀態,該命令新增位置應該影響不大.然後重啟電腦後直接fdisk –l 依然可以看到所掛接的分割槽。至此iscsi所有操作完成,但掛載的分割槽不是linux所識別,必須使用FDISK進行磁碟分割槽。
1.2 設定分割槽
1.2.1 使用fdisk命令進行磁碟分割槽
fdisk是各種Linux發行版本中最常用的分割槽工具,是被定義為Expert級別的分割槽工具。我們可以透過fdisk來分割槽使用iscsi裝置。它還包括一個二級選單,首先輸入命令,然後出現問答式介面,使用者透過在這個介面中輸入命令引數來操作fdisk。
# fdisk /dev/hdb
執行後出現fdiak的命令提示符:
Command (m for help):
使用n命令建立一個分割槽,會出現選擇主分割槽(p primary partition)還是擴充套件分割槽(l logical)的提示,通常選用主分割槽。然後按照提示輸入分割槽號(Partion number(1-4):)、新分割槽起始的磁碟塊數(First Cylinder)和分割槽的大小,可以是以MB為單位的數字(Last cylindet or +siza or +sizeM or +sizeK:)。例如:
[root@linux ~]#fdisk /dev/sdb
檢視分割槽,如果是第一次操作時,顯示為無。
Command (m for help):p
 
Disk /dev/sdb:255 heads, 63 sectors, 4427 cylinders
Units = cylinders of 16065 * 512 bytes
 
Device Boot    Start       End    Blocks   Id  System
建立分割槽
Command (m for help):n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4427, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-4427, default 4427):
Using default value 4427
儲存分割槽資訊
Command (m for help):w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING:If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

1.2.2 現在驗證新分割槽:
[root@linux ~]# fdisk /dev/sdb
 
The number of cylinders for this disk is set to 4427.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):p
 
Disk /dev/sdb:255 heads, 63 sectors, 4427 cylinders
Units = cylinders of 16065 * 512 bytes
 
Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1      4427  35559846   83  Linux
 
Command (m for help):q

1.2.3 格式化分割槽
[root@localhost ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
214761472 inodes, 429495759 blocks
21474787 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
13108 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
            102400000, 214990848
 
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 

1.2.4 設定載入點:
檔案系統必須有一個掛載點,它只是一個空的目錄,新檔案系統在這裡與系統目錄樹“相連”。經過以上的操作,我的 Linux伺服器已經連線到 iSCSI 儲存裝置, 並且如同Linux 本機上面的一個 SCSI 硬碟一樣。 使用的方式幾乎一模一樣。
假設iSCSI 主機掛載到 /cluster/raid 目錄下:
[root@linux ~]# mkdir /cluster/raid
[root@linux ~]# mount  /dev/sda1 /cluster/raid
[root@linux ~]# df
Filesystem       1K-blocks          Used    Available  Use%  Mounted on
/dev/hda1         10080488       2950408     6618012   31%   /
tmpfs              5036316         81172     4699312   0%    /dev/shm
/dev/sda1       1914788196      27040372  1790482212   2%    /cluster/raid

1.2.5 設定自動掛載:
在機器重新啟動後自動載入分割槽,你必須在/etc/fstab中加入相應分割槽,但分割槽型別必須市"_netdev".例如載入的分割槽sdb1:
 
[root@linux ~]# vi /etc/fstab
/dev/sdb1   /cluster/raid   ext3    -_netdev     0   0
/dev/sdc1   /data/sdc1      ext3    _netdev     0   0
/dev/sdd1   /data/sdd1      ext3    _netdev     0   0

1.2.6 檢視掛載分割槽:
[root@localhost ~]# df -h
檔案系統              容量    已用     可用     已用%      掛載點
/dev/sda1              64G    5.6G      55G     10%         /
tmpfs                 1.7G       0     1.7G      0%         /dev/shm
/dev/sdb1             1.6T    197M     1.5T      1%         /data/sdb1
/dev/sdc1             1.6T    197M     1.5T      1%         /data/sdc1  

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27036311/viewspace-1061192/,如需轉載,請註明出處,否則將追究法律責任。

相關文章