iscsi基础知识
简介
iSCSI(Internet Small Computer System Interface,发音为/ˈаɪskʌzi/),Internet小型计算机系统接口,又称为IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术
基于IP协议的SCSI Small Computer System Interface
小型计算机系统接口(英语:Small Computer System Interface; 简写:SCSI),一种用于计算机和智能设备之间(硬盘、软驱、光驱、打印机、扫描仪等)系统级接口的独立处理器标准。 SCSI是一种智能的通用接口标准。
SCSI接口具有应用范围广、多任务、带宽大、CPU占用率低,以及热插拔等优点。
iSCSI(互联网小型计算机系统接口)是一种在TCP/IP上进行数据块传输的标准。它是由Cisco和IBM两家发起的,并且得到了各大存储厂商的大力支持。iSCSI可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行快速的数据存取备份操作。
工作流程
iSCSI系统由SCSI适配器发送一个SCSI命令。
命令封装到TCP/IP包中并送入到以太网络。
接收方从TCP/IP包中抽取SCSI命令并执行相关操作。
把返回的SCSI命令和数据封装到TCP/IP包中,将它们发回到发送方。
系统提取出数据或命令,并把它们传回SCSI子系统。
通过iscsi实现存储共享,创建IQN用于识别启动器和目标,然后建立tpg共享存储组,设置相应的访问控制权限,然后在共享存储组添加lun逻辑单元(存储设备),然后建立实现共享portals入口(ip port)
概念
TPG: 共享存储组,某个特定iSCSI目标要侦听的接口IP地址和TCP端口的集合。可以将目标配置添加到TPG以协调多个LUN的设置。
ACL: 访问权限控制列表,一种使用节点IQN(通常是启动器名称)来验证启动器的访问权限的访问限制
IQN: iSCSI限定名称,全球唯一名称,用于以强制命名格式来识别启动器和目标。
IQN格式如下:
iqn.YYYY-MM.com.reversed.domain[:optional_string]
iqn:表示此名称使用域为标识符。
YYYY-MM:表示拥有域名的年月时间。
com.reversed.domain:拥有此iSCSI组织的逆向域名
:optional_string:以冒号为前缀的可选字符串,全球唯一,由域所有者分配,其中可包含冒号为分割符的组织边界
LUN: 逻辑单元号,带有编号的块设备,连接到目标且通过目标来使用。可以有一个或多个LUN连接到单个目标,但通常一个目标提供一个LUN
portals入口: 目标或启动器上用于建立的IP地址和端口。 3260
ISCSI配置
准备
先准备一个分区
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (45467648-83886079, default 45467648):
Using default value 45467648
Last sector, +sectors or +size{
K,M,G} (45467648-83886079, default 83886079):
Using default value 83886079
Partition 4 of type Extended and of size 18.3 GiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (45469696-83886079, default 45469696):
Using default value 45469696
Last sector, +sectors or +size{
K,M,G} (45469696-83886079, default 83886079): +2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
再准备一个空磁盘
sdb为新添加的磁盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 19.5G 0 part /
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part
sdb 8:16 0 2G 0 disk
sr0 11:0 1 3.8G 0 rom /run/media/root/RHEL-7.2 Server.x86_64
安装服务端软件
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# yum install targetcli -y
创建
命令的使用
[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
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] 物理scsi
| o- ramdisk ................ [Storage Objects: 0] 闪存
o- iscsi ............................ [Targets: 0] 通过create创建,两个分别将sdb sda5 共享出去
o- loopback ......................... [Targets: 0]
/>
创建LUN
/> cd /backstores/block
/backstores/block> create name=LUN0 dev=/dev/sdb //创建磁盘/dev/sdb为LUN0
Created block storage object LUN0 using /dev/sdb.
/backstores/block> create name=LUN1 dev=/dev/sda5 //创建sda5分区为LUN1
Created block storage object LUN1 using /dev/sda5.
/backstores/block> ls //使用ls命令来查看创建的结果
o- block ............................................. [Storage Objects: 2]
o- LUN0 ...................... [/dev/sdb (2.0GiB) write-thru deactivated]
o- LUN1 ..................... [</