一.简介

iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的、可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

iSCSI是一种基于TCP/IP 的协议,用来建立和管理IP存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于C/S模式,其通常应用环境是:设备互相靠近,并且这些设备由SCSI 总线连接。

iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。iSCSI可分享的设备类型有很多,包括镜像文件(*.img)、分区(partition)、物理硬盘、raid设备、逻辑卷等。

二.实验

1. ISCSI 服务端: 172.16.97.136

    ISCSI 客户端: 172.16.97.138

2. 关闭Selinux,打开防火墙端口

[root@localhost ~]# setenforce 0
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success

3. 查看服务端系统磁盘信息,并创建LVM,使用LVM管理便于磁盘的扩展

#查看硬盘配置
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6.2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sdc 8:32 0 8G 0 disk sdd 8:48 0 8G 0 disk sde 8:64 0 8G 0 disk sr0 11:0 1 1024M 0 rom #格式化物理磁盘为PV
[root@localhost
~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. [root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <7.00g 0 /dev/sdb lvm2 --- 8.00g 8.00g
#创建VG [root@localhost
~]# vgcreate linux-pv /dev/sdb Volume group "linux-pv" successfully created [root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <7.00g 0 linux-pv 1 0 0 wz--n- <8.00g <8.00g
#创建逻辑卷 [root@localhost
~]# lvcreate -n share-lv -L 4G linux-pv Logical volume "share-lv" created. [root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <6.20g swap centos -wi-ao---- 820.00m share-lv linux-pv -wi-a----- 4.00g [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6.2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 8G 0 disk └─linux--pv-share--lv 253:2 0 4G 0 lvm sdc 8:32 0 8G 0 disk sdd 8:48 0 8G 0 disk sde 8:64 0 8G 0 disk sr0 11:0 1 1024M 0 rom

4. 服务端安装配置iSCSI

#安装target服务
[root@localhost ~]# yum -y install targetd targetcli
[root@localhost ~]# systemctl start targetd
[root@localhost ~]# systemctl enable targetd
Created symlink from /etc/systemd/system/multi-user.target.wants/targetd.service to /usr/lib/systemd/system/targetd.service.

 

[root@localhost ~]# 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/
/backstores> cd block 
/backstores/block> create 
dev=       name=      readonly=  wwn=       
/backstores/block> create share-disk /dev/linux-pv/share-lv 
Created block storage object share-disk using /dev/linux-pv/share-lv.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 1]
  o- share-disk ........................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated]
    o- alua ....................................................................................................... [ALUA Groups: 1]
      o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
/backstores/block> cd ..
/backstores> ls 
o- backstores ................................................................................................................ [...]
  o- block .................................................................................................... [Storage Objects: 1]
  | o- share-disk ......................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated]
  |   o- alua ..................................................................................................... [ALUA Groups: 1]
  |     o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
  o- fileio ................................................................................................... [Storage Objects: 0]
  o- pscsi .................................................................................................... [Storage Objects: 0]
  o- ramdisk .................................................................................................. [Storage Objects: 0]
/backstores> cd..
/> ls 
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- share-disk ....................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru deactivated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/> cd iscsi 
/iscsi> ls 
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi> create iqn.2019-05.com.share-disk:server
Created target iqn.2019-05.com.share-disk:server.
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.2019-05.com.share-disk:server ................................................................................... [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.2019-05.com.share-disk:server/
/iscsi/iqn.20...e-disk:server> tpg1/
/iscsi/iqn.20...k:server/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...k:server/tpg1> cd luns 
/iscsi/iqn.20...ver/tpg1/luns> ls 
o- luns .................................................................................................................. [LUNs: 0]
/iscsi/iqn.20...ver/tpg1/luns> cd ..
/iscsi/iqn.20...k:server/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...k:server/tpg1> cd acls 
/iscsi/iqn.20...ver/tpg1/acls> ls 
o- acls .................................................................................................................. [ACLs: 0]
/iscsi/iqn.20...ver/tpg1/acls> create iqn.2019-05.com.share-disk:client
Created Node ACL for iqn.2019-05.com.share-disk:client
/iscsi/iqn.20...ver/tpg1/acls> cd ..
/iscsi/iqn.20...k:server/tpg1> ls 
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
  o- acls ................................................................................................................ [ACLs: 1]
  | o- iqn.2019-05.com.share-disk:client .......................................................................... [Mapped LUNs: 0]
  o- luns ................................................................................................................ [LUNs: 0]
  o- portals .......................................................................................................... [Portals: 1]
    o- 0.0.0.0:3260 ........................................................................................................... [OK]
/iscsi/iqn.20...k:server/tpg1> cd luns 
/iscsi/iqn.20...ver/tpg1/luns> create /backstores/block/share-disk 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-05.com.share-disk:client
/iscsi/iqn.20...ver/tpg1/luns> ls 
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 ........................................................... [block/share-disk (/dev/linux-pv/share-lv) (default_tg_pt_gp)]
/iscsi/iqn.20...ver/tpg1/luns> cd ..
/iscsi/iqn.20...k:server/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> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 172.16.97.61 3260
Using default IP port 3260
Created network portal 172.16.97.61:3260.
/iscsi/iqn.20.../tpg1/portals> ls 
o- portals ............................................................................................................ [Portals: 1]
  o- 172.16.97.61:3260 ........................................................................................................ [OK]
/iscsi/iqn.20.../tpg1/portals> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- share-disk ......................................................... [/dev/linux-pv/share-lv (4.0GiB) write-thru activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2019-05.com.share-disk:server ................................................................................. [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2019-05.com.share-disk:client .................................................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................................................ [lun0 block/share-disk (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................... [block/share-disk (/dev/linux-pv/share-lv) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 172.16.97.61:3260 ................................................................................................ [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄