Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9246431
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 服务器与存储

2012-09-24 12:26:52

2012-09-23 21:32:46|  分类: openfiler系统+fr |  标签: |字号 

RHEL5 - iSCSI(一) 什麼是 SAN / IP-SAN

什麼是 SAN (Storage area Network),他是一種資料儲存裝置(Raw Device),不過他不像是 NAS 可以直接提供存取.他只提供給 Server 資料儲存裝置,讓 Server 能夠有額外的硬碟裝置.因為它可以很彈性的提供給不同的 serve 大小不同的空間,所以常用在大企業中.最早的 SAN 傳輸介面為光纖,但是隨著 1G,10Gb 網卡(有一種專門用在 iSCSI 的網卡,因為有 TOE:TCP/IP offload engine,它具有運算的功能所以不會因此佔用系統上的 CPU 的使用率)的上市,網卡的傳輸頻寬增加,網卡也可以擔任光纖提供的頻寬(光纖的頻寬為 2G,4Gb,光纖短波-850 mm,長波-1310 mm),這個技術稱為 iSCSI(Internet SCSI),也因此以網卡為傳輸為介質的 SAN,被稱為 IP-SAN.
相關廠商 : EMC / NetApp / FalconStor

常見的 IP-SAN 有 iSCSI / FCoE / FCP / AoE

RHEL5 - iSCSI(二) 安裝 iSCSI Target / initiator

Initiator 指的是 "使用磁碟" 的主機端, Target 指的是 "提供磁碟" 的伺服器端.

iSCSI Target
iSCSI 是一種 SAN的裝置而 SAN的裝置主要是提供 Server 儲存體的空間.相較於傳統的 SAN 是以光纖為傳輸媒體而 iSCSI(Internet SCSI)他是 IP-based 的資料儲存的裝置.使得他能更容易應用在企業中. 1.一般的網卡就能當作 iSCSI Target 但是缺點就是會消耗太多的 CPU 資源,針對這樣的問題所以發展出另外兩種的 iSCSI Target 網卡.2.一種是軟體的 iscsi + TOE (TOE:TCP/IP offload engine),它可以針對 TCP/IP 的封包直接在網路卡上運算所以不會因此佔用系統上的 CPU 的使用率,  3.另外一種就是硬體式的 iSCSI + TOE. 它除了具有 TOE 還可以直接針對 iSCSI 的資料做運算.基本上它的使用上就像是一般儲存裝置 HBA.你可以直接在 BIOS 選項作 iSCSI 硬體開機的動作.

note: SCSI Port - SCSI Protocol

在 RedHat 5 之前的版本是不支援 iSCSI Target 的,所以建議大家使用 iet(iSCSI Enterprise Target) :   但是這一版本的 iSCSI Target 現在看起來已經沒有在更新了加上 RHEL5 已經包含了 iSCSI Target 的服務.所以現在就不再使用 iet(iSCSI Enterprise Target) 有興趣的可以參考一下之前的文章 

安裝啟動 iSCSI target:
在 RHEL5 光碟中的 /ClusterStorage/ 目錄會找到 scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm 檔案這就是 iSCSI Target 的程式.一開始沒選擇全部安裝還需要 perl-Config-General 這一個套件.

[ ~]# rpm -ivh /media/cdrom/ClusterStorage/scsi-target-utils-0.0-0.20070620snap.el5.i386.rpm
[ ~]# service tgtd start
[ ~]# chkconfig tgtd on

安裝啟動 iSCSI initiator:
在 RHEL5 光碟中的 /Server/ 目錄會找到 iscsi-initiator-utils-6.2.0.868-0.18.el5 檔案這就是 iSCSI initiator 的程式

[ ~]# rpm -ivh iscsi-initiator-utils-6.2.0.868-0.18.el5
[ ~]# service iscsi start
[ ~]# chkconfig iscsi on
RHEL5 - iSCSI(三) 建立 iSCSI Target controller device

目前我的環境如下所示:
1. RHEL5 Server - 當作 iSCSI Target 端,
    2顆硬碟,一個是 OS 另外一個就是給 iSCSI 當做分享出來的 raw devices 所使用.
2. RHEL5 Client - 當作 iSCSI Initiator 端.
3.Switch - 因為是 IP-SAN 所以不需要 Fiber switch,原來的 Network Switch 即可使用.建議使用 1Gb 以上的環境.

第一步是新增 controller device 其中的 iqn(iSCSI Qualified Name)格式如下 iqn.yyyy-mm.[:identifier] 名稱最好是根據 iqn 來命名.不像是 iet(iSCSI Enterprise Target) 是將設定寫在檔案,要使用 tgtd 必須使用指令來完成設定動作.不過很貼心的是你在 /usr/share/doc/scsi-target-utils-0.0/README.iscsi 檔案都可以找到範例.

[ ~]# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2009-4.tw.benjr:storage

--tid : 這個 id 必須唯一,當我們在指派硬體資源(如硬碟空間)時就是依據此 id 來看是指派給哪一個 iqn.
-T : iqn(iSCSI Qualified Name)
先來看一下剛剛的指令做了什麼.

[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
           
 Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
    Account information:
    ACL information:

lun0 是個用來管理的 controller device,是自動產生而且一但建立就無法移除.

RHEL5 - iSCSI(四) 指定硬碟空間給 iSCSI Target

剛剛建立好了 iqn 接下來就是要 指定硬碟空間給 iSCSI Target.

[ ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1

--tid 1 : 還記得剛剛設定的 tid 吧!!
--lun 1 : 除了剛剛自動建立好的 lun 0 ,第一個指定為 lun1,以此類推.
通常 SCSI RAID 會用多顆 SCSI HD 組合成一個邏輯裝置(LUN),SCSI 控制器就可以使用單一的邏輯裝置來做存取. 
-b /dev/sdb1 : 除了一般 partition 外還可以用  LVM.一般系統廠商所提供的 iSCSI Target 也都是配合 LVM 來運作.
LVM(Logical Volume Manager)是一種可以動態變更磁區大小的方式,可以讓你能更容易利用管理你的硬碟. 

除了可以指定一般的 partition 當作 iSCSI Target 端的 Lun 之外還可以使用 file 當作 block device.方式一樣原先指定 partition 給他換成 file 就可以了!不過先要建立一個檔案是空的.

[ ~]# dd if=/dev/zero of=iscsidisk bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 18.005 seconds, 59.6 MB/s

沒有出現錯誤訊息你會看到和我一樣的 lun1 對應到 /dev/sdb1 ,lun2 對應到  /root/iscsidisk

[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
        LUN: 2
            Type: disk
            SCSI ID: deadbeaf1:2
            SCSI SN: beaf12
            Size: 1G
            Backing store: /root/iscsidisk
 
   Account information:
    ACL information:

先移除掉 lun 2 一開始還不需要這麼多的 lun,移除的指令會在後面說明.

[ ~]# tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 2
RHEL5 - iSCSI(伍) iSCSI Target ACL

iSCSI Target 預設是不讓任何人存取,除非設定了 ACL(Access Control List). 一開始在實驗階段可以用 ALL 讓任意的 Initiator 都可以存取.

[ ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL

--tid 1 : 還記得剛剛設定的 tid 吧!!
-I ALL  : 不限制任何 IP 的 initiators 都可以來存取這個 iSCSI Target.  (-I : 大寫的 i;ALL 必須都為大寫才會生效)) 

[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
    ACL information:
        ALL

不過沒人希望什麼阿貓阿狗的 initiators 都來使用我這一台 iSCSI Target.先把 "ALL" 移除.ALL 比較適合使用在 iSCSI Boot.

[ ~]# tgtadm --lld iscsi --op unbind --mode target --tid 1 -I ALL
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
    ACL information:

下面使用幾個範例來說明 ACL IP 的指定方式:

[ ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.8.1.121
[ ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.8.1.0/24
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
    ACL information:
        192.8.1.121
        192.8.1.0/24

你除了可以指定特定 IP : 192.8.1.121 的 initiator 可以存取此 iSCSI Target device外還可以針對相同網域的 IP: 192.8.1.0/24 來設定.

RHEL5 - iSCSI(六) iSCSI initiator

目前 RHEL5 提供一支程式 "iscsiadm" 我們只要透過這一支程式就可以讓 initiator 去連接 Target 端的硬碟. iscsiadm 原自於 open-iscsi 關於指令問題可以參考  的詳細說明.

[root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 192.8.1.55:3260
192.8.1.55:3260,1 iqn.2009-4.tw.benjr:storage

"iqn.2009-4.tw.benjr:storage" 這就是192.8.1.55:3260 的 iqn.
-p : iSCSI target 的 IP . iSCSI 預設使用的 port 是 3260.
-T : 指定 target_iqn_name 
-l: login

[root@localhost ~]# iscsiadm -m node -T iqn.2009-4.tw.benjr:storage -p 192.8.1.55:3260 -l
Logging in to [iface: default, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]
Login to [iface: default, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]: successful
[root@localhost ~]# iscsiadm -m session
tcp: [1] 192.8.1.55:3260,1 iqn.2009-4.tw.benjr:storage

在 iSCSI Target 端也會看到 iSCSI Initiator 是否有連接.

[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
        I_T nexus: 4
            Initiator: iqn.1994-05.com.redhat:116f23e2ef8
            Connection: 0
                IP Address: 192.8.1.121

    
LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
    ACL information:
        192.8.1.121
        192.8.1.0/24

如果成功連接上 iSCSI target它使用的方式就如同一般的硬碟.

[ ~]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       60801   488279610   8e  Linux LVM

Disk /dev/sdb: 10.0 GB, 10010133504 bytes
64 heads, 32 sectors/track, 9546 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System

想登出或是移除 iSCSI initiator 設定時使用:
-u: (logout) 相同 Login 的指令但使用參數 -u 
-o delete : 可以移除掉 Target 的連結.只會在下一次重新啟動 iSCSI 才有效.

[root@localhost ~]# iscsiadm -m node -T iqn.2009-4.tw.benjr:storage -p 192.8.1.55:3260 -u
Logging out of session [sid: 1, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]
Logout of [sid: 1, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]: successful
[ ~]# iscsiadm -m node -T iqn.2009-4.tw.benjr:storage -p 192.8.1.55:3260 -o delete

RHEL5 - iSCSI(七) 從 iSCSI Target 移除硬碟

剛剛我們指定了一個硬碟 /dev/sdb1 給 iSCSI Target ,現在我們再透過指令新增另外一個硬碟 /dev/sdb2 ,後面就是這一次的重點如何移除指定好的硬碟.

[ ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /dev/sdb2
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
        I_T nexus: 3
            Initiator: iqn.1994-05.com.redhat:116f23e2ef8
            Connection: 0
                IP Address: 192.8.1.121
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
        LUN: 2
            Type: disk
            SCSI ID: deadbeaf1:2
            SCSI SN: beaf12
            Size: 9G
            Backing store: /dev/sdb2

    Account information:
    ACL information:
        192.8.1.121
        192.8.1.0/24

透過參數 --op delete 去移除 --lun2 也就是 /dev/sdb2 的硬碟空間.

[ ~]# tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 2
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
        I_T nexus: 3
            Initiator: iqn.1994-05.com.redhat:116f23e2ef8
            Connection: 0
                IP Address: 192.8.1.121
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
    ACL information:
        192.8.1.121
        192.8.1.0/24

很好 --lun 2 已經不存在了.不過很可惜是剛剛所有使用 tgtadm 指令設定 iSCSI Target 在重新開機後就不存在了,所以建議將剛剛幾個指令寫在 /etc/rc.local 檔案中.

RHEL5 - iSCSI(八) CHAP 身分驗證

除了指定 IP 做 ACL 還可以透過 user / password (CHAP-Challenge Handshake Authentication Protocol 使用 MD5 的加密驗證) 來做身分驗證.

CHAP 有很多種除了
1.單向 CHAP 驗證:在此安全性等級,只有目標 Target 會做驗證.另外一種是 
2.相互(Mutual) CHAP 驗證:在此安全性等級,目標 Target 與啟動器 Initiator 皆會被彼此做驗證.最後是
3.Reverse CHAP驗證:一般的 CHAP 使用 one-way hash,密碼檔無法回朔,但是使用 Reverse CHAP 是可以的.關於 Reverse CHAP 目前網路上我還查不太到很多的資料所以無法做說明.

先來說明第一種 單向 CHAP 驗證CHAP(Challenge Handshake Authentication Protocol)

預設 iSCSI 採用了 單向 CHAP(Challenge Handshake Authentication Protocol) 的身分驗證方式,基本上是一種以 MD5 的加密驗證方式.方式如下:

1. 在雙方(Target / Initiator) 建立連線後,Target 送出 "challenge" 的訊息告知 Initiator 要做身分驗證.
2. Initiator 會將使用者密碼使用 md5 做 one-way hash 並送出去給 Target 端.
假如使用者密碼是 :123456 ,md5 做過 one-way hash 之後變成 : f447b20a7fcbf53a5d5be013ea0b15af
3. Target 端將以經過 md5 的密碼和 Initiator 做比對,如果比對正確,這身份驗證及成立要不然就會將此次連結做中斷.
Target 端並沒有將原先密碼儲存下來,而是將密碼紀錄成做過 one-way hash  的 f447b20a7fcbf53a5d5be013ea0b15af.如果兩邊的 md5 一樣即代表成立.
4. 在正常連線過程中會不時重復做 1~3 的 CHAP 身分驗證.

為什麼身分驗證會採用 One Way Hashes 其優點是原資料已經不存在,傳送在網路上不需怕密碼檔被盜取.

note : One Way Hashes
One Way Hashes 主要會產生一組固定長度字串(fingerprint or message digests),這組字串用來比對原資料是否遭到修改,它的特性如下
1.原資料輸入長度為可變
2.輸出的 fingerprint 為固定長度
3.當資料任何 byte 改變時, fingerprint 也會變的完全不同
4.我們無法依據 fingerprint 來回推成原資料,這也是為什麼稱為 One Way hash(單方向的資料運算,函數多對一的特性)
既然無法回推成原資料,那怎知資料是否正確, One Way hash 會再將資料再做一次 One Way hash 然後直接比對 fingerprint 是否一樣.

不過所有的連線還是會受到 ACL 的限制, CHAP 只是多加上一層保護.先將之前設定先取消,將 ACL 改成 ALL.

[ ~]# tgtadm --lld iscsi --op unbind --mode target --tid 1 -I 192.8.1.121
[ ~]# tgtadm --lld iscsi --op unbind --mode target --tid 1 -I 192.8.1.0/24
[ ~]# tgtadm --lld iscsi --op unbind --mode target --tid 1 -I ALL

iSCSI 的帳號跟本地端的 Linux 帳號密碼無關,所以必須透過 "tgtadm" 來建立.

[ ~]# tgtadm --lld iscsi --op new --mode account --user benjr --password benjr
[ ~]# tgtadm --lld iscsi --op show --mode account
Account list:
    benjr

帳號是建立好了還要將他指定到哪一個 target.

[ ~]# tgtadm --lld iscsi --op bind --mode account --tid 1 --user benjr
#使用 --op unbind 可以將這使用者從這 iqn 移除.
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
        I_T nexus: 4
            Initiator: iqn.1994-05.com.redhat:116f23e2ef8
            Connection: 0
                IP Address: 192.8.1.121
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
        benjr
    ACL information:
        ALL

iSCSI initiator 如要使用 CHAP 登入 Target,我們需要修改 /etc/iscsi/iscsid.conf, node.session.auth.username 和 node.session.auth.password 都要修改剛剛設定好的 --user benjr --password benjr .
incoming 或是 outgoing 的 password 和 username 的最大限制是 256 字元.

[~]# cat /etc/iscsi/iscsid.conf
n
ode.session.auth.username = benjr
node.session.auth.password = benjr
RHEL5 - iSCSI(九) 相互(Mutual) CHAP incoming / outgoing 驗證

相互(Mutual) CHAP 驗證:CHAP 的認證端可為 Target(Incoming Authentication) 或是 Initiator(Outgoing Authentication) 任一端來認證.也就是說 Target(Incoming Authentication) 是由 Target 端為 Initiator 認證.這樣的認證方式可以允許多個 Initiator 來連接到 Target.而 Initiator(Outgoing Authentication) 是由 Initiator 來認證 Target 端.

之前我們都是在 Target 端設定帳號密碼,這就是使用 Incoming Authentication 是由 Target 端為 Initiator 認證.要同時使用 Outgoing Authentication 也很簡單.只要指定 outgoing 的 user 和 password

剛剛已經設定過 Incoming 的認證方式,現在要透過 "tgtadm" 來建立 Outgoing 的認證.

[ ~]# tgtadm --lld iscsi --op new --mode account --user in_benjr --password in_benjr --outgoing
[ ~]# tgtadm --lld iscsi --op show --mode account
Account list:
    benjr
    in_benjr

帳號是建立好了還要將他指定到哪一個 target.

[ ~]# tgtadm --lld iscsi --op bind --mode account --tid 1 --user benjr --outgoing
[ ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2009-4.tw.benjr:storage
    System information:
        Driver: iscsi
        Status: running
    I_T nexus information:
        I_T nexus: 4
            Initiator: iqn.1994-05.com.redhat:116f23e2ef8
            Connection: 0
                IP Address: 192.8.1.121
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: deadbeaf1:0
            SCSI SN: beaf10
            Size: 0
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: deadbeaf1:1
            SCSI SN: beaf11
            Size: 9G
            Backing store: /dev/sdb1
    Account information:
        benjr
        in_benjr  (outgoing)
    ACL information:
        ALL

iSCSI initiator 如要使用 Outgoing CHAP ,我們需要修改 /etc/iscsi/iscsid.conf, node.session.auth.username_in 和 node.session.auth.password_in 都要修改剛剛設定好的

[ ~]# cat /etc/iscsi/iscsid.conf
node.session.auth.username = benjr
node.session.auth.password = benjr
node.session.auth.username_in = in_benjr
node.session.auth.password _in= in_benjr

參考文件 : 

RHEL5 - iSCSI(十) Intel NIC + iSCSI Remote Boot ROM
硬體需求:
一般的網卡可以擔當 iSCSI initiator 的工作,市面上很多的作業系統(Windows, RHEL , SLES) 都以軟體的方式去支援.但是如果你想將作業系統透過遠端的 iSCSI  SAN 來啟動,是需要透過硬體的 iSCSI 網卡才有辦法做到.

雖然 RHEL5 在安裝時就可以選擇由 iSCSI Boot . 不過很可惜的是,如果你的 BIOS 不支援從 iSCSI Boot,那安裝完系統後就再也開不了機,因為一般 BIOS 只能從當地端的硬碟開機(硬體的 iSCSI 會被視為當地硬碟),目前只有 EFI(Extensible Firmware Interface,目前是由 Intel 主導,主要目的是取代現前使用的 BIOS) 的系統會支援從 iSCSI Boot ,所以呢!!!一般的網卡是軟體的 iSCSI + TOE 還要有 EFI 才能實現由 iSCSI Boot (硬體的 iSCSI 不在此限).

但是最近在查詢 iSCSI 的資料時發現了 Intel 出了 Intel? iSCSI Remote Boot 這個 ROM 就包含了 iSCSI Boot 的功能.它可以讓你原先的 Intel 網卡直接透過他提供的功能能夠從遠端的 iSCSI 直接開機.下載點在    方式也不難.
 
不過在使用這 Intel? iSCSI Remote Boot 有其限制,它主要是針對Intel PCI-Express Server 等級的 Gigabit family 網卡所設計的.所以如果你手上有下面這幾張卡就可以使用.

  • Intel? Gigabit CT Desktop Adapter(Controller:82574L)
  • Intel? Gigabit ET Dual Port Server Adapter(Controller:82576)
  • Intel? Gigabit EF Dual Port Server Adapter(Controller:82576)
  • Intel? Gigabit ET Quad Port Server Adapter(Controller:82576)
  • Intel? PRO/1000 PT Quad Port Server Adapter(Controller:82571EB)
  • Intel? PRO/1000 PT Quad Port LP Server Adapter(Controller:82571EB)
  • Intel? PRO/1000 PF Quad Port Server Adapter(Controller:82571EB)
  • Intel? PRO/1000 PT Dual Port Server Adapter(Controller:82571EB)
  • Intel? PRO/1000 PF Dual Port Server Adapter(Controller:82571EB)
  • Intel? PRO/1000 PT Server Adapter(Controller:82572EI)
  • Intel? PRO/1000 PF Server Adapter(Controller:82572EI)
  • Intel? Gigabit PT Quad Port Server ExpressModule(Controller:82571)
  • Intel? 10 Gigabit AF DA Dual Port Server Adapter(Controller:82598EB)
  • Intel? 10 Gigabit AT Server Adapter(Controller:82598EB)
  • Intel? 10 Gigabit XF SR Server Adapter(Controller:82598EB)
  • Intel? 10 Gigabit XF LR Server Adapter(Controller:82598EB)
  • Intel? 10 Gigabit XF SR Dual Port Server Adapter(Controller:82598EB)
  • Intel? 10 Gigabit CX4 Dual Port Server Adapter(Controller:82598EB)

這下載檔案中還包含了 iSCSI Remote Boot 的 driver,幾乎是市面上常用的作業系統都包含在裡面.

  • Microsoft* Windows* Server 2003 SP1, SP2, R2 x86
  • Microsoft Windows Server 2008 x86
  • Red Hat* Enterprise Linux 4 U3, Red Hat* Enterprise Linux 5
  • Novell SUSE* Linux Enterprise 9 SP3, Novell SUSE* Linux Enterprise 10

更新 iSCSI Remote Boot ROM:
Intel 提供的這一之工具 Intel iSCSI Network Adapter Boot Configuration Utility (iSCSIUtl) 是一隻 DOS 的程式,所以第一步就是先回到 DOS 先行更新 Intel NIC firmware 的 iSCSI Remote Boot ROM.在剛剛下載的檔案中解開後會發現目錄 iSCSIUtl\DOS\iscsiutl.exe 就是更新 Intel NIC 的 iSCSI Remote Boot ROM 的主程式.使用方式也很簡單: 
iSCSIUtl -[OPTION] or -[OPTION]=[VALUE]

C:\iscsiutl -all -up
Intel(R) iSCSI Boot Utility
iSCSIUtl version 2.3.17.00
Copyright (C) 2003-2009 Intel Corporateion
 
Programming flash on part 1 with iSCSI Boot image
An Intel(R) Boot Agent setting has been detected on this device. Programming
this device with Intel(R) iSCSI Boot will erase this setting.
 

Would you like to continue? (Y)es or (N)o:Y

*
Flash update successful.
 
Flash not enabled on port 2
 
Use the "-FLASHENABLE" parameter to enable to flash
 
Port Network Address Series  WOL Boot ROM Type           Version
==== =============== ======  === ======================= =======
1    001517785DD6    Gigabit YES iSCSI Enabled           2.3.17  
2.   001517785DD7    Gigabit N/A FLASH Disabled          2.3.17  

上面的指令會找出任何包含 pre-installed Intel Boot Agent image 的網卡,通常兩個埠的網卡第一個埠會被更新.系統會詢問你是否更新回答 Y(yes) 系統就會開始更新,如果你需要更新其他的網路埠時可以指定埠來更新.
ISCSIUTL -NIC=1 -FLASHENABLE

等系統重新開機後你會發現 Intel 的網卡的 Option ROM 變的不一樣.

Intel(R) iSCSI Boot version 2.3.17
Copyright (c) 2003-2009 Intel Corporation. All rights reserved.
Press ESC key to skip iSCSI boot initialization.
Press to run setup...

按下 就可以進入 Intel iSCSI Remote Boot 的 Option ROM.針對 iSCSI initiator 端作設定.

設定 iSCSI Remote Boot
接下來我們就可以直接在 Intel 的 Option ROM 上設定 iSCSI Target 所指定的 Lun ,如果你沒有硬體的 iSCSI Target 端也沒關係,你可以先用 RHEL5 的 iSCSI Target 端的功能 先進入 Intel iSCSI Remote Boot 的 option ROM.

進入 iSCSI Remote Boot Port Selection Menu 你可以看到目前系統所有的 Intel iSCSI Remote Boot-capable adapters.你可以在此頁面看到系統上 Intel 網卡的 PCI device ID, PCI bus/device/function 以及 MAC Address

這裡最多可以顯示出來 10 iSCSI Remote Boot-capable ports ,超過系統就顯示不出來了,我想一台 Server 要超過 10 個網路埠的機會不大.這裡需要做說明的是 iSCSI Remote Boot status ,也就是顯示在最後的 BOOT:PRIMARY, BOOT:DISABLED

Boot 的選項可以分成下面幾種.

  • Primary:

    當網路埠選擇成 Primary(按 'P' 鍵可以把狀態改變成 Primary) Intel iSCSI Remote Boot 會以此當作連上 iSCSI Target 為第一優先設定值.當系統有多個網路埠時只能有一個 Primary.

  • secondary:

    當網路埠選擇成 secondary(按 'S' 鍵可以把狀態改變成 secondary) , 只有當 Primary 連線失敗時 secondary 才會向 iSCSI Target 要求連線.當系統有多個網路埠時只能有一個 secondary.

  • 按 'D' 鍵可以把 iSCSI Remote Boot 網路埠的功能暫停使用.
  • 按 'B' 鍵可以讓網路埠的 LED 閃爍.
  • 按 'ESC' 鍵可以離開設定.

前面更新 iSCSI Boot ROM 時我只針對一個 port 做更新,所以我們只會看到一個狀態是 PRIMARY 另外一個是 DISABLED.

選擇你的網卡之後進入 iSCSI setup menu 主要的選項有四種:
  • iSCSI Remote Boot Configuration

    這邊的設定就是 iSCSI Remote Boot initiator 和 target 的選項包括了 IP ,name 以及 Boot Lun 皆是在裡設定.

  • CHAP Configuration

    預設 iSCSI 採用了 CHAP(Challenge Handshake Authentication Protocol) 的身分驗證方式,基本上是一種以 MD5 的加密驗證方式.如果你的系統有採用密碼的保護就需要在這裡做設定.

  • Discard Changes and Exit

    如果剛剛在 iSCSI Remote Boot Configuration 或是 CHAP Configuration 設定不滿意選擇"Discard Changes and Exit" 系統就不儲存剛剛所有的設定了.並且回到上一層 "iSCSI Remote Boot Port Selection Menu

  • Save Changes and Exit

    選擇 "Save Changes and Exit" 就可以將剛剛在  iSCSI Remote Boot Configuration 或是 CHAP Configuration 所設定的記錄下來,並且回到上一層 "iSCSI Remote Boot Port Selection Menu

我們先來設定 "SCSI Boot Configuration"

設定可以分成 "Initiator" 和 "Target" 端,上面那一部分就是本機 "Intel iSCSI Remote Boot " 也就是 "Initiator" 端的設定.

  • Use Dynamic IP Configuration (DHCP)

    如果你的 DHCP 有針對 iSCSI 設定你只要直接勾選由 DHCP 指派 client IP address, subnet mask, and gateway IP address.

  • Initiator Name

    這裡就是設定 iSCSI initiator name 主要是為了讓  iSCSI target 可以辨識 Intel iSCSI Remote Boot 的名稱.

  • Initiator IP

    設定固定的 IP 這 IP 必須要和 Target 同網段也必須能和 Target 建立連線.

  • Subnet Mask

    IP 的 subnet-mask 取決於你的網路 IP 的網段.

  • Gateway IP

    當你的 Target 和 Initiator 處於不同網段時需要 gateway 來轉送封包.

下面半步就是 Target 端的設定,除了 Target Name(就是 IQN ) 輸入時注意不要打錯外,其他就是 iSCSI Target 端的 IP.

  • Use DHCP for iSCSI Target Information

    如果你的 DHCP 有針對 iSCSI 設定你只要直接勾選由 DHCP 指派 iSCSI target's IP address, IP port number, iSCSI target name, and SCSI LUN ID.

  • Target Name

    Target 端的 IQN (iSCSI Qualified Name)格式如下 iqn.yyyy-mm.[:identifier] .

  • Target IP

    iSCSI Target 端的 IP 位置.

  • Target Port

    iSCSI 所使用的 TCP Port Number(預設為 3260).

  • Boot LUN

    通常 SCSI RAID 會用多顆 SCSI HD 組合成一個邏輯裝置(LUN),SCSI 控制器就可以使用單一的邏輯裝置來做存取,通常 LUN 是由 0 開始但是 RHEL5 的 iSCSI Target 的 lun0 是用來當作管理控制 controller device.

iSCSI 採用 CHAP-Challenge Handshake Authentication Protocol(以 MD5 為基礎的加密驗證),來做身分驗證. 單向 CHAP 驗證:在此安全性等級,只有目標 Target 會做驗證.

  • User Name

    iSCSI target 端所設定的 CHAP 使用者名稱.

  • Target Secret

    iSCSI target 端所設定的 CHAP 密碼. 這密碼不可和 Initiator Secret 端所設定的密碼相同.

  • Use Mutual CHAP

    相互(Mutual) CHAP 驗證,在此安全性等級,目標 Target 與啟動器 Initiator 皆會被彼此做驗證

  • Initiator Secret

    iSCSI Initiator Mutual CHAP 密碼.這密碼不可和 Target Secret 端所設定的密碼相同.

如果沒有設定上的錯誤登出之後你可以看到系統會多出一個 iSCSI 的 drive.

Intel(R) iSCSI Boot version 2.3.17
Copyright (c) 2003-2009 Intel Corporation. All rights reserved.
Press ESC key to skip iSCSI boot initialization.

Initializing adapter configuration - MAC address(001517785DD6).
Using STATIC configuration for primary port, please wait.
iSCSI Target Name       : iqn.2009-4.bios:storage
iSCSI Target IP Address : 192.8.1.1
LUN ID: 1                Port: 3260
iSCSI Initiator IP      : 192.8.1.24
iSCSI Gateway IP        : 192.8.1.1
iSCSI Initiator Name    : iqn.ben

Attempting to connect to target disk using MAC address(001517785DD6)


LUN: 1  DEVICE: IET VIRTUAL-DISK  18.63 GB

BIOS Boot Menu
更新完 Intel iSCSI Remote Boot 後在 BIOS 的 Boot Menu 會多出一個 Intel? iSCSI Remote Boot 的選項.下面你看到的是我 IBM 的 Server 每一家的 Boot Menu 顯示出來的都不盡相同.

自從 RHEL5 開始安裝的時候多了一個選項 "Advanced Storage Configuration" ,這選項就是可以讓你從 iSCSI 開機.步驟如下:
選擇 "Add iSCSI Target" 如果你網路環境沒有 iSCSI Target 可以使用 RHEL5 建立出 iSCSI Target 端的服務 

Target IP Address :這就是 iSCSI Target 端的 IP
iSCSI initiator Name : iSCSI Target 所指定的 iqn(iSCSI Qualified Name)

如果順利完成即刻就會看到 iSCSI Target 所指派的硬碟空間.

RHEL5 U3 iSCSI boot 多加了  user / password (CHAP-Challenge Handshake Authentication Protocol 使用 MD5 的加密驗證) 來做身分驗證.
接下來安裝的步驟都會像是安裝在一般硬碟上面.RHEL5 U3 有支援 IBFT(iSCSI Boot Firmware Table) 所以可以直接安裝在這一顆硬碟上安裝作業系統不需要其他 dirver.
RHEL5 - iSCSI(十一) MPIO

iSCSI remote boot 可以透過 MPIO(multipath I/O) 來確保他的連線不會因為單一的網路斷線而失去連線,但是這功能是不是用 teaming (teaming 是一個為通過由多個網卡創建的 team,多張網卡視同一張,可以提供負載平衡 load-balancing,容錯 fault-tolerance 的功能) 一樣就可以解決了.為什麼還會用到 MPIO 這東西.

圖片出自於 
關於這一點在 Intel 的官方網站文件 Intel? PRO/1000 Server Adapter iSCSI and iSCSI Remote Boot Frequently Asked Questions -  
 有提到,這裡面提到的都屬於硬體的 iSCSI remote boot.

Q18: Does Intel iSCSI boot support adapter teaming?
A18: Adapter teaming is not supported on ports configured for iSCSI remote boot due to limitations in the OS stack, which does not support teaming for iSCSI traffic. Storage failover and load balancing support is provided by using MPIO. 

Q16: Is Multipath I/O (MPIO) supported by Intel iSCSI boot?

A16: Intel iSCSI boot solutions use the standard OS iSCSI boot initiators to provide remote boot support, so MPIO and other advanced features are supported for iSCSI boot via the OS initiator once the OS boots.

上面兩個問題提到了一點 " iSCSI remote boot(系統支援由 iSCSI SAN 遠端開機)" 因為 OS 無法在開機時就支援 teaming 所以如果要確保網路品質建議使用 MPIO 這一項功能(需要硬體的 iSCSI 網卡),但是問題二卻談到了目前 Intel 的網卡是否支援 iSCSI MPIO Boot 的功能.答案是不支援.雖然我們在設定 Intel iSCSI Boot 可以選擇 Primary 以及 Secondary 但這不代表這就是支援 MPIO.以 Intel iSCSI NIC 的規則是如果 Primary 的設定連接失敗時才會使用 Secondary 的設定值,也因此這兩路徑不會同時存在.
 
現在我們就來看看如何做到 MPIO 的功能.不過到目前為止我都還沒試成過以硬體的 iSCSI 網卡加上 MPIO 的功能開機成功.下面的例子是在 RHEL5 作業環境下以一般軟體式的 iSCSI Initiator + MPIO.

配置 iSCSI 多路境 MPIO(Multipath),需要同網段的網卡兩個埠,目前我的 iSCSI Target 端為 192.8.1.55

[ ~]# ifconfig | grep 192.8
          inet addr:192.8.1.214  Bcast:192.8.1.255  Mask:255.255.255.0
          inet addr:192.8.1.85  Bcast:192.8.1.255  Mask:255.255.255.0

先確定這兩個埠和 iSCSI Target 互通.

[ ~]# ping -I eth0 192.8.1.55
[ ~]# ping -I eth1 192.8.1.55

iSCSI initiator 預設會依據網路狀態只和 iSCSI Target 建立一個 session,雖然你的網路上同網段的埠有兩個以上.他還是只會建立一個 session.如果我們要使用 iSCSI interfaces (iface) binding 的功能必須要在 /var/lib/iscsi/ifaces 指定多個網路埠.我們可以使用 iscsiadm 的指令來建立.建立 ieth0 和 ieth1

[ ~]# iscsiadm -m iface -I ieth0 --op=new
[ ~]# iscsiadm -m iface -I ieth1 --op=new

ieth0 和 ieth1 真實會指向實體裝置 eth0 和 eth1

[ ~]# iscsiadm -m  iface -I ieth0 --op=update -n iface.net_ifacename -v eth0
[ ~]# iscsiadm -m  iface -I ieth1 --op=update -n iface.net_ifacename -v eth1

除了可以指定網路裝置名稱外 ethx 還可以依據網卡的 MAC address 來指定 "iface.hwaddress",確定一下剛剛建立出來的 ieth0 和 ieth1

[ ~]# iscsiadm -m iface
ieth0 tcp,default,eth0
ieth1 tcp,default,eth1

iscsiadm 主要會在 /var/lib/iscsi/ifaces 目錄下面建立剛剛所設定的 iface 裝置, iscsiadm 會依據這邊的設定同時向 iSCSI Target 建立連線.

[ ~]# cat /var/lib/iscsi/ifaces/ieth0
iface.iscsi_ifacename = ieth0
iface.net_ifacename = eth0
iface.hwaddress = default
iface.transport_name = tcp
[ ~]# cat /var/lib/iscsi/ifaces/ieth1
iface.iscsi_ifacename = ieth1
iface.net_ifacename = eth1
iface.hwaddress = default
iface.transport_name = tcp

當我們只要透過 iscsiadm 這一支程式去向 iSCSI Target  端建立連線時,要特別去指定剛剛我們建立好的 iSCSI interfaces (iface) binding 裝置,這樣就可以讓 iSCSI Initiator 和 iSCSI  Target 端建立多條連線.

[ ~]# iscsiadm -m discovery -t sendtargets -p 192.8.1.55 -I ieth0 -I ieth1
192.8.1.55:3260,1 iqn.2009-4.tw.benjr:storage
192.8.1.55:3260,1 iqn.2009-4.tw.benjr:storage

"iqn.2009-4.tw.benjr:storage" 這就是192.8.1.55:3260 iSCI Target 的 iqn.

[ ~]# iscsiadm -m node --loginall=all
Logging in to [iface: ieth1, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]
Logging in to [iface: ieth0, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]
Login to [iface: ieth1, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]: successful
Login to [iface: ieth0, target: iqn.2009-4.tw.benjr:storage, portal: 192.8.1.55,3260]: successful

登入 iSCSI Target 之後我們會發現多出來兩顆硬碟,不管是大小還是狀態都一樣,這就是 iSCSI Initiator 已經和 Target 端透過兩條路徑建立了不同的連線.接下來就需要設定一下所謂的 MPIO , 在 Linux 下是被稱為 device-mapper multipath

[ ~]#  fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       60801   488279610   8e  Linux LVM

Disk /dev/sdb: 20.0 GB, 20012106240 bytes
64 heads, 32 sectors/track, 19085 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sdc: 20.0 GB, 20012106240 bytes
64 heads, 32 sectors/track, 19085 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System

DM(Device-Mapper) multipath 的設定檔儲存在 /etc/multipath.conf ,我們只需要將系統預設的 blacklist - devnode,將他用 "#"註解掉.讓系統自己來偵測即可.

[ ~]# vi /etc/multipath.conf
blacklist {
#        devnode "*"
}

DM(Device-Mapper) multipath 的服務名稱為 multipathd ,開機啟動時設定 chkconfig ,立即啟用服務使用 service 程式.

[ ~]# chkconfig multipathd on
Start multipathd:

[ ~]# service multipathd start
List multipath devices:

當我將 "multipathd" 的服務啟動之後使用 multipath 指定來觀看可以發現剛剛由 iSCSI Initiator 連線所建立出來的 2 顆硬碟已經其實是指向同一個 SCSI ID 而 DM-Multipath 也確認的出來.

[ ~]# multipath -ll
mpath1 (16465616462656166313a3100000000000000000000000000) dm-2 IET,VIRTUAL-DISK
[size=19G][features=0][hwhandler=0]
\_ round-robin 0 [prio=1][active]
 \_ 7:0:0:1 sdb 8:16  [active][ready]
\_ round-robin 0 [prio=1][enabled]
 \_ 6:0:0:1 sdc 8:32  [active][ready]

我們也可以透過指令 scsi_id 來檢視硬碟裝置的 ID 是否相同.

[ ~]# scsi_id -x -g -u -s /block/sdb
ID_VENDOR=IET
ID_MODEL=VIRTUAL-DISK
ID_REVISION=0001
ID_SERIAL=16465616462656166313a3100000000000000000000000000
ID_TYPE=disk
ID_BUS=scsi
[ ~]# scsi_id -x -g -u -s /block/sdc
I
D_VENDOR=IET
ID_MODEL=VIRTUAL-DISK
ID_REVISION=0001
ID_SERIAL=16465616462656166313a3100000000000000000000000000
ID_TYPE=disk
ID_BUS=scsi

我們透過系統就可以觀看到 /dev/dm 的裝置了.這個裝置就如同一般的硬碟裝置,如同 /dev/sda 你可以針對他做分割,格式化,讀寫等動作.而且還具備 MPIO 的功能.

[ ~]# fdisk -l
Disk /dev/dm-2: 20.0 GB, 20012106240 bytes
255 heads, 63 sectors/track, 2433 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot      Start         End      Blocks   Id  System
/dev/dm-2p1   *           1          13      104391   83  Linux
/dev/dm-2p2              14        2433    19438650   8e  Linux LVM

如果系統沒有自動產生 /dev/dm 的裝置時可以透過程式 kpartx 來產生.

[ ~]# kpartx -a /dev/mapper/16465616462656166313a3100000000000000000000000000

參考資料 : http://blog.chinaunix.net/u3/92556/showart_1842981.html

 
阅读(1252) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~