Linux下配置iscsi網絡存儲

        1. 服務端配置

        實驗環境系統版本:

        CentOS Linux release 7.3.1611 (Core)

1) 安裝軟件包

yum -y install targetcli

2) 創建要輸出的iscsi存儲

        可輸出的設備有如下幾種: 

        a、lvm卷設備; 

        b、由文件組成的塊設備(經過tgtimg工具處理過的); 

        c、單一的分區; 

        d、整個磁盤; 

        e、RAID組成的卷設備; 

        這裏準備了一個lvm邏輯卷,如下:

[root@dengqp03 conf.d]# lvdisplay  
  --- Logical volume ---
  LV Path                /dev/vg_dengqp03/LogVol01
  LV Name                LogVol01
  VG Name                vg_dengqp03
  LV UUID                wK1tx8-98Eo-wXsN-TMdU-0yl8-8okh-7iiQuo
  LV Write Access        read/write
  LV Creation host, time dengqp03, 2016-04-19 03:43:00 -0400
  LV Status              available
  # open                 1
  LV Size                10.84 GiB
  Current LE             2774
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

3) 查看客戶端InitiatorName 用戶創建acl

[root@dengqp-test ~]# cat /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.1994-05.com.redhat:f958e9b53119

4) 使用targetcli配置存儲

[root@dengqp03 conf.d]# targetcli 
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
 
/> 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 create mydata /dev/mapper/vg_dengqp03-LogVol01  //創建共享塊存儲
Created block storage object mydata using /dev/mapper/vg_dengqp03-LogVol01.
/> cd iscsi 
/iscsi> create iqn.2017-03.com.dengqp:server0  //創建一個target
Created target iqn.2017-03.com.dengqp:server0.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2017-03.com.dengqp:server0 ...................................................................................... [TPGs: 1]
    o- tpg1 ................................................................................................. [no-gen-acls, no-auth]
      o- acls ............................................................................................................ [ACLs: 0]
      o- luns ............................................................................................................ [LUNs: 0]
      o- portals ...................................................................................................... [Portals: 1]
        o- 0.0.0.0:3260 ....................................................................................................... [OK]
/iscsi> cd iqn.2017-03.com.dengqp:server0/tpg1/
/iscsi/iqn.20...:server0/tpg1> cd portals/
/iscsi/iqn.20.../tpg1/portals> delete ip_address=0.0.0.0 ip_port=3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 10.20.2.237   //創建共享地址,端口默認爲3260
Using default IP port 3260
Created network portal 10.20.2.237:3260.
/iscsi/iqn.20.../tpg1/portals> cd ..
/iscsi/iqn.20...:server0/tpg1> luns/ create /backstores/block/mydata //在target上面創建一個lun
Created LUN 0.
/iscsi/iqn.20...:server0/tpg1> acls/ create iqn.1994-05.com.redhat:f958e9b53119 //acls目錄創建共享密碼
Created Node ACL for iqn.1994-05.com.redhat:f958e9b53119
Created mapped LUN 0.
/iscsi/iqn.20...engqp:server0> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- mydata .................................................. [/dev/mapper/vg_dengqp03-LogVol01 (10.8GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2017-03.com.dengqp:server0 .................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.1994-05.com.redhat:f958e9b53119 .................................................................. [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ................................................................................ [lun0 block/mydata (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................ [block/mydata (/dev/mapper/vg_dengqp03-LogVol01)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 10.20.2.237:3260 ................................................................................................. [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> saveconfig      //保存配置
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

5) 啓動target服務

[root@dengqp03 conf.d]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@dengqp03 conf.d]# systemctl start target
[root@dengqp03 conf.d]# systemctl status target
● target.service - Restore LIO kernel target configuration
   Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
   Active: active (exited) since Mon 2017-03-27 03:33:22 EDT; 4s ago
  Process: 14646 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
 Main PID: 14646 (code=exited, status=0/SUCCESS)
 
Mar 27 03:33:22 dengqp03 systemd[1]: Starting Restore LIO kernel target configuration...
Mar 27 03:33:22 dengqp03 systemd[1]: Started Restore LIO kernel target configuration.

2. 客戶端配置

        實驗環境系統版本:

        CentOS release 6.7 (Final)

1) man iscsiadm 查看幫助中的examples

Discover targets at a given IP address:

iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover

Login, must use a node record id found by the discovery:

iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --login

2) 發現服務器端輸出的設備

[root@dengqp-test samba]# iscsiadm --mode discoverydb --type sendtargets --portal 10.20.2.237 --discover 
Starting iscsid:                                           [  OK  ]
10.20.2.237:3260,1 iqn.2017-03.com.dengqp:server0

3) 鏈接設備

[root@dengqp-test samba]# iscsiadm --mode node --targetname iqn.2017-03.com.dengqp:server0 --portal 10.20.2.237:3260 --login                                 
Logging in to [iface: default, target: iqn.2017-03.com.dengqp:server0, portal: 10.20.2.237,3260] (multiple)
Login to [iface: default, target: iqn.2017-03.com.dengqp:server0, portal: 10.20.2.237,3260] successful.

4) 查看驗證設備是否已識別

[root@dengqp-test samba]# fdisk -l
如下爲發現的網絡存儲
Disk /dev/sdb: 11.6 GB, 11634999296 bytes
64 heads, 32 sectors/track, 11096 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk identifier: 0x00000000

5) 創建iscsi掛載點並掛載網絡存儲

[root@dengqp-test /]# mkdir iscsi
[root@dengqp-test /]# mount /dev/sdb /iscsi/
//如果掛載出現如下錯誤,需要使用mkfs格式化後再進行掛載
mount: you must specify the filesystem type
[root@dengqp-test /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb               11G  4.1G  6.0G  41% /iscsi


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