1. 程式人生 > >002.iSCSI服務端配置

002.iSCSI服務端配置

一 iSCSI target的磁碟種類

  • 大型檔案
  • 單一分割槽(partition)
  1. 磁碟
  2. 陣列
  3. RAID
  4. LVM

二 iSCSI建立步驟

  1. 建立用於共享的磁碟裝置(分割槽/磁碟/檔案)
  2. 建立後備磁碟
  3. 建立相應的IQN
  4. 建立相應的規則 #(可選)
  5. 為後備磁碟建立LUN
  6. 指定偵聽的IP和埠 #(可選)
  7. 檢查並儲存配置
  8. 防火牆規則開放
  9. 服務(開機)啟動

三 建立所需磁碟裝置

3.1 建立一個3GB大小的/dev/sdc1作為共享

  1    Device Boot      Start         End      Blocks   Id  System
  2
/dev/sdc1 2048 6293503 3145728 83 Linux

3.2 建立一個2GB大小的/dev/server/iscsi01LV作為共享

使用fdisk建立一個用於共享的LVM分割槽disk1_lv。

  1    Device Boot      Start         End      Blocks   Id  System
  2 /dev/sdb1            2048     4196351     2097152   8e  Linux LVM
  3 /dev/sdb2         4196352     8390655     2097152   8e  Linux LVM
  4
[[email protected] ~]# pvcreate /dev/sdb1 5 [[email protected] ~]# pvcreate /dev/sdb2 6 [[email protected] ~]# vgcreate iSCSI -s 16M /dev/sdb1 /dev/sdb2 7 Volume group "iSCSI" successfully created 8 [[email protected] ~]# lvcreate -n disk1_lv -L 2G iSCSI

3.3 建立一個1GB大小的檔案disk1_file作為共享

  1 [[email protected] ~]# dd if=/dev/zero of=/root/disk1_file bs=1M count=1024

四 建立後備儲存

4.1 安裝相關軟體

  1 [[email protected] ~]# yum -y install targetcli

4.2 相關設定-互動模式

  1 [[email protected] ~]# targetcli	#進入targetcli互動配置檢視
  2 block:定義的塊裝置,磁碟驅動器、磁碟分割槽、LVM等
  3 fileio:建立的指定大小的檔案,如dd if=/dev/zero of=……所建立
  4 pscsi:物理SCSI,通常不採用此型別
  5 ramdisk:在記憶體中建立的一個指定大小ramdisk裝置
  6 /> cd /backstores/
  7 /backstores> block/ create block1 /dev/iSCSI/disk1_lv	#建立名為block1的lvm的後備儲存
  8 Created block storage object block1 using /dev/iSCSI/disk1_lv.
  9 /backstores> block/ create block2 /dev/sdc1		#建立名為block2的磁碟分割槽後備儲存
 10 Created block storage object block2 using /dev/sdc1.
 11 /backstores> fileio/ create file1 /root/disk1_file	#建立名為file1的大型檔案後備儲存
 12 Created fileio file1 with size 1073741824
 13 /backstores> ls						#檢視建立情況
 14 o- backstores ....................................................................................... [...]
 15   o- block ........................................................................... [Storage Objects: 2]
 16   | o- block1 ....................................... [/dev/iSCSI/disk1_lv (2.0GiB) write-thru deactivated]
 17   | o- block2 ................................................. [/dev/sdc1 (3.0GiB) write-thru deactivated]
 18   o- fileio .......................................................................... [Storage Objects: 1]
 19   | o- file1 ........................................... [/root/disk1_file (1.0GiB) write-back deactivated]
 20   o- pscsi ........................................................................... [Storage Objects: 0]
 21   o- ramdisk ......................................................................... [Storage Objects: 0]

五 建立相應的IQN

  1 /backstores> cd /iscsi
  2 /iscsi> create iqn.2016-09.com.example:remotedisk1	#建立符合名稱的IQN名稱
  3 /iscsi> ls
  4 o- iscsi ..................................................................................... [Targets: 2]
  5   o- iqn.2003-01.org.linux-iscsi.system1.x8664:sn.5792c2787dd8 .................................. [TPGs: 1]
  6   | o- tpg1 ........................................................................ [no-gen-acls, no-auth]
  7   |   o- acls ................................................................................... [ACLs: 0]
  8   |   o- luns ................................................................................... [LUNs: 0]
  9   |   o- portals ............................................................................. [Portals: 0]
 10   o- iqn.2016-09.com.example:remotedisk1 ........................................................ [TPGs: 1]
 11     o- tpg1 ........................................................................ [no-gen-acls, no-auth]
 12       o- acls ................................................................................... [ACLs: 0]
 13       o- luns ................................................................................... [LUNs: 0]
 14       o- portals ............................................................................. [Portals: 0]

六 建立相應的ACL規則

  1 /iscsi> cd iqn.2016-09.com.example:remotedisk1/tpg1/
  2 /iscsi/iqn.20...otedisk1/tpg1> acls/ create iqn.2016-09.com.example:desktop0
  3 #只允許 iqn.2016-09.com.example:desktop0客戶端使用此iSCSI提供磁碟服務
  4 /iscsi/iqn.20...otedisk1/tpg1> ls
  5 o- tpg1 ............................................................................ [no-gen-acls, no-auth]
  6   o- acls ....................................................................................... [ACLs: 1]
  7   | o- iqn.2016-09.com.example:desktop0 .................................................. [Mapped LUNs: 0]
  8   o- luns ....................................................................................... [LUNs: 0]
  9   o- portals ................................................................................. [Portals: 0]

七 為後備儲存建立LUN

注意:

1 之前建立的ACL將分配到每個LUN。

2 建立LUN必須在TPG下

  1 /iscsi/iqn.20...otedisk1/tpg1> luns/ create /backstores/block/block1
  2 #將之前建立的後備磁碟block1建立一個LUN
  3 Created LUN 0.
  4 Created LUN 0->0 mapping in node ACL iqn.2016-09.com.example:desktop0
  5 /iscsi/iqn.20...otedisk1/tpg1> luns/ create /backstores/block/block2	#將之前建立的後備磁碟block2建立一個LUN
  6 Created LUN 1.
  7 Created LUN 1->1 mapping in node ACL iqn.2016-09.com.example:desktop0
  8 /iscsi/iqn.20...otedisk1/tpg1> luns/ create /backstores/fileio/file1	#將之前建立的後備磁碟file1建立一個LUN
  9 Created LUN 2.
 10 Created LUN 2->2 mapping in node ACL iqn.2016-09.com.example:desktop0
 11 /iscsi/iqn.20...otedisk1/tpg1> ls					#檢視所有資訊
 12 o- tpg1 ............................................................................ [no-gen-acls, no-auth]
 13   o- acls ....................................................................................... [ACLs: 1]								#ACL規則1條均分配在三個LUN中
 14   | o- iqn.2016-09.com.example:desktop0 .................................................. [Mapped LUNs: 3]
 15   |   o- mapped_lun0 ............................................................. [lun0 block/block1 (rw)]
 16   |   o- mapped_lun1 ............................................................. [lun1 block/block2 (rw)]
 17   |   o- mapped_lun2 ............................................................. [lun2 fileio/file1 (rw)]
 18   o- luns ....................................................................................... [LUNs: 3]								#三個LUN均對應後備磁碟
 19   | o- lun0 .......................................................... [block/block1 (/dev/iSCSI/disk1_lv)]
 20   | o- lun1 .................................................................... [block/block2 (/dev/sdc1)]
 21   | o- lun2 ............................................................. [fileio/file1 (/root/disk1_file)]
 22   o- portals ................................................................................. [Portals: 0]
 23 /iscsi/iqn.20...otedisk1/tpg1>

八 指定偵聽IP地址和埠

注意:

1 若不指定埠將採用預設埠3260

2 若不指定IP,將允許伺服器上定義的所有網路介面上的連線

3 建立LUN必須在TPG下

  1 /iscsi/iqn.20...otedisk1/tpg1> portals/ create 172.24.8.11	#指定本地用於偵聽客戶端連線的IP
  2 Using default IP port 3260
  3 Created network portal 172.24.8.0:3260.

九 檢查並儲存退出

最後檢查ls一遍,然後儲存退出

  1 /iscsi> cd /
  2 /> ls
  3 o- / ................................................................................................ [...]
  4   o- backstores ..................................................................................... [...]
  5   | o- block ......................................................................... [Storage Objects: 2]
  6   | | o- block1 ....................................... [/dev/iSCSI/disk1_lv (2.0GiB) write-thru activated]
  7   | | o- block2 ................................................. [/dev/sdc1 (3.0GiB) write-thru activated]
  8   | o- fileio ........................................................................ [Storage Objects: 1]
  9   | | o- file1 ........................................... [/root/disk1_file (1.0GiB) write-back activated]
 10   | o- pscsi ......................................................................... [Storage Objects: 0]
 11   | o- ramdisk ....................................................................... [Storage Objects: 0]
 12   o- iscsi ................................................................................... [Targets: 1]
 13   | o- iqn.2016-09.com.example:remotedisk1 ...................................................... [TPGs: 1]
 14   |   o- tpg1 ...................................................................... [no-gen-acls, no-auth]
 15   |     o- acls ................................................................................. [ACLs: 1]
 16   |     | o- iqn.2016-09.com.example:desktop0 ............................................ [Mapped LUNs: 3]
 17   |     |   o- mapped_lun0 ....................................................... [lun0 block/block1 (rw)]
 18   |     |   o- mapped_lun1 ....................................................... [lun1 block/block2 (rw)]
 19   |     |   o- mapped_lun2 ....................................................... [lun2 fileio/file1 (rw)]
 20   |     o- luns ................................................................................. [LUNs: 3]
 21   |     | o- lun0 .................................................... [block/block1 (/dev/iSCSI/disk1_lv)]
 22   |     | o- lun1 .............................................................. [block/block2 (/dev/sdc1)]
 23   |     | o- lun2 ....................................................... [fileio/file1 (/root/disk1_file)]
 24   |     o- portals ........................................................................... [Portals: 1]
 25   |       o- 172.24.8.0:3260 ......................................................................... [OK]
 26   o- loopback ................................................................................ [Targets: 0]
 27 /> exit

十 防火牆開放

  1 [[email protected] ~]# firewall-cmd --add-port=3260/tcp		#防火牆新增iSCSI的埠
  2 Warning: ALREADY_ENABLED
  3 [[email protected] ~]# firewall-cmd --add-port=3260/tcp --permanent	#防火牆開放此埠
  4 success

十一 開啟服務

  1 [[email protected] ~]# systemctl start target
  2 [[email protected] ~]# systemctl enable target