linux学习之ISCSI网络共享服务

######iSCSI远程块存储######

 

.iSCSI概念 提供iSCSI目标 访问iSCSI存储

iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令。iSCSI限定名称用于确定发起端和目

,并采用iqn.yyyy-mm.{reverse domain}:label的格式。默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文。

iSCSI发起端:需要访问原始SAN存储的客户端。

iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”

iSCSI目标门户:通过网络向发起端提供目标的服务器。

IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,最好的做法是使用一个在Internet上可能独一无二的名称。

 

.

linux学习之ISCSI网络共享服务

linux学习之ISCSI网络共享服务

.进入iSCSI目标交互式配置模式

desktop34为服务端  server34为客户端

1.建立需要的lvm卷

[[email protected] ~]# fdisk /dev/vdb

  Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2050047     1024000   8e  Linux LVM

[[email protected] ~]# partprobe

linux学习之ISCSI网络共享服务

[[email protected] ~]# pvcreate /dev/vdb1

  Physical volume "/dev/vdb1" successfully created

[[email protected] ~]# vgcreate  vg0 /dev/vdb1

  Volume group "vg0" successfully created

[[email protected] ~]# vgdisplay

[[email protected] ~]# lvcreate -l 249 -n iscsi_storage vg0  ##建立名为iscsi_storage的逻辑卷,大小为249个pe

  Logical volume "iscsi_storage" created

[[email protected] ~]# lvs

  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert

  iscsi_storage vg0  -wi-a----- 996.00m     

 linux学习之ISCSI网络共享服务                                       

2.服务端

[[email protected] ~]# yum install targetcli -y ##iscsi远程共享服务

[[email protected] ~]# systemctl start target.service

[[email protected] ~]# systemctl enable target.service

[[email protected] ~]# targetcli ##

/>ls

linux学习之ISCSI网络共享服务

/> /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   ##创建一个名为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.2017-06.com.example:server1storagekey   ##设置钥匙

Created Node ACL for iqn.2017-06.com.example:strage1key

Created mapped LUN 0.

/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals  create 172.25.254.134 ##该服务使用的是3260端口

Using default IP port 3260

Created network portal 172.25.254.134:3260.

/> exit

Global pref auto_save_on_exit=true

Last 10 configs saved in /etc/target/backup.

Configuration saved to /etc/target/saveconfig.json

 linux学习之ISCSI网络共享服务

 

 

3.客户端

[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi ##写入服务端设置的钥匙

[[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2017-06.com.example:server1storagekey

[[email protected] ~]# systemctl restart iscsi

linux学习之ISCSI网络共享服务

[[email protected] ~]# iscsiadm -m discovery -t st -p 172.25.254.134 ##查找iscsi服务端所共享的目标

172.25.254.134:3260,1 iqn.2017-06.com.example:strage1

[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.134 -l ##通过3260短口登陆

[[email protected] ~]# fdisk -l ##查看设备,/dev/sda设备即远程共享

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

 linux学习之ISCSI网络共享服务

挂载

[[email protected] ~]# fdisk /dev/sda         ##建立sda1分区

[[email protected] ~]# partprobe

[[email protected] ~]# mkfs.xfs /dev/sda1         ##格式化

[[email protected] ~]# mount /dev/sda1  /mnt/ ##挂载在本机

[[email protected] ~]# tree -C /var/lib/iscsi/ ##

测试

linux学习之ISCSI网络共享服务

[[email protected] ~]# umount /mnt/

[[email protected] ~]# blkid ##查看设备信息

/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"

/dev/vdb: PTTYPE="dos"

/dev/sda1: UUID="308836da-acba-412d-b1bf-f723103d52ee" TYPE="xfs"

[[email protected] ~]# vim /etc/fstab ##开机自动挂载,因为是网络共享设备,所以要先启动网络挂载此设备

UUID="308836da-acba-412d-b1bf-f723103d52ee" /mnt xfs defaults,_netdev 0   0

 linux学习之ISCSI网络共享服务

删除

[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.134 -u  ##登出网络设备

[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.254.134 -o delete ##删除信息

[[email protected] ~]# tree -C /var/lib/iscsi/    ##查看,无配置信息

 linux学习之ISCSI网络共享服务

 

 

4.服务端删除

 

[[email protected] ~]# targetcli

/> clearconfig confirm=True ##清除iscsi的所有配置信息

All configuration cleared

 

 linux学习之ISCSI网络共享服务