Linux ISCSI 管理配置


一.簡介

iSCSI(internet SCSI)技術由IBM公司研究開發,是一個供硬件設備使用的、可以在IP協議的上層運行的SCSI指令集,這種指令集合可以實現在IP網絡上運行SCSI協議,使其能夠在諸如高速千兆以太網上進行路由選擇。iSCSI技術是一種新儲存技術,該技術是將現有SCSI接口與以太網絡(Ethernet)技術結合,使服務器可與使用IP網絡的儲存裝置互相交換資料。

iSCSI是一種基於TCP/IP 的協議,用來建立和管理IP存儲設備、主機和客戶機等之間的相互連接,並創建存儲區域網絡(SAN)。SAN 使得SCSI 協議應用於高速數據傳輸網絡成為可能,這種傳輸以數據塊級別(block-level)在多個數據存儲網絡間進行。SCSI 結構基於C/S模式,其通常應用環境是:設備互相靠近,並且這些設備由SCSI 總線連接。

iSCSI 的主要功能是在TCP/IP 網絡上的主機系統(啟動器 initiator)和存儲設備(目標器 target)之間進行大量數據的封裝和可靠傳輸過程。iSCSI可分享的設備類型有很多,包括鏡像文件(*.img)、分區(partition)、物理硬盤、raid設備、邏輯卷等。

二.實驗

1. ISCSI 服務端: 172.16.97.136

    ISCSI 客戶端: 172.16.97.138

2. 關閉Selinux,打開防火牆端口

[root@localhost ~]# setenforce 0
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success

3. 查看服務端系統磁盤信息,並創建LVM,使用LVM管理便於磁盤的擴展

#查看硬盤配置
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6.2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sdc 8:32 0 8G 0 disk sdd 8:48 0 8G 0 disk sde 8:64 0 8G 0 disk sr0 11:0 1 1024M 0 rom #格式化物理磁盤為PV
[root@localhost
~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <7.00g 0 /dev/sdb lvm2 --- 8.00g 8.00g
#創建VG [root@localhost
~]# vgcreate linux-pv /dev/sdb Volume group "linux-pv" successfully created [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <7.00g 0 linux-pv 1 0 0 wz--n- <8.00g <8.00g
#創建邏輯卷 [root@localhost
~]# lvcreate -n share-lv -L 4G linux-pv Logical volume "share-lv" created. [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <6.20g swap centos -wi-ao---- 820.00m share-lv linux-pv -wi-a----- 4.00g [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6.2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 8G 0 disk └─linux--pv-share--lv 253:2 0 4G 0 lvm sdc 8:32 0 8G 0 disk sdd 8:48 0 8G 0 disk sde 8:64 0 8G 0 disk sr0 11:0 1 1024M 0 rom

4. 服務端安裝配置iSCSI

#安裝target服務
[root@localhost ~]# yum -y install targetd targetcli
[root@localhost ~]# systemctl start targetd
[root@localhost ~]# systemctl enable targetd
Created symlink from /etc/systemd/system/multi-user.target.wants/targetd.service to /usr/lib/systemd/system/targetd.service.

 

#創建target
[root@localhost ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb46 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]
#創建塊設備
/> cd backstores/ /backstores> cd block /backstores/block> create dev= name= readonly= wwn= /backstores/block> create share-disk /dev/linux-pv/share-lv Created block storage object share-disk using /dev/linux-pv/share-lv. /backstores/block> ls o- block ...................................................................................................... [Storage Objects: 1] o- share-disk ........................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated] o- alua ....................................................................................................... [ALUA Groups: 1] o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized] /backstores/block> cd .. /backstores> ls o- backstores ................................................................................................................ [...] o- block .................................................................................................... [Storage Objects: 1] | o- share-disk ......................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated] | o- alua ..................................................................................................... [ALUA Groups: 1] | o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized] o- fileio ................................................................................................... [Storage Objects: 0] o- pscsi .................................................................................................... [Storage Objects: 0] o- ramdisk .................................................................................................. [Storage Objects: 0] /backstores> cd.. /> ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 1] | | o- share-disk ....................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated] | | o- alua ................................................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 0] o- loopback ......................................................................................................... [Targets: 0] /> cd iscsi /iscsi> ls o- iscsi .............................................................................................................. [Targets: 0] /iscsi> create iqn.2019-05.com.share-disk:server Created target iqn.2019-05.com.share-disk:server. 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.2019-05.com.share-disk:server ................................................................................... [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.2019-05.com.share-disk:server/ /iscsi/iqn.20...e-disk:server> tpg1/ /iscsi/iqn.20...k:server/tpg1> ls 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/iqn.20...k:server/tpg1> cd luns /iscsi/iqn.20...ver/tpg1/luns> ls o- luns .................................................................................................................. [LUNs: 0] /iscsi/iqn.20...ver/tpg1/luns> cd .. /iscsi/iqn.20...k:server/tpg1> ls 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]
#創建ACL
/iscsi/iqn.20...k:server/tpg1> cd acls /iscsi/iqn.20...ver/tpg1/acls> ls o- acls .................................................................................................................. [ACLs: 0] /iscsi/iqn.20...ver/tpg1/acls> create iqn.2019-05.com.share-disk:client Created Node ACL for iqn.2019-05.com.share-disk:client /iscsi/iqn.20...ver/tpg1/acls> cd .. /iscsi/iqn.20...k:server/tpg1> ls o- tpg1 ..................................................................................................... [no-gen-acls, no-auth] o- acls ................................................................................................................ [ACLs: 1] | o- iqn.2019-05.com.share-disk:client .......................................................................... [Mapped LUNs: 0] o- luns ................................................................................................................ [LUNs: 0] o- portals .......................................................................................................... [Portals: 1] o- 0.0.0.0:3260 ........................................................................................................... [OK] /iscsi/iqn.20...k:server/tpg1> cd luns /iscsi/iqn.20...ver/tpg1/luns> create /backstores/block/share-disk Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2019-05.com.share-disk:client /iscsi/iqn.20...ver/tpg1/luns> ls o- luns .................................................................................................................. [LUNs: 1] o- lun0 ........................................................... [block/share-disk (/dev/linux-pv/share-lv) (default_tg_pt_gp)] /iscsi/iqn.20...ver/tpg1/luns> cd .. /iscsi/iqn.20...k:server/tpg1> cd portals/ /iscsi/iqn.20.../tpg1/portals> ls o- portals ............................................................................................................ [Portals: 1] o- 0.0.0.0:3260 ............................................................................................................. [OK] /iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260 Deleted network portal 0.0.0.0:3260 /iscsi/iqn.20.../tpg1/portals> create 172.16.97.61 3260 Using default IP port 3260 Created network portal 172.16.97.61:3260. /iscsi/iqn.20.../tpg1/portals> ls o- portals ............................................................................................................ [Portals: 1] o- 172.16.97.61:3260 ........................................................................................................ [OK] /iscsi/iqn.20.../tpg1/portals> cd / /> ls o- / ......................................................................................................................... [...] o- backstores .............................................................................................................. [...] | o- block .................................................................................................. [Storage Objects: 1] | | o- share-disk ......................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru activated] | | o- alua ................................................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized] | o- fileio ................................................................................................. [Storage Objects: 0] | o- pscsi .................................................................................................. [Storage Objects: 0] | o- ramdisk ................................................................................................ [Storage Objects: 0] o- iscsi ............................................................................................................ [Targets: 1] | o- iqn.2019-05.com.share-disk:server ................................................................................. [TPGs: 1] | o- tpg1 ............................................................................................... [no-gen-acls, no-auth] | o- acls .......................................................................................................... [ACLs: 1] | | o- iqn.2019-05.com.share-disk:client .................................................................... [Mapped LUNs: 1] | | o- mapped_lun0 ............................................................................ [lun0 block/share-disk (rw)] | o- luns .......................................................................................................... [LUNs: 1] | | o- lun0 ................................................... [block/share-disk (/dev/linux-pv/share-lv) (default_tg_pt_gp)] | o- portals .................................................................................................... [Portals: 1] | o- 172.16.97.61:3260 ................................................................................................ [OK] o- loopback ......................................................................................................... [Targets: 0] /> saveconfig
/> exit
[root@localhost ~]# systemctl restart targetd

 5.ISCSI客戶端配置

[root@localhost ~]#yum -y install iscsi-initiator-utils 

# 修改/etc/iscsi/initiatorname.iscsi文件

[root@iscsi-client ~]# vim /etc/iscsi/initiatorname.iscsi
iqn.2019-05.com.share-disk:client

# 啟動服務

[root@iscsi-client ~]# systemctl start iscsid
[root@iscsi-client ~]# systemctl enable iscsid
# 掛載192.168.1.157,掛載之前必須要發現該iscsi
[root@iscsi-client ~]# iscsiadm -m discovery -t st -p 192.168.1.157
iqn.2019-05.com.share-disk:server

[root@iscsi-client ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.1.157 -l

# 掛載192.
168.1.158,掛載之前必須要發現該iscsi
[root@iscsi
-client ~]# iscsiadm -m discovery -t st -p 192.168.1.158 192.168.1.158:3260,1

iqn.2019-05.com.share-disk:server
[root@iscsi-client ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.1.158 -l 

#查看 [root@iscsi
-client ~]# lsblk

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM