iSCSI

iSCSI概念

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

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

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

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

 

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

 

1.

iscsi是直接對設備進行共享的服務

 

2.啓動iscsi共享設備

server端:

 

1)實驗前在服務端建立lvm設備

[root@server13 ~]# fdisk /dev/vdb##建立lvm設備

n→p→回車→回車→+1000M→p→t→8e→p→wq

 

[root@server13 ~]# partprobe

[root@server13 ~]# pvcreate /dev/vdb1##共享一個lv

  Physical volume "/dev/vdb1" successfully created

[root@server13 ~]# vgcreate vg0 /dev/vdb1

  Volume group "vg0" successfully created

[root@server13 ~]# vgdisplay

[root@server13 ~]# lvcreate -l 249 -n iscsi_storage vg0

  Logical volume "iscsi_storage" created

 

測試:

[root@server13 ~]# lvs##lvm設備的成功建立

  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert

  iscsi_storage vg0  -wi-a----- 996.00m                                           

 

2)服務的安裝與開啓

[root@server13 ~]# yum install targetcli.noarch ##安裝iSCSI目標軟件包

[root@server13 ~]# systemctl enable target.service ##啓動服務

ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

[root@server13 ~]# systemctl start  target.service

[root@server13 ~]# systemctl stop firewalld.service

 

 

3)服務端的配置

[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     ##創建邏輯單元號

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    ##加密(默認情況下,網絡通信是至iSCSI目標上的端口3260/tcp的明文)

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

 

查看:

[root@server13 ~]# targetcli

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: 1]

  | | o- server1storage  [/dev/vg0/iscsi_storage (996.0MiB) 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-06.com.example:strage1 ................. [TPGs: 1]

  |   o- tpg1 ............................. [no-gen-acls, no-auth]

  |     o- acls ........................................ [ACLs: 1]

  |     | o- iqn.2017-06.com.example:server1storagekey  [Mapped LUNs: 1]

  |     |   o- mapped_lun0 ...... [lun0 block/server1storage (rw)]

  |     o- luns ........................................ [LUNs: 1]

  |     | o- lun0  [block/server1storage (/dev/vg0/iscsi_storage)]

  |     o- portals .................................. [Portals: 1]

  |       o- 172.25.13.11:3260 .............................. [OK]

  o- loopback ....................................... [Targets: 0]

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

  

 

 

在客戶端連接:

[root@desktop13 ~]# vim /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2017-06.com.example:server1storagekey

 

[root@desktop13 ~]# systemctl restart iscsi

[root@desktop13 ~]# fdisk -l

 

Disk /dev/vda: 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: 0x00013f3e

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    20970332    10484142+  83  Linux

 

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

 

[root@desktop13 ~]# iscsiadm -m discovery -t st -p 172.25.13.11    ##查找iscsi服務器所提供的iscsi目標

172.25.13.11:3260,1 iqn.2017-06.com.example:strage1

[root@desktop13 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.13.11 -l    ##登錄服務器上的iscsi目標  

Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] (multiple)

Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] successful.

 

 

測試:

[root@desktop13 ~]# fdisk -l    ##客戶端上出現一個新硬盤設備

 

Disk /dev/vda: 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: 0x00013f3e

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    20970332    10484142+  83  Linux

 

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 /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 4194304 bytes

Disk label type: dos

Disk identifier: 0xfe173449

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1            8192     2039807     1015808   83  Linux

 

 

 

 

3.自動掛載

 

[root@desktop13 ~]# vim /etc/fstab

 10 UUID=2da90fa4-582e-4c16-863a-bd6d83587e8f /mnt xfs defaults,_netdev 0 0

##_netdev表示開機掛載之前先啓動網絡服務 


4.刪除

[root@desktop13 ~]# umount /mnt/

[root@desktop13 ~]# tree -C /var/lib/iscsi//var/lib/iscsi/

├── ifaces

├── isns

├── nodes

   └── iqn.2017-06.com.example:strage1

       └── 172.25.13.11,3260,1

           └── default

├── send_targets

   └── 172.25.13.11,3260

       ├── iqn.2017-06.com.example:strage1,172.25.13.11,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:strage1/172.25.13.11,3260,1

       └── st_config

├── slp

└── static

 

10 directories, 2 files

 

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

Logging out of session [sid: 1, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260]

Logout of [sid: 1, target: iqn.2017-06.com.example:strage1, portal: 172.25.13.11,3260] successful.

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



在服務端刪除:

[root@server13 ~]# 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

 

測試:

[root@desktop13 ~]# tree -C /var/lib/iscsi//var/lib/iscsi/

├── ifaces

├── isns

├── nodes

├── send_targets

   └── 172.25.13.11,3260

       └── st_config

├── slp

└── static

 

 


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