使用iSCSI服務部署網路存儲 iSCSI技術實現了物理硬碟設備與TCP/IP網路協議的相互結合,使得用戶可以通過互聯網方便地訪問遠程機房提供的共用存儲資源.下麵介紹如何在Linux上部署iSCSI服務端程式,並分別給予Linux系統和Windows系統來訪問遠程的存儲資源. 實驗環境 主機名稱 | ...
使用iSCSI服務部署網路存儲
iSCSI技術實現了物理硬碟設備與TCP/IP網路協議的相互結合,使得用戶可以通過互聯網方便地訪問遠程機房提供的共用存儲資源.下麵介紹如何在Linux上部署iSCSI服務端程式,並分別給予Linux系統和Windows系統來訪問遠程的存儲資源.
實驗環境
主機名稱 | 操作系統 | IP地址 |
---|---|---|
iSCSI服務端 | RHEL7 | 192.168.56.15 |
iSCSI客戶端 | CentOS7 | 192.168.56.5 |
windows7客戶端 | windows7 | 192.168.56.100 |
1.安裝iSCSI
服務
[root@iSCSI-Server ~]# yum install targetd targetcli -y
//啟動iSCSI服務並加入開機自啟動
[root@iSCSI-Server ~]# systemctl start targetd && systemctl enable targetd
Created symlink from /etc/systemd/system/multi-user.target.wants/targetd.service to /usr/lib/systemd/system/targetd.service.
2.配置iSCSI服務共用資源
//我們要添加sdb這塊磁碟
[root@iSCSI-Server ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 1G 0 part [SWAP]
└─sda3 8:3 0 48.5G 0 part /
sdb 8:16 0 2T 0 disk
sr0 11:0 1 3.8G 0 rom /mnt
[root@iSCSI-Server ~]# 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/block
Created block storage object disk0 using /dev/sdb.
/backstores/block> ls
o- block ............................................................ [Storage Objects: 1]
o- disk0 .................................... [/dev/sdb (2.0TiB) write-thru deactivated]
o- alua ............................................................. [ALUA Groups: 1]
o- default_tg_pt_gp ................................. [ALUA state: Active/optimized]
/backstores/block>
3.創建iSCSI target
名稱及配置共用資源
/backstores/block> cd /
/> cd iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412.
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.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412 ............ [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.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412
/iscsi/iqn.20....a5b591427412> ls
o- iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412 .............. [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/iqn.20....a5b591427412> cd tpg1
/iscsi/iqn.20...91427412/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...91427412/tpg1> cd luns
/iscsi/iqn.20...412/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
/iscsi/iqn.20...412/tpg1/luns> ls
o- luns ........................................................................ [LUNs: 1]
o- lun0 .................................... [block/disk0 (/dev/sdb) (default_tg_pt_gp)]
/iscsi/iqn.20...412/tpg1/luns>
4.設置訪問控制列表(ACL).
/iscsi/iqn.20...412/tpg1/luns> cd ..
/iscsi/iqn.20...91427412/tpg1> ls
o- tpg1 ........................................................... [no-gen-acls, no-auth]
o- acls ...................................................................... [ACLs: 0]
o- luns ...................................................................... [LUNs: 1]
| o- lun0 .................................. [block/disk0 (/dev/sdb) (default_tg_pt_gp)]
o- portals ................................................................ [Portals: 1]
o- 0.0.0.0:3260 ................................................................. [OK]
/iscsi/iqn.20...91427412/tpg1>
/iscsi/iqn.20...91427412/tpg1> cd acls
/iscsi/iqn.20...412/tpg1/acls> ls
o- acls ........................................................................ [ACLs: 0]
/iscsi/iqn.20...412/tpg1/acls> create iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412:client
Created mapped LUN 0.
/iscsi/iqn.20...412/tpg1/acls>
5.設置iSCSI服務端的監聽IP地址和埠號.
/iscsi/iqn.20...412/tpg1/acls> cd ..
/iscsi/iqn.20...91427412/tpg1> ls
o- tpg1 ........................................................... [no-gen-acls, no-auth]
o- acls ...................................................................... [ACLs: 1]
| o- iqn.2003-01.org.linux-iscsi.iscsi-server.x8664:sn.a5b591427412:client [Mapped LUNs: 1]
| o- mapped_lun0 ............................................. [lun0 block/disk0 (rw)]
o- luns ...................................................................... [LUNs: 1]
| o- lun0 .................................. [block/disk0 (/dev/sdb) (default_tg_pt_gp)]
o- portals ................................................................ [Portals: 1]
o- 0.0.0.0:3260 ................................................................. [OK]
/iscsi/iqn.20...91427412/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> create 192.168.56.15
/iscsi/iqn.20.../tpg1/portals> cd /
/> 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
[root@iSCSI-Server ~]#
6.配置妥當後檢查配置信息,重啟iSCSI服務端程式並配置防火牆策略.
[root@iSCSI-Server ~]# systemctl restart targetd
//防火牆可以如下配置
[root@iSCSI-Server ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@iSCSI-Server ~]# firewall-cmd --reload
配置Linux客戶端.
iscsiadm是用於管理、查詢、插入、更新或刪除iSCSI資料庫配置文件的命令行工具,用戶需要先使用這個工具掃描發現遠程iSCSI服務端,然後查看找到的服務端上有哪些可用的共用存儲資源.
-m discovery參數的目的是掃描併發現可用的存儲資源
-t st參數為執行掃描操作的類型
-p 192.168.56.15參數為iSCSI服務端的IP地址
-m node參數為將客戶端所在主機作為一臺節點伺服器
-T 參數為要使用的存儲資源
-p 192.168.56.15參數為對方iSCSI伺服器IP的地址
--login或-l參數進行登陸驗證
//安裝iSCSI客戶端服務程式initiator.預設RHEL7已經安裝了.
[root@iSCSI-Client ~]# yum install iscsi-initiator-utils -y
//編輯名稱文件
[root@iS
CSI-Client ~]# vim /etc/iscsi/initiatorname.iscsi
//重啟客戶端服務程式
[root@iSCSI-Client ~]# systemctl restart iscsid
[root@iSCSI-Client ~]# systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
//先發現再登錄
[root@iSCSI-Client ~]# iscsiadm -m discovery -t st -p 192.168.56.15
192.168.56.15:3260,1 iqn.2003-01.org.linux-iscsi.qdlinux.x8664:sn.f32bb7ada923
//使用iscsiadm命令發現遠程伺服器上可用的存儲資源後,接下來準備登陸iSCSI伺服器
[root@iSCSI-Client ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.qdlinux.x8664:sn.f32bb7ada923 -p 192.168.56.15 --login
登陸成功後查看一下發現多了一塊磁碟
[root@iSCSI-Client ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 47.5G 0 part /
sdb 8:16 0 2T 0 disk
sdc 8:32 0 2T 0 disk
sr0 11:0 1 4.2G 0 rom /mnt
[root@iSCSI-Client ~]# file /dev/sdc
/dev/sdc: block special
//查看設備UUID
[root@iSCSI-Client ~]# blkid
/dev/sda1: UUID="2b924cf3-3741-4489-afda-20ad6c3b8366" TYPE="xfs"
/dev/sda2: UUID="c8ad89d6-ca56-4120-a4b6-5d9c54976bbb" TYPE="swap"
/dev/sda3: UUID="780d3cde-84a6-4f98-a800-94b0dc7f57f9" TYPE="xfs"
/dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdc: UUID="28619840-b497-49ca-92c6-c530a850dd40" TYPE="xfs"
//開機自動掛載,由於iSCSI基於TCP/IP網路傳輸數據的
//因此必須在fstab配置文件中加上`_netdev`參數
//表示當系統聯網後再進行掛載操作,以免系統開機時間過長或開機失敗.
[root@iSCSI-Client ~]# vim /etc/fstab
UUID=28619840-b497-49ca-92c6-c530a850dd40 /iscsi xfs defaults,_netdev 0 0
[root@iSCSI-Client ~]# mount -a
[root@iSCSI-Client ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 4.6G 43G 10% /
devtmpfs 472M 0 472M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 8.0M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sr0 4.2G 4.2G 0 100% /mnt
/dev/sda1 497M 148M 350M 30% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdc 2.0T 33M 2.0T 1% /iscsi
//如果不再需要使用iSCSI共用設備資源了,可以使用iscsiadm命令的-u參數將其卸載.
[root@iSCSI-Client ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.qdlinux.x8664:sn.f32bb7ada923 -u
Logging out of session [sid: 1, target: iqn.2003-01.org.linux-iscsi.qdlinux.x8664:sn.f32bb7ada923, portal: 192.168.56.15,3260]
Logout of [sid: 1, target: iqn.2003-01.org.linux-iscsi.qdlinux.x8664:sn.f32bb7ada923, portal: 192.168.56.15,3260] successful.
配置Windows客戶端.
1.運行iSCSI發起程式.
在Windows7操作系統中已經預設安裝了iSCSI客戶端程式,我們只需要在控制面板中找到系統和安全
標簽,然後點擊管理工具
,進入到管理工具
頁面後點擊iSCSI發起程式
.在第一次運行iSCSI發起程式時,系統會提示Mirosoft iSCSI服務端未運行
,點擊是
按鈕即可自動啟動並運行iSCSI發起程式.
2.掃描發現iSCSI服務端上可用的存儲資源.
不論是Windows系統還是Linux系統,要想使用iSCSI共用存儲資源都必須先進行掃描發現操作.運行iSCSI發起程式後在目標
選項卡的目標
文本框寫入iSCSI伺服器的IP地址,然後點擊快速連接
按鈕.
在彈出的快速鏈接
提示框中可看到共用的硬碟存儲資源,點擊完成
按鈕即可.