Linux運維筆記-文檔總結-iSCSI存儲服務

以下所有操作都是在Red-hat 7.0上


1.iSCSI概念(iscsi是直接對設備進行共享的服務)

iSCSI(Internet SCSI)支持從客戶端(發起端)通過IP向遠程服務器上的SCSI存儲設備(目標)發送SCSI命令。iSCSI限定名稱用於確定發起端和目標,並採用iqn.yyyy-mm.{reverse domain}:label的格式。默認情況下,網絡通信是至iSCSI目標上的端口3260/tcp的明文。

 iSCSI發起端:需要訪問原始SAN存儲的客戶端。

 iSCSI目標:從iSCSI服務器提供的遠程硬盤磁盤,或“目標門戶”

 iSCSI目標門戶:通過網絡向發起端提供目標的服務器。

IQN:“iSCSI限定名稱”。每個發起端和目標需要唯一名稱進行標識,最好的做法是使用一個在Internet上可能獨一無二的名稱。

這裏寫圖片描述

這裏寫圖片描述

2.配置iSCSI

在server服務端上:

建立lvm設備(動態分配空間)

fdisk /dev/vdb
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1000M  ##分配1000M空間
Partition 1 of type Linux and of size 1000 MiB is set

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xdb6410a5

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM' ##類型搞成LVM類型

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xdb6410a5

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   8e  Linux LVM

Command (m for help): wq
The partition table has been altered!

partprobe ##重載分區表

這裏寫圖片描述

pvcreate /dev/vdb1 ##共享一個lv

vgcreate vg0 /dev/vdb1 ##共享一個vg

lvcreate -l 249 -n iscsi_storage vg0 ##命名爲iscsi_倉庫

yum install targetcli.noarch ##安裝iSCSI目標軟件包

systemctl enable target.service ##開啓target服務

systemctl start target.service

systemctl stop firewalld.service

這裏寫圖片描述
這裏寫圖片描述

[root@server13 ~]# targetcli       ##進入iSCSI目標交互式配置模式
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
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 server1storage /dev/vg0/iscsi_storage   ##和邏輯卷建立聯繫,把/dev/vg0/iscsi_storage用server1storage表示
Created block storage object server1storage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:strage1        ##創建iqn服務的名稱(每個發起端和目標需要唯一名稱進行標識)
Created target iqn.2017-06.com.example:strage1.
Created TPG 1.
/> ls
o- / ....................................................... [...]
  o- backstores ............................................ [...]
  | o- block ................................ [Storage Objects: 1]
  | | o- server1storage  [/dev/vg0/iscsi_storage (996.0MiB) write-thru deactivated]
  | o- fileio ............................... [Storage Objects: 0]
  | o- pscsi ................................ [Storage Objects: 0]
  | o- ramdisk .............................. [Storage Objects: 0]
  o- iscsi .......................................... [Targets: 1]
  | o- iqn.2017-06.com.example:strage1 ................. [TPGs: 1]
  |   o- tpg1 ............................. [no-gen-acls, no-auth]
  |     o- acls ........................................ [ACLs: 0]
  |     o- luns ........................................ [LUNs: 0]
  |     o- portals .................................. [Portals: 0]
  o- loopback ....................................... [Targets: 0]
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage         ##加密(默認情況下,網絡通信是至iSCSI目標上的端口3260/tcp的明文)
Created LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey
Created Node ACL for iqn.2017-06.com.example:server1storagekey
Created mapped LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.13.11
Using default IP port 3260
Created network portal 172.25.13.11:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

在desktop客戶端上:

vim /etc/iscsi/initiatorname.iscsi ##進入配置文件

InitiatorName=iqn.2017-06.com.example:server1storagekey ##鑰匙

systemctl restart iscsi ##重啓服務

iscsiadm -m discovery -t st -p 172.25.10.10 ##識別查詢設備
iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -l ##遠程連接存儲塊

mkfs.xfs /dev/sda ##格式化硬盤

mount /dev/sda /mnt/ ##掛載硬盤,進行遠程存儲。

這裏寫圖片描述

這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

3.自動掛載

vim /etc/fstab

10 UUID=2da90fa4-582e-4c16-863a-bd6d83587e8f /mnt xfs defaults,_netdev 0 0 ##儘量使用uuid掛載,因爲在每次開機時,這個服務會發生漂移。

這裏寫圖片描述

4.刪除iSCSI設備

在客戶端刪除:

iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -u ##登出iSCSI目標,以暫時斷開連接。

iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -o delete ##刪除iSCSI目標的本地記錄,以永久斷開連接。

這裏寫圖片描述

在服務端刪除:

[root@server10 ~]# targetcli 
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> clearconfig confirm=True  ##確定刪除。
All configuration cleared
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

The End

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