linux學習-使用iSCSI服務部署網絡存儲
1、 網絡存儲技術
傳統的SCSI小型計算機系統接口(Small Computer System Interface)技術是存儲設備最基本的標準協議,但通常需要設備互相靠近並用SCSI總線鏈接,因此受到了物理環境的限制。
iSCSI小型計算機系統接口(即Internet Small Computer System Interface)則是由IBM公司研究開發用於實現在IP網絡上運行SCSI協議的新存儲技術,即能夠讓SCSI接口與以太網技術相結合,使用iSCSI協議基於以太網傳送SCSI命令與數據,克服了SCSI需要直接連接存儲設備的局限性,使得我們可以跨越不同的服務器共享存儲設備,並可以做到不停機狀態下擴展存儲容量。
SAN存儲區域網絡技術(Storage Area Network)便是基於iSCSI存儲協議,采用高速光釬通道傳輸存儲數據的服務程序。
2 部署iSCSI存儲
iSCSI的工作方式分為服務端(target)與客戶端(initiator):
服務端:即存放硬盤或RAID設備的存儲端,目的是為客戶端提供可用的存儲。
客戶端:使用服務端的服務器主機。
本實驗需要兩臺虛擬主機來完成,分別是:
主機名稱 |
操作系統 |
IP地址 |
iscsi服務端 |
紅帽RHEL7操作系統 |
192.168.10.10 |
iscsi客戶端 |
紅帽RHEL7操作系統 |
192.168.10.20 |
邏輯單元LUN(即Logical Unit Number)是使用iSCSI協議中的重要概念,因為當客戶機想要使用服務端存儲設備時都必需輸入對應的名稱(Target ID),而一個服務端可能會同時提供多個可用的存儲設備,於是便用LUN來詳細的描述設備或對象,同時每個LUN Device可能代表一個硬盤或RAID設備,LUN的名稱由用戶指定。
配置iSCSI服務端:
第1步:準備作為LUN發布的存儲設備。
在虛擬機中再添加4塊硬盤:
創建RAID5並設置1塊備份故障盤:
[[email protected] ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
查看RAID陣列的詳細信息,記錄下UUID的值:
[[email protected] ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Sep 24 21:59:57 2015
Raid Level : raid5
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Thu Sep 24 22:02:23 2015
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : 3370f643:c10efd6a:44e91f2a:20c71f3e
Events : 26
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde
創建RAID陣列配置文件:
[[email protected] ~]# vim /etc/mdadm.conf
DEVICE /dev/sdb /dev/sdc /dev/sdd /dev/sde
ARRAY /dev/md0 UUID=3370f643:c10efd6a:44e91f2a:20c71f3e
第2步:安裝iSCSI target服務程序:
[[email protected] ~]# yum -y install targetd targetcli
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分安裝信息………………
Installing:
targetcli noarch 2.1.fb34-1.el7 rhel7 55 k
targetd noarch 0.7.1-1.el7 rhel7 48 k
Complete!
啟動iSCSI target服務程序:
[[email protected] ~]# systemctl start targetd
將iSCSI target服務程序添加到開機啟動項:
[[email protected] ~]# systemctl enable targetd
ln -s ‘/usr/lib/systemd/system/targetd.service‘ ‘/etc/systemd/system/multi-user.target.wants/targetd.service‘
第3步:創建存儲對象。
targetcli命令用於管理iSCSI target存儲設備,格式為:“targetcli”
[[email protected] ~]# targetcli
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目錄中:
/> cd /backstores/block
/backstores/block>
使用/dev/md0創建設備disk0:
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
返回到根目錄中:
/backstores/block> cd ..
/backstores> cd ..
/>
查看創建後的設備:
/> ls
o- / ..................................................................... [...]
o- backstores .......................................................... [...]
| o- block .............................................. [Storage Objects: 1]
| | o- disk0 ..................... [/dev/md0 (40.0GiB) write-thru deactivated]
| o- fileio ............................................. [Storage Objects: 0]
| o- pscsi .............................................. [Storage Objects: 0]
| o- ramdisk ............................................ [Storage Objects: 0]
o- iscsi ........................................................ [Targets: 0]
o- loopback ..................................................... [Targets: 0]
第4步:配置iSCSI target目標。
進入到iscsi目錄中:
/> cd iscsi
/iscsi>
創建iSCSI target目標:
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80.
Created TPG 1.
依次進入到target的luns目錄中:
/iscsi> cd iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80/
/iscsi/iqn.20....d497c356ad80> ls
o- iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80 ...... [TPGs: 1]
o- tpg1 ............................................... [no-gen-acls, no-auth]
o- acls .......................................................... [ACLs: 0]
o- luns .......................................................... [LUNs: 0]
o- portals .................................................... [Portals: 0]
/iscsi/iqn.20....d497c356ad80> cd tpg1/
/iscsi/iqn.20...c356ad80/tpg1> cd luns
/iscsi/iqn.20...d80/tpg1/luns>
創建LUN設備:
/iscsi/iqn.20...d80/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
第5步:設置訪問控制列表。
切換到acls目錄中:
/iscsi/iqn.20...d80/tpg1/luns> cd ..
/iscsi/iqn.20...c356ad80/tpg1> cd acls
創建訪問控制列表:
/iscsi/iqn.20...d80/tpg1/acls> create iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80:client
Created mapped LUN 0.
切換到portals目錄中:
/iscsi/iqn.20...d80/tpg1/acls> cd ..
/iscsi/iqn.20...c356ad80/tpg1> cd portals
添加允許監聽的IP地址:
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.10
Using default IP port 3260
Created network portal 192.168.10.10:3260.
查看配置概述後退出工具:
/iscsi/iqn.20.../tpg1/portals> ls /
o- / ........................... [...]
o- backstores................. [...]
| o- block ................... [Storage Objects: 1]
| | o- disk0 ................. [/dev/md0 (40.0GiB) write-thru activated]
| o- fileio .................. [Storage Objects: 0]
| o- pscsi ................... [Storage Objects: 0]
| o- ramdisk ................. [Storage Objects: 0]
o- iscsi ..................... [Targets: 1]
| o- iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80 .... [TPGs: 1]
| o- tpg1 .................. [no-gen-acls, no-auth]
| o- acls ........................................................ [ACLs: 1]
| | o- iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80:client [Mapped LUNs: 1]
| | o- mapped_lun0 ............................................. [lun0 block/disk0 (rw)]
o- luns .................... [LUNs: 1]
| | o- lun0 .............. [block/disk0 (/dev/md0)]
| o- portals ............. [Portals: 1]
| o- 192.168.10.20: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
第4步:創建防火墻允許規則:
[[email protected] ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[[email protected] ~]# firewall-cmd --reload
success
配置iSCSI客戶端:
首先檢查能夠與iscsi服務端通信:
[[email protected] ~]# ping -c 4 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.959 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.469 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.465 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.277 ms
--- 192.168.10.10 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.277/0.542/0.959/0.253 ms
紅帽RHEL7系統已經默認安裝了iscsi客戶端服務程序:
[[email protected] ~]# yum install iscsi-initiator-utils
Loaded plugins: langpacks, product-id, subscription-manager
Package iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 already installed and latest version
Nothing to do
編輯的iscsi客戶端名稱文件:
該名稱是initiator客戶端的唯一標識,讀者可以按照我的方法修改,也可以用iscsi-iname命令隨機生成~都可以的。
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80:client
重啟iscsi客戶端服務程序:
[[email protected] ~]# systemctl restart iscsid
將iscsi客戶端服務程序添加到開機啟動項中:
[[email protected] ~]# systemctl enable iscsid
ln -s ‘/usr/lib/systemd/system/iscsid.service‘ ‘/etc/systemd/system/multi-user.target.wants/iscsid.service‘
發現iscsi服務端的可用存儲設備:
iscsiadm命令用於管理(插入、查詢、更新或刪除)iSCSI數據庫配置文件的命令行工具,格式見下面演示。
[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.10.10
192.168.10.10:3260,1 iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80
連接iscsi服務端的可用存儲設備:
[[email protected] ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80 -p 192.168.10.10 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80, portal: 192.168.10.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.linuxprobe.x8664:sn.d497c356ad80, portal: 192.168.10.10,3260] successful.
此時便多了一塊硬盤設備:
[[email protected] ~]# file /dev/sdb
/dev/sdb: block special
格式化、掛載後查看容量信息:
[[email protected] ~]# mkfs.xfs /dev/sdb
log stripe unit (524288 bytes) is too large (maximum is 256KiB)
log stripe unit adjusted to 32KiB
meta-data=/dev/sdb isize=256 agcount=16, agsize=654720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=10475520, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# mkdir /iscsi
[[email protected] ~]# mount /dev/sdb /iscsi
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.4G 15G 20% /
devtmpfs 734M 0 734M 0% /dev
tmpfs 742M 176K 742M 1% /dev/shm
tmpfs 742M 8.8M 734M 2% /run
tmpfs 742M 0 742M 0% /sys/fs/cgroup
/dev/sr0 3.5G 3.5G 0 100% /media/cdrom
/dev/sda1 497M 119M 379M 24% /boot
/dev/sdb 40G 33M 40G 1% /iscsi
查看設備的UUID值:
[[email protected] ~]# blkid | grep /dev/sdb
/dev/sdb: UUID="eb9cbf2f-fce8-413a-b770-8b0f243e8ad6" TYPE="xfs"
設置為開機後自動掛載時因為iSCSI服務程序基於IP網絡傳輸數據,所以我們必需在fstab文件中添加參數_netdev,代表網絡聯通後再掛載:
[[email protected] ~]# vim /etc/fstab
UID=eb9cbf2f-fce8-413a-b770-8b0f243e8ad6 /iscsi xfs defaults,_netdev 0 0
linux學習-使用iSCSI服務部署網絡存儲