全部產品
Search
文件中心

Cloud Storage Gateway:在Linux系統上使用卷

更新時間:Aug 04, 2026

本文介紹如何在Linux作業系統上串連並使用iSCSI卷。

前提條件

已建立iSCSI卷。具體操作,請參見建立iSCSI卷。

串連卷

  1. 登入Elastic Compute Service。

    說明

    如果您的本地主機已通過專線和阿里雲專用網路連通,您也可以使用本地主機進行操作。

  2. 串連ECS Linux執行個體。具體操作,請參見選擇ECS執行個體。

  3. 執行如下命令,安裝iscsi-initiator-utils。

    您需要通過iscsi-initiator-utils串連到目標iSCSI卷,如果您已經安裝,請跳過此步驟。

    sudo yum install iscsi-initiator-utils

    如果您使用的是Debian或者Ubuntu作業系統,請執行如下命令安裝。

    sudo apt-get install open-iscsi
  4. 驗證iSCSI守護進程是否正在運行。

    • 如果是RHEL 5/RHEL 6,請執行如下命令:

      sudo /etc/init.d/iscsi status
    • 如果是RHEL7及以上版本,請執行如下命令:

      sudo systemctl status iscsid

    如果執行以上命令,未返回running狀態,則執行如下命令啟動iSCSI守護進程。

    • 如果是RHEL 5/RHEL 6,請執行如下命令:

      sudo /etc/init.d/iscsi start
    • 如果是RHEL7及以上版本,請執行如下命令:

      sudo systemctl start iscsid
  5. (可選)設定CHAP認證。

    說明

    如果您在建立iSCSI卷時,啟用了CHAP認證,則需要在進階設定對話方塊中設定CHAP認證資訊後,才能使用iSCSI卷。

    1. 執行如下命令開啟iscsid.conf設定檔。

      vi /etc/iscsi/iscsid.conf
    2. 找到CHAP Settings,刪除相關配置項前面的注釋符#,並設定使用者和密碼。

      • 使用者為建立iSCSI卷時設定的入站CHAP使用者。

      • 密碼為建立iSCSI卷時設定的入站CHAP密碼。

      
      # To request that the iscsi initd scripts startup a session set to "automatic".
      # node.startup = automatic
      
      # To manually startup the session set to "manual". The default is automatic.
      node.startup = automatic
      
      # For "automatic" startup nodes, setting this to "Yes " will try logins on each
      # available iface until one succeeds, and then stop.  The default "No" will try
      # logins on all available ifaces simultaneously.
      node.leading_login = No
      
      # *************
      # CHAP Settings
      # *************
      
      # To enable CHAP authentication set node.session.auth.authmethod
      # to CHAP. The default is None.
      node.session.auth.authmethod = CHAP
      
      # To set a CHAP username and password for initiator
      # authentication by the target(s), uncomment the following lines:
      node.session.auth.username = user1
      node.session.auth.password = 12345678901qaz
      
      # To set a CHAP username and password for target(s)
      # authentication by the initiator, uncomment the following lines:
      #node.session.auth.username_in = username_in
      #node.session.auth.password_in = password_in
      
      # To enable CHAP authentication for a discovery session to the target
      # set discovery.sendtargets.auth.authmethod to CHAP. The default is None.
      #discovery.sendtargets.auth.authmethod = CHAP
      
      # To set a discovery session CHAP username and password for the initiator
  6. 發現iSCSI卷。

    您可以在阿里雲Cloud Storage Gateway控制台上找到對應的塊網關,在卷列表頁面中擷取塊網關IPv4地址,在服务IP第二行擷取塊網關IPv6地址。

    • IPv4方式執行如下命令:

      iscsiadm -m discovery -t st -p <目標IPv4地址>:3260
    • IPv6方式執行如下命令:

      iscsiadm -m discovery -t st -p <目標IPv6地址>:3260

    3260為訪問連接埠,保持不變;目標IPv4地址為塊網關IPv4地址;目標IPv6地址為塊網關IPv6地址。

    說明
    • 網關從v1.6.0版本開始支援IPv6。

    • 僅華東5(呼和浩特)地區支援IPv6方式掛載,網關所使用的VPC和vSwitch要支援使用IPv6。

    • 使用IPv6方式掛載前請確保所使用的ECS用戶端已經配置了IPv6地址。

    • 如果已有網關所使用的VPC和vSwitch支援IPv6,可以在網關巨集指令清單中啟用IPv6後,在服務IP第二行擷取IPv6地址,而在此VPC下新建立的網關預設支援IPv6,不需要進行啟用操作。

  7. 掛載iSCSI卷。

    • IPv4方式執行如下命令:

      iscsiadm -m node -T <目標名稱> -p <目標IPv4地址>:3260 -l
    • IPv6方式執行如下命令:

      iscsiadm -m node -T <目標名稱> -p <目標IPv6地址>:3260 -l

    目標名稱為iSCSI卷的目標名稱,可以從步驟6發現iSCSI卷的命令返回中擷取。

    說明

    由於iSCSI 協議限制,請勿將一個iSCSI卷掛載到多個Linux用戶端。

查看卷

  1. 執行fdisk -l或lsblk命令查看iSCSI卷。

  2. 確認已掛載的iSCSI捲成為一個可用的裸磁碟,您可以在本地主機上進行讀寫操作。

    執行 fdisk -l 命令查看系統磁碟,其中 /dev/sdd(1099.5 GB)即為已掛載的 iSCSI 卷對應的裸磁碟。

    
    [root@client2 ~]# fdisk -l
    
    Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk label type: dos
    Disk identifier: 0x000e1179
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   419430399   208665600   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    
    
    Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    
    
    Disk /dev/mapper/centos-home: 151.5 GB, 151523426304 bytes, 295944192 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    
    
    Disk /dev/sdd: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 4096 bytes / 524288 bytes

卸載卷

當不再使用iSCSI卷時可以通過以下命令列進行卸載。

  • IPv4方式執行如下命令:

    iscsiadm -m node -T <目標名稱> -p <目標IPv4地址>:3260 -u
  • IPv6方式執行如下命令:

    iscsiadm -m node -T <目標名稱> -p <目標IPv6地址>:3260 -u