首頁 > 軟體

Linux基礎教學學習筆記34——設定ISCSI

2020-06-16 18:02:31

RHCE7認證學習筆記34——設定ISCSI

一、儲存裝置型別

  • DSA:直接區域儲存
  • NAS:網路區域儲存
  • SAN:儲存區域網路,塊級別共用

二、設定iscsi伺服器端

這裡舉例子說明,假如伺服器有2個分割區/dev/sdb7,/dev/sdb8要共用出去:   
    /dev/sdb7      1230848      1640447    200M  Linux filesyste
    /dev/sdb8      1640448      2459647    400M  Linux filesyste

安裝target包:
[root@linuxidc ~]# yum install target* -y

啟動target服務
[root@linuxidc ~]# systemctl start target
   
設定步驟:

1、準備要共用的塊;

使用targetcli命令進入target設定介面:
 [root@linuxidc ~]# targetcli

/> pwd
/
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]

進入backstores/block目錄建立要共用的塊,建立block1和block2:
       
/> cd backstores/
/backstores> ls
o- backstores ................................................................................................................ [...]
  o- block .................................................................................................... [Storage Objects: 0]
  o- fileio ................................................................................................... [Storage Objects: 0]
  o- pscsi .................................................................................................... [Storage Objects: 0]
  o- ramdisk .................................................................................................. [Storage Objects: 0]
       
/backstores/block> create block1 dev=/dev/sdb7
Created block storage object block1 using /dev/sdb7.
/backstores/block> create block2 dev=/dev/sdb8
Created block storage object block2 using /dev/sdb8.

/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 2]
  o- block1 .......................................................................... [/dev/sdb7 (200.0MiB) write-thru deactivated]
  o- block2 .......................................................................... [/dev/sdb8 (400.0MiB) write-thru deactivated]

exit退出儲存targetcli,並重新進入:
/backstores/block> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@linuxidc ~]# targetcli

2、建立一個target;

target標準名字格式:

年  月  域名倒寫 名字

iqn.2015-02.com.sg:disk1

進入iscsi目錄,建立target:

/iscsi> create iqn.2015-02.com.sg:disk1
                   
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2015-02.com.sg:disk1 ............................................................................................ [TPGs: 1]

3、在target上面建立一個lun;

進入/iscsi/iqn.2015-02.com.sg:disk1/tpg1目錄:     
 /iscsi/iqn.20...sg:disk1/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
  o- acls ................................................................................................................ [ACLs: 0]
  o- luns ................................................................................................................ [LUNs: 0]
  o- portals .......................................................................................................... [Portals: 0]

acls目錄建立共用密碼:                   
 /iscsi/iqn.20...sg:disk1/tpg1> acls/ create iqn.2015-02.com.sg:diskpasswd

建立lun:       
/iscsi/iqn.20...sg:disk1/tpg1> luns/ create /backstores/block/block1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2015-02.com.sg:diskpasswd
/iscsi/iqn.20...sg:disk1/tpg1> luns/ create /backstores/block/block2
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2015-02.com.sg:diskpasswd

 o- luns .......................................................................................................... [LUNs: 2]
  |    | o- lun0 ....................................................................................... [block/block1 (/dev/sdb7)]
  |    | o- lun1 ....................................................................................... [block/block2 (/dev/sdb8)]

portal建立共用埠和地址:
/iscsi/iqn.20...sg:disk1/tpg1> portals/ create 10.35.89.32
Using default IP port 3260
Created network portal 10.35.89.32:3260.

exit退出並儲存:

Configuration saved to /etc/target/saveconfig.json

組態檔儲存在:/etc/target/saveconfig.json,可以直接修改組態檔

三、用戶端設定iscsi連線

安裝target包: 
[root@client ~]# yum install target* -y

檢視fuw伺服器端共用的內容:
[root@client ~]# iscsiadm -m discovery -t st -p 10.35.89.32
10.35.89.32:3260,1 iqn.2015-02.com.sg:disk1

編輯/etc/iscsi/initiatorname.iscsi檔案,設定伺服器端共用的名字和密碼:
InitiatorName=iqn.2015-02.com.sg:diskpasswd

重新啟動iscscid服務:

[root@client ~]# systemctl restart iscsid.service

掛載伺服器端共用的內容:

[root@client ~]# iscsiadm -m node -T iqn.2015-02.com.sg:disk1 -p 10.35.89.32 -l

掛載成功後,使用fdisk命令即可檢視到新增加的兩塊磁碟:

斷開掛載的連線:
[root@client ~]# iscsiadm -m node -T iqn.2015-02.com.sg:disk1 -p 10.35.89.32 -u

使用fdisk命令劃分共用的磁碟,格式化,並掛載資料夾,編輯fstab檔案設定開機自動掛載:
 [root@client ~]# fdisk /dev/sdb

Device Boot      Start        End      Blocks  Id  System
/dev/sdb1            8192      114687      53248  83  Linux

[root@client ~]# mkfs.xfs /dev/sdb1

[root@client /]# mount /dev/sdb1 /aa

編輯fstab檔案時候,將default換成_netdev引數:

/dev/sdb1      /aa    xfs    _netdev 0 0

本文永久更新連結地址http://www.linuxidc.com/Linux/2015-04/116093.htm


IT145.com E-mail:sddin#qq.com