在 Ubuntu OS 上掛載 iSCSI 磁碟區

瞭解如何在 Ubuntu 上以多路徑 I/O 掛載 Block Storage for Classic 磁碟區,以進行備援的高效能儲存存取。

請按照教學在配備 Ubuntu 作業系統的伺服器上掛載 IBM Cloud® Block Storage for Classic 磁碟區。 您將會建立兩個連線,從主機的一個網路介面連到儲存空間陣列的兩個目標 IP 位址。

有關此 iSCSI 服務在 Ubuntu 作業系統上運作方式的詳細資訊,請參閱 iSCSI 啟動端(或客戶端) 文件。 如果您使用的是其他 Linux® 作業系統,請參閱您所使用發行版的文件,並確認多路徑功能是否支援用於設定路徑優先順序的非對稱邏輯單元存取(ALUA)。

開始之前

  1. 在控制台、CLI、API 或 Terraform中為 Classic 建立虛擬伺服器

  2. 在同一個資料中心 訂購區塊儲存卷

  3. 確定主機已授權存取 Block Storage for Classic 磁碟區。 有關更多信息,請參閱 在控制台授權主機從 CLI 授權主機使用 Terraform 授權主機。 授權完成後,請記下使用者名稱、密碼和主機 IQN 資訊。

如果多個主機裝載相同的 Block Storage for Classic 磁區而未聯合管理,則您的資料有毀損風險。 如果多個主機同時對磁區進行變更,則可能會發生磁區毀損。 您需要群集感知的共享磁碟檔案系統來防止資料遺失,例如 Microsoft Cluster Shared Volumes ( CSV )、Red Hat Global File System ( GFS2 )、VMware® VMFS 等。 如需更多資訊,請參閱您的作業系統說明文件。

在您開始設定 iSCSI, 之前,請確定網路介面已經正確設定,並配置好 open-iscsi 套件才能正常運作,尤其是在啟動時。 在 Ubuntu 的較新版本中,設定網路位址資訊的主要工具是 Netplan。 它使用 YAML 設定檔來定義網路設定,取代 /etc/network/interfaces 等舊方法。 Netplan 可以使用命令列或透過桌面環境中的 NetworkManager 進行設定。

最好是在 VLAN 上執行儲存空間資料流量,這樣會略過防火牆。 透過軟體防火牆執行儲存空間資料流量,會增加延遲,而且會對儲存空間效能造成不利的影響。 如需將儲存空間資料流量遞送至其專屬 VLAN 介面的相關資訊,請參閱 常見問題

安裝 iSCSI 和多重路徑公用程式

請確定您的系統已更新,並包含 open-iscsimultipath-tools 套件。 請使用下列指令來安裝套件。

  • 更新作業系統:

    apt-get update
    
  • 安裝 open-iscsi

    sudo apt install open-iscsi
    

    當安裝套件時,它會建立下列兩個檔案。

    • /etc/iscsi/iscsid.conf
    • /etc/iscsi/initiatorname.iscsi
  • 啟動服務:

    systemctl enable open-iscsi
    
    systemctl enable iscsid
    
  • 安裝 multipath-tools

    sudo apt install multipath-tools
    

設定 ISCSI

更新啟動器名稱

  1. 檢查 /etc/iscsi/initiatorname.iscsi 檔案是否存在,並檢視其內容。

    cat /etc/iscsi/initiatorname.iscsi
    
    root@vsi4classicubuntu:~# cat /etc/iscsi/initiatorname.iscsi
    GenerateName=yes
    
  2. 使用文字編輯器,以 IBM Cloud® 主控台的 IQN 更新 /etc/iscsi/initiatorname.iscsi 檔案。 請以以下格式輸入數值。

    InitiatorName=<IQN-value-from-the-portal>
    

配置認證

  1. 請檢查檔案內容,確保該 iscsid.conf 檔案確實存在。

    cat /etc/iscsi/iscsid.conf
    
  2. 使用文字編輯器,取消註解並編輯下列項目。 您可以在 IBM Cloud® 主控台中找到使用者名稱和密碼。

    node.session.auth.authmethod = CHAP
    node.session.auth.username = <Username-value-from-Portal>
    node.session.auth.password = <Password-value-from-Portal>
    discovery.sendtargets.auth.authmethod = CHAP
    discovery.sendtargets.auth.username = <Username-value-from-Portal>
    discovery.sendtargets.auth.password = <Password-value-from-Portal>
    

    請將其他 CHAP 設定保留為註解狀態。IBM Cloud® 儲存空間僅使用單向驗證。 請勿啟用 Mutual CHAP。

  3. 重新啟動 iSCSI 服務,以便變更生效。

    systemctl restart iscsid.service
    

如需詳細資訊,請參閱 Ubuntu 手冊 - iscsidUbuntu 手冊 - systemctl

設定多路徑

  1. 安裝 multipath 公用程式後,您可以檢查 multipath.conf 檔案的預設內容。

    cat /etc/multipath.conf
    
  2. 使用文字編輯器 /etc/multipath.conf 修改 的預設值,將其替換為以下程式碼片段的內容。

    defaults {
    user_friendly_names no
    max_fds max
    flush_on_last_del yes
    queue_without_daemon no
    dev_loss_tmo infinity
    fast_io_fail_tmo 5
    }
    # All data in the following section must be specific to your system.
    blacklist {
    wwid "SAdaptec*"
    devnode "^hd[a-z]"
    devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
    devnode "^cciss.*"
    }
    devices {
    device {
    vendor "NETAPP"
    product "LUN"
    path_grouping_policy group_by_prio
    features "3 queue_if_no_path pg_init_retries 50"
    prio "alua"
    path_checker tur
    failback immediate
    path_selector "round-robin 0"
    hardware_handler "1 alua"
    rr_weight uniform
    rr_min_io 128
    }
    

    設定檔的初始預設值部分會設定系統,使多重路徑裝置的名稱格式為 /dev/mapper/mpathn,其中 mpathn 是裝置的 WWID (World Wide Identifier) 編號。 如需詳細資訊,請參閱 Ubuntu 手冊 - multipath.conf

  3. 儲存設定檔並退出編輯器。

  4. 啟動多路徑服務。

    service multipath-tools start
    
    1. 啟用必要的服務。

    如果您在啟動多路徑常駐程式之後需要編輯多路徑配置檔,則必須重新啟動 multipathd 服務,變更才會生效。

    如需在 Ubuntu 20 上使用裝置映射器多重路徑功能的詳細資訊,請參閱 裝置映射器多重路徑簡介

探索儲存裝置並登入

iscsiadm 公用程式是一個命令列工具,用於發現和登入 iSCSI 目標,以及存取和管理 open-iscsi 資料庫。 如需詳細資訊,請參閱 Ubuntu 手冊 - iscsiadm。在此步驟,使用從 IBM Cloud® 主控台取得的目標 IP 位址來發現裝置。

  1. 對 iSCSI 陣列執行探索。

    Block Storage for Classic 需要使用 SendTargets 方法進行動態目標偵測。 請勿使用靜態節點配置,因為此配置不具可擴展性,且當儲存裝置發生變更(例如對主機授予或撤銷 LUN 存取權限)時,可能會導致連線問題。 動態發現可確保您的主機自動偵測目標入口網站的任何變更。

    iscsiadm -m discovery -t sendtargets -p <ip-value-from-IBM-Cloud-console>
    

    如果顯示 IP 資訊及存取詳細資料,則探索成功。

    root@vsi4classicubuntu:~# iscsiadm -m discovery -t sendtargets -p 161.26.114.197
    161.26.114.197:3260,1052 iqn.1992-08.com.netapp:stfdal1304
    161.26.114.196:3260,1049 iqn.1992-08.com.netapp:stfdal1304
    
  2. 配置自動登入。

    sudo iscsiadm -m node --op=update -n node.conn[0].startup -v automatic
    sudo iscsiadm -m node --op=update -n node.startup -v automatic
    
  3. 登入 iSCSI 陣列。

    sudo iscsiadm -m node --login
    

驗證配置

  1. 驗證已建立 iSCSI 階段作業。

    iscsiadm -m session -o show
    
    root@vsi4classicubuntu:~# iscsiadm -m session -o show
    tcp: [3] 161.26.114.197:3260,1052 iqn.1992-08.com.netapp:stfdal1304 (non-flash)
    tcp: [4] 161.26.114.196:3260,1049 iqn.1992-08.com.netapp:stfdal1304 (non-flash)
    
  2. 請驗證存在多個路徑。

    multipath -ll
    

    這個指令會報告路徑。 如果配置正確,則每一個磁區都有單一群組,路徑數等於 iSCSI 階段作業數。 可以使用單一路徑附加磁碟區,但重要的是在兩個路徑上都建立連線,以避免服務中斷。

    root@vsi4classicubuntu:~# multipath -ll
     3600a0980383056666424506a33426478 dm-0 NETAPP,LUN C-Mode
     size=500G features='3 queue_if_no_path pg_init_retries 50' hwhandler='1 alua'
     wp=rw
     |-+- policy='service-time 0' prio=50 status=active
     | `- 3:0:0:0 sdb 8:16 active ready running
     `-+- policy='service-time 0' prio=10 status=enabled
       `- 2:0:0:0 sda 8:0    active ready running
    

    如果 MPIO 未正確配置,則發生網路中斷時或 IBM Cloud® 團隊執行維護時,您的儲存裝置可能會中斷連線並顯示離線。 MPIO 在這些事件發生時提供額外的連線能力,並透過持續的讀寫操作維持與卷的連線。

    在此範例中,3600a0980383056666424506a33426478 是磁區存在時持續存在的 WWID。 建議您的應用程式使用 WWID。 您亦可透過在 multipath.conf. 檔案中使用「user_friendly_names」或「alias」關鍵字,為項目指派更易於閱讀的名稱。

  3. 請檢查 dmesg,確定偵測到新磁碟。

    dmesg
    

建立分割區及檔案系統 (選用)

在主機上裝載並可存取磁區之後,您可以建立檔案系統。 請遵循這些步驟,以便在新裝載的磁區上建立檔案系統。

  1. 建立分割區。

    $ sudo fdisk /dev/mapper/mpatha
    
    Welcome to fdisk (util-linux 2.34).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0x92c0322a.
    
    Command (m for help): p
    Disk /dev/mapper/mpatha: 1 GiB, 1073741824 bytes, 2097152 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 65536 bytes
    Disklabel type: dos
    Disk identifier: 0x92c0322a
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1):
    First sector (2048-2097151, default 2048):
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2097151, default 2097151):
    
    Created a new partition 1 of type 'Linux' and of size 1023 MiB.
    
    Command (m for help): w
    The partition table has been altered.
    
  2. 建立檔案系統。

    $ sudo mkfs.ext4 /dev/mapper/mpatha-part1
    mke2fs 1.45.5 (07-Jan-2020)
    Creating filesystem with 261888 4k blocks and 65536 inodes
    Filesystem UUID: cdb70b1e-c47c-47fd-9c4a-03db6f038988
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
  3. 裝載區塊裝置。

    sudo mount /dev/mapper/mpatha-part1 /mnt
    
  4. 存取資料以確認新分割區及檔案系統已備妥可供使用。

    ls /mnt
    

卸載 Block Storage for Classic 磁區

當您不再需要該磁碟區時,請先卸載它,然後再刪除它。

  1. 卸載檔案系統。

    umount /dev/mapper/XXXp1 /PerfDisk
    

    如需詳細資訊,請參閱 Ubuntu 手冊 - umount

  2. 如果您在該目標入口網站中沒有任何其他磁區,可登出該目標。

    iscsiadm -m node -t <TARGET NAME> -p <PORTAL IP:PORT> --logout
    
  3. 如果您在該目標入口網站中沒有任何其他磁區,請刪除目標入口網站記錄,以防止未來的登入嘗試。

    iscsiadm -m node -o delete -t <TARGET IQN> -p <PORTAL IP:PORT>
    

    如需詳細資訊,請參閱 Ubuntu 手冊 - iscsiadm