#################iscsi################node
#####################################shell
iSCSI(Internet SCSI)支持從客戶端(發起端)經過IP向遠程服務器上的json
SCSI存儲設備(目標)發送SCSI命令。iSCSI限定名稱用於肯定發起端和目vim
標,並採用iqn.yyyy-mm.{reverse domain}:label的格式。默認狀況下,網絡服務器
通訊是至iSCSI目標上的端口3260/tcp的明文。網絡
l iSCSI發起端:須要訪問原始SAN存儲的客戶端。app
l iSCSI目標:從iSCSI服務器提供的遠程硬盤磁盤,或「目標門戶」dom
l iSCSI目標門戶:經過網絡向發起端提供目標的服務器。tcp
lide
IQN:「iSCSI限定名稱」。每一個發起端和目標須要惟一名稱進行標識,
最好的作法是使用一個在Internet上可能獨一無二的名稱。
1.在server端
先對vdb進行分區
[root@server ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created
[root@server ~]# vgcreate vg0 /dev/vdb1
Volume group "vg0" successfully created
[root@server ~]# lvcreate -l 249 -n iscsi_storage vg0
Logical volume "iscsi_storage" created
[root@server ~]# lvs ##查看lvm設備
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsi_storage vg0 -wi-a----- 996.00m
安裝iscsi目標軟件包
yum install -y targetcli
systemctl enable target
systemctl start target
systemctl stop firewalld
進入iscsi目標交互式配置模式
[root@server ~]# 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 .........................................
/> /backstores/block create server1storage /dev/vg0/iscsi_storage
Created block storage object server1storage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:stragel
Created target iqn.2017-06.com.example:stragel.
Created TPG 1.
/> clearconfig confirm=True
All configuration cleared
/> 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 create server1storage /dev/vg0/iscsi_storage
Created block storage object server1storage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:strage1
Created target iqn.2017-06.com.example:strage1.
Created TPG 1.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage
Created LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.017-06.com.example:server1storagekey
WWN not valid as: iqn, naa, eui
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey
Created Node ACL for iqn.2017-06.com.example:server1storagekey
Created mapped LUN 0.
/> /iscsi
/iscsi> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
systemctl restart iscsi
2.在desktop端
systemctl stop firewalld
systemctl disable firewalld
[root@desktop ~]# vim /etc/iscsi/initiatorname.iscsi ###在/etc/iscsi/initiatorname.iscsi中設置發起端的IQN
[root@desktop ~]# iscsiadm -m discovery -t st -p 172.25.254.102 ###查找iscai服務器所提供的iscsi目標
172.25.254.102:3260,1 iqn.2017-06.com.example:strage1
[root@desktop ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.102 -l 登錄服務器上的一個或多個iscsi目標
Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.254.102,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.254.102,3260] successful.
[root@desktop ~]# fdisk -l
Disk /dev/sda: 1044 MB, 1044381696 bytes, 2039808 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
對sda進行分區
[root@desktop ~]# partprobe ###同步分區表
[root@desktop ~]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@desktop ~]# mkfs.xfs /dev/sda1 -f
meta-data=/dev/sda1 isize=256 agcount=8, agsize=31744 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=253952, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@desktop ~]# mount /dev/sda1 /mnt
[root@desktop ~]# yum install -y tree
[root@desktop ~]# tree -C /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2017-06.com.example:strage1
│ └── 172.25.254.102,3260,1
│ └── default
├── send_targets
│ └── 172.25.254.102,3260
│ ├── iqn.2017-06.com.example:strage1,172.25.254.102,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:strage1/172.25.254.102,3260,1
│ └── st_config
├── slp
└── static
[root@desktop ~]# blkid ###查看分區的UUID
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/sda1: UUID="4fc4230e-3b7d-42fc-a11a-1d1d07968289" TYPE="xfs"
寫自動掛載
vim /etc/fstab
3.刪除客戶端的數據
iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.102 -u
##確保iscsi服務在引導時啓動。
##確保沒有使用目標所提供的任何設備。
##確保從/etc/fstab等位置中刪除使用目標的全部永久掛載
##登出iSCSI目標,以暫時斷開鏈接。
iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.102 -o delete
###刪除iSCSI目標的本地記錄,以永久斷開鏈接。
4.刪除服務端的數據
clearconfig confirm=Ture ##清除iscsi的全部信息