4.6.1 ISCSI網絡存儲

 

目前計算機領域的存儲解決方案主要有直連存儲(DAS)、存儲區域網絡(SAN)、以及網絡附加存儲(NAS)三種。

DASDirect-Attached Storage)指的是主機總線直接通過SCSI接口與存儲設備相連,這種連接方式主要應用在家庭個人電腦環境中。

SANStorage Area Network)指的是一整套存儲網絡的解決方案,SAN採用的是光纖通道技術,SAN就是通過光纖交換機將服務器與存儲設備連接在一起的網絡整體環境,SAN的優勢在於其先進的光纖通信技術,爲當今爆炸式的數據增長環境提供了快速高效的存儲方案。

NASNetwork-Attached Storage)可以使用普通的網絡環境,通過以太網交換機等設備連接服務器與存儲設備,NAS的優勢在於無需對網絡環境進行改造,NAS可以使用現有的網絡環境,而且不同廠家的設備只要使用TCP/IP協議,就可以滿足設備之間對兼容性的要求,NFSCIFS就屬於網絡附加存儲的解決方案,它們都提供了對文件系統的共享。

由於傳統的SAN需要價格昂貴的光纖設備作爲基礎,所以現在又有了基於IP技術的SAN,可以通過IP網絡進行數據存儲,服務器在不進行任何改造的情況下使用現有的以太網卡就可以訪問IP SANISCSI就是這樣的技術)。

NASSAN的主要區別在於,NAS共享的是文件系統,SAN共享的是塊設備。

本節重點關注ISCSI網絡存儲與數據同步rsync系統。

 

4.6.1 ISCSI網絡存儲

ISCSIInternet Small Computer System Interface)是典型的IP-SAN技術,是基於因特網的SAN存儲技術,該技術使得我們可以在基於IP協議的網絡上傳輸SCSI命令,在ISCSI環境中,客戶端(initiators)發送SCSI命令給遠程的SCSI存儲設備(targets),實現數據的存儲與備份功能。ISCSI使用TCP8603260端口進行通信。

ISCSISCSI最大的區別在於ISCSI擺脫了存儲設備的距離限制,使得任何主機都可以通過局域網或廣域網訪問我們的存儲設備,而對於數據中心而言,這是至關重要的。

下面我們將在Centos 6.3中部署一個ISCSI服務器以及客戶端訪問的環境。

1. 部署ISCSI服務

Centos 6.3平臺上部署ISCSI服務需要安裝target軟件,安裝完成後,可以通過命令或修改配置文件這兩種方式部署ISCSI服務。

如果需要使用命令配置服務,可以參考tgtadm命令的man手冊,其中有詳細的示例。以下操作將使用修改配置文件的方式來進行,先弄清楚兩個概念:LUNIQN

LUNLogic Unit Number)是設備的邏輯單元號,一般爲一個數字,我們使用LUN來標識存儲設備。

IQNISCSI Qualified Name)爲ISCSI合格名稱,一般格式爲iqn.yyyy-mm<reversed domain name>:identifier,其中,yyyy代表年,mm代表月,reversed domain name是域名的反寫,identifier爲標識名稱。

部署ISCSI服務器時,首先需要安裝scsi-target-utils軟件。默認的服務器配置文件爲/etc/tgt/targets.conf,我們需要在配置文件添加共享設備,爲共享設備創建LUNIQN

[root@instructor ~]# yum -y install scsi-target-utils
[root@instructor ~]# vim /etc/tgt/targets.conf 
<target iqn.2014.08.com.example.instructor:disk1>   
  backing-store /dev/sdb3    
 backing-store /dev/sdb5 
</target>  
<target iqn.2014-08.com.example.instructor:disk2>   
  backing-store /dev/sdc3    
 lun 10    
 vendor_id jacob Inc.   
  incominguser tom tompass12 
</target> 
<target iqn.2014.08.com.example.instructor:disk3>    
 backing-store /dev/sdd3   
  lun 20    
 initiator-address 192.168.0.102   
  incominguser tom tompass12 
</target>    
[root@instructor ~]# service tgtd restart && chkconfig tgtd on

 

/etc/tgt/targets.conf配置文件說明如下。

第一個target定義了兩個LUNLUN編號會自動按順序分配給LUN1LUN2LUN0一般會分配給SCSI控制器。默認允許所有人訪問該target/dev/sdb3/dev/sdb5是準備共享的設備,通過backing-store指定設備路徑,backing-store支持文件或塊設備。此外,也可以使用direct-store指定設備路徑,但direct-store僅支持本地SCSI設備。

第二個target定義了一個LUNLUN編號爲手動配置的10,共享設備是/dev/sdc3,手動修改設備的廠家信息爲jacob Inc.。此外,通過 incominguser選項將該target設置爲僅允許tom賬戶訪問,密碼爲tompass12

第三個target定義了一個LUNLUN編號爲20,共享設備爲/dev/sdd3,僅允許tom賬戶通過192.168.0.102主機訪問該target

backing-store 後備存儲,一般指非實際的物理盤、如lv卷、某個分區、文件組成的塊設備
direct_store 直接存儲,與backing-store相對,指實際的物理磁盤,如整個硬盤
initiator-address 使用chap認證協議,由target來認證initiator端,格式爲"incominguser username userpassword"
outgingUsername 使用chap認證協議,由initiator來認證target端,格式爲"outgoingusername username userpassword",較少使用

當服務器端啓動tgtd服務後,隨時可以通過tgtadm命令來查看ISCSI的詳細信息。以下tgtadm的輸出內容爲精簡後的部分輸出結果。

[root@instructor ~]# tgtadm --lld iscsi --op show --mode target( tgt-admin -s)
Target 1: iqn.2014-08.com.example.instructor:disk2
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 10
            Type: disk
            SCSI ID: IET     0001000a
            SCSI SN: beaf110
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc3
            Backing store flags: 
    Account information:
        tom
    ACL information:
        ALL
Target 2: iqn.2014.08.com.example.instructor:disk1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 1
            Type: disk
            SCSI ID: IET     00020001
            SCSI SN: beaf21
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb3
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00020002
            SCSI SN: beaf22
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb5
            Backing store flags: 
    Account information:
    ACL information:
        ALL
Target 3: iqn.2014.08.com.example.instructor:disk3
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 20
            Type: disk
            SCSI ID: IET     00030014
            SCSI SN: beaf320
            Size: 1086 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdd3
            Backing store flags: 
    Account information:
        tom
    ACL information:
        192.168.0.102

 

2. 客戶端訪問

Linux客戶端訪問ISCSI服務器需要安裝iscsi-initiator-utils軟件包。第一部,通過iscsiadm命令的discovery選項可以發現服務器端ISCSIIQN。第二步,通過login選項加載服務器的IQN

[root@desktop24 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.254
Starting iscsid:                                           [  OK  ]
192.168.0.254:3260,1 iqn.2014-08.com.example.instructor:disk2
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk1
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk3
[root@desktop24 ~]# iscsiadm -m node -T iqn.2014.08.com.example.instructor:disk1 -p 192.168.0.254 -l

 

如果想開機自動掛載此硬盤的話需要,注意這裏不是default,而是_netdev

[root@desktop24 ~]# echo '/dev/sdc1 /iscsi_ceshi ext4 _netdev 0 0' >> /etc/fstab

 

查看當前鏈接狀態

[root@desktop24 ~]# iscsiadm -m node -S
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk3
192.168.0.254:3260,1 iqn.2014.08.com.example.instructor:disk1
192.168.0.254:3260,1 iqn.2014-08.com.example.instructor:disk2

卸載

[root@desktop24 ~]# umount /iscsi_ceshi/
[root@desktop24 ~]# iscsiadm -m node -T  iqn.2014.08.com.example.instructor:disk1 -u
Logging out of session [sid: 2, target: iqn.2014.08.com.example.instructor:disk1, portal: 192.168.0.254,3260]
Logout of [sid: 2, target: iqn.2014.08.com.example.instructor:disk1, portal: 192.168.0.254,3260] successful.

緩存信息還在系統中,下次啓動將自動鏈接

[root@desktop24 ~]# ls /var/lib/iscsi/nodes
iqn.2014.08.com.example.instructor:disk1
iqn.2014-08.com.example.instructor:disk2
iqn.2014.08.com.example.instructor:disk3

刪除緩存信息

[root@desktop24 ~]# iscsiadm -m node -T iqn.2014.08.com.example.instructor:disk
{1,2,3} -o delete

 

客戶端對分區進行加密的配置

[root@desktop24 ~]# vim /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP 
node.session.auth.username = tom 
node.session.auth.password = tompass12 
discovery.sendtargets.auth.authmethod = CHAP 
discovery.sendtargets.auth.username = tom 
discovery.sendtargets.auth.password = tompass12    
 
[root@desktop24 ~]# iscsiadm -m discovery -t st -p 192.168.0.254
[root@desktop24 ~]# service iscsi restart
[root@desktop24 ~]# ls /dev/sd*(全部已自動登錄)
/dev/sdc   /dev/sdd   /dev/sde  /dev/sdf

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章