iSCSI是一種基于TCP/IP 的協(xié)議,用來建立和管理IP存儲設(shè)備、主機和客戶機等之間的相互連接贵扰,并創(chuàng)建存儲區(qū)域網(wǎng)絡(luò)(SAN)赢笨。SAN 使得SCSI 協(xié)議應(yīng)用于高速數(shù)據(jù)傳輸網(wǎng)絡(luò)成為可能端朵,這種傳輸以數(shù)據(jù)塊級別(block-level)在多個數(shù)據(jù)存儲網(wǎng)絡(luò)間進行。SCSI 結(jié)構(gòu)基于C/S模式婉弹,其通常應(yīng)用環(huán)境是:設(shè)備互相靠近荠卷,并且這些設(shè)備由SCSI 總線連接。
·
簡單來說
就是把SCSI指令通過TCP/IP協(xié)議封裝起來瑞你,在以太網(wǎng)中傳輸酪惭。iSCSI 可以實現(xiàn)在IP網(wǎng)絡(luò)上傳遞和運行SCSI協(xié)議,使其能夠在諸如高速千兆以太網(wǎng)上進行數(shù)據(jù)存取者甲,實現(xiàn)了數(shù)據(jù)的網(wǎng)際傳遞和管理春感。基于iSCSI建立的存儲區(qū)域網(wǎng)(SAN)與基于光纖的FC-SAN相比虏缸,具有很好的性價比鲫懒。
實驗
關(guān)閉了selinux 和防火墻,centos7
target (服務(wù)器): 192.168.247.149
Initiator(客戶端):192.168.247.154
服務(wù)端
新加一塊硬盤刽辙,用來做存儲
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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
創(chuàng)建磁盤并格式化
一個硬盤主 分區(qū)至少有1個窥岩,最多4個,擴展分區(qū)可以沒有宰缤,最多1個颂翼。且主分區(qū)+擴展分區(qū)總共不能超過4個。
為了突破這最多四個主分區(qū)的限制慨灭,管理員可以把其中一個主分區(qū)設(shè)置為擴展分區(qū)(注意只能夠使用一個擴展分區(qū))來進行擴充朦乏。而在擴充分區(qū)下,又可以建立多個邏輯分區(qū)氧骤。也就是說集歇,擴展分區(qū)是無法直接使用的,必須在細分成邏輯分區(qū)才可以用來存儲數(shù)據(jù)语淘。通常情況下诲宇,邏輯分區(qū)的起始位置及結(jié)束位置記錄在每個邏輯分區(qū)的第一個扇區(qū),這也叫做擴展分區(qū)表惶翻。在擴展分區(qū)下姑蓝,系統(tǒng)管理員可以根據(jù)實際情況建立多個邏輯分區(qū),將一個擴展分區(qū)劃割成多個區(qū)域來使用吕粗。
格式化為LVM(LVM是 Logical Volume Manager邏輯卷管理)
LVM的好處就是可以按需分配纺荧,動態(tài)管理
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #必須要一個主分區(qū)
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): t #類型
Selected partition 1 #編號 可按 L 查看要創(chuàng)建的格式
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p #查看
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xea844b86
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 8e Linux LVM
保存即可
partprobe #是配置生效
創(chuàng)建邏輯卷
[root~] ]$pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root~] ]$pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 59.78g 0
/dev/sdb1 lvm2 --- 20.00g 20.00g
[root~] ]$vgcreate vg_iscsi /dev/sdb1
Volume group "vg_iscsi" successfully created
[root~] ]$vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 59.78g 0
vg_iscsi 1 0 0 wz--n- 20.00g 20.00g
[root~] ]$lvcreate -l 100%FREE -n /dev/vg_iscsi/lv_iscsi
Logical volume "lv_iscsi" created.
[root~] ]$lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 57.78g
swap centos -wi-ao---- 2.00g
lv_iscsi vg_iscsi -wi-a----- 20.00g
安裝配置target
[root~] ]$yum -y install targetcli
[root~] ]$targetcli
#最初狀態(tài)
/> 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
/backstores/block> create sdb1_iscsi /dev/vg_iscsi/lv_iscsi
Created block storage object sdb1_iscsi using /dev/vg_iscsi/lv_iscsi.
切換到iscsi下
/iscsi> create iqn.2017-05.com.master:ip149 #注意全局唯一,格式iqn.日期(日期只能有年月并且月份必須加0.顛倒的domain:自定義標識
/iscsi/iqn.20...149/tpg1/acls> create iqn.2017-05.com.master:ip149
Created Node ACL for iqn.2017-05.com.master:ip149
/iscsi/iqn.20...149/tpg1/acls> cd ../luns
/iscsi/iqn.20...149/tpg1/luns> create /backstores/block/sdb1_iscsi
/iscsi/iqn.20...149/tpg1/luns> cd ../portals/
/iscsi/iqn.20.../tpg1/portals> create 192.168.247.149
Using default IP port 3260
/iscsi/iqn.20.../tpg1/portals> cd /
#完成狀態(tài)
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 1]
| | o- sdb1_iscsi ........................................................ [/dev/vg_iscsi/lv_iscsi (20.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.2017-05.com.master:ip149 ...................................................................................... [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 1]
| | o- iqn.2017-05.com.master:ip149 ......................................................................... [Mapped LUNs: 1]
| | o- mapped_lun0 ............................................................................ [lun0 block/sdb1_iscsi (rw)]
| o- luns .......................................................................................................... [LUNs: 1]
| | o- lun0 ...................................................................... [block/sdb1_iscsi (/dev/vg_iscsi/lv_iscsi)]
| o- portals .................................................................................................... [Portals: 1]
| o- 0.0.0.0:3260 ..................................................................................................... [OK]
o- loopback ......................................................................................................... [Targets: 0]
/> exit
啟動服務(wù)
[root~] ]$systemctl start target.service
[root~] ]$systemctl enable target.service
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root~] ]$
客戶端
[root~] ]$yum -y install iscsi-initiator*
[root~] ]$vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-05.com.master:ip149 #服務(wù)器的iqn
[root@minion-02 /]# systemctl restart iscsi
[root@minion-02 /]# iscsiadm -m discovery -t st -p 192.168.247.149
192.168.247.149:3260,1 iqn.2017-05.com.master:ip149
[root@minion-02 /]# iscsiadm -m node -T iqn.2017-05.com.master:ip149 -p 192.168.247.149 -l
Logging in to [iface: default, target: iqn.2017-05.com.master:ip149, portal: 192.168.247.149,3260] (multiple)
Login to [iface: default, target: iqn.2017-05.com.master:ip149, portal: 192.168.247.149,3260] successful.
[root@minion-02 /]# fdisk -l
#可以看到iscsi已經(jīng)掛上 為sdb
Disk /dev/sdb: 21.5 GB, 21470642176 bytes, 41934848 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
[root@minion-02 /]#
#sdb就像是新加的硬盤,我們可以fdisk 它
n p 1 enter enter w
我們可以對這個盤進行單獨的掛載宙暇。切記不可擴展到某個分區(qū)
掛載
[root@minion-02 /]# mkfs.xfs /dev/sdb1
[root@minion-02 /]# mkdir /mnt/iscsi
[root@minion-02 /]# mount /dev/sdb1 /mnt/iscsi/
[root@minion-02 /]# blkid
/dev/sda1 : UUID="64f589c2-2ac4-47f7-8d35-170913a2563f" TYPE=”xfs”
[root@minion-02 /]# vim /etc/fstab
UUID="64f589c2-2ac4-47f7-8d35-170913a2563f" /mnt/iscsi xfs defaults,_netdev 0 0
fstab一定呀寫對输枯,不然系統(tǒng)重啟會啟動不起來,特別注意占贫。
萬一 啟動不起來怎么辦桃熄?
重啟虛擬機 按 e 進行編輯
修改ro rd........等 為 ro.break
switch_root:/# mount –o remount,rw /sysroot/
switch_root:/# chroot /sysroot/
sh-4.2#vi /etc/fstab #重新編輯
##這里還可以修改root密碼。
passwd root型奥。
如果忘記密碼也可用這個辦法修改