iSCSI 互联网小型计算机系统接口是由IBM下属的两大研发机构AImaden和Haifa研究中心共同开发的,是一个供硬件设备使用的、可在IP协议上层运行的SCSI指令集,是一种开放的基于IP协议的工业技术标准.该协议可以用TCP/IP对SCSI指令进行封装,使得这些指令能够通过基于IP网络进行传输,从而实现SCSI和TCP/IP协议的连接.对于局域网环境中的用户来说,采用该标准只需要不多的投资就可以方便、快捷地对信息和数据进行交互式传输及管理.
iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料.
设备由 SCSI 总线连接,iSCSI的主要功能是在 TCP/IP 网络上的主机系统 (启动器 initiator) 和存储设备 (目标器 target) 之间进行大量数据的封装和可靠传输过程.此外 iSCSI 提供了在 IP 网络封装 SCSI 命令,且以TCP/IP协议传输.
ISCSI/SAN/NAS常用名词解释
iSCSI:Internet 小型计算机系统接口 (iSCSI:Internet Small Computer System Interface) Internet 小型计算机系统接口(iSCSI)是一种基于 TCP/IP 的协议,用来建立和管理 IP 存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN).
SAN网络:Storage Area Network 存储区域网络,多采用高速光纤通道,对速率、冗余性要求高.使用iscsi存储协议块级传输.
NAS网络:Network Attachment Storage 网络附件存储,采用普通以太网,对速率、冗余无特别要求,使用NFS、CIFS共享协议文件级传输.
SAN和NAS的区别:SAN一般特指存储网络的构建方式,NAS一般特指产品.SAN有单独的存储网络,NAS使用现有网络,家庭网络存储设备:FREENAS,用的是FREEBSD系统.
NFS 与 ISCSI 的区别
NFS 是以文件为单位的,共享出去的是文件.而ISCSI是以block为单位,共享出去的是设备,端口:3260/tcp.
iSCSI 网络存储,在工作上分为服务端(target)和客户端(initiator).iSCSI服务端用于存放硬盘存储资源的服务器,能够为用户提供可用的存储资源,iSCSI客户端则是用户使用的软件,用于访问远程服务端的存储资源.
1.通过yum安装iSCSI服务端,此处已安装成功,略过本步骤
[root@localhost ~]# yum install -y targetd targetcli
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager.
Package targetd-0.8.6-1.el7.noarch already installed and latest version
Package targetcli-2.1.fb46-1.el7.noarch already installed and latest version
Nothing to do
2.安装成功后,手动启动iSCSI服务,并设置开机自启动 (注意:iSCSI服务程序为targetd)
[root@localhost ~]# systemctl restart targetd
[root@localhost ~]# systemctl enable targetd
3.查看iSCSI服务端共享资源,targetcli是用于管理iSCSI服务的专用命令,在执行命令是可看到交互界面.
[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]
/>
4.进入/backstores/block共享设备位置,并创建共享设备名称 (注意:/backstores/block是iSCSI服务端配置共享设备的位置)
/> cd backstores/block #进入共享设备位置
/backstores/block> create disk0 /dev/sdb #创建共享设备名称 此处将 /dev/sdb 加入到设备中命名为disk0
Created block storage object disk0 using /dev/sdb.
/backstores/block> cd / #返回根
/> ls
o- / ............................................................. [...]
o- backstores .................................................. [...]
| o- block ..................................................... [Storage Objects: 1]
| | o- disk0 ................................................... [/dev/sdb (20.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]
/>
5.创建iSCSI target名称及配置共享资源,iSCSI target 名称是由系统自动生成的,这是一串用于描述共享资源的唯一字符串
/> cd iscsi #进入iSCSI目录
/iscsi> create #创建target标签
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>
/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8/ #进入上面的标签中
/iscsi/iqn.20....8c7dcc63aea8> ls #查看标签内容
o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8 ........ [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/iqn.20....8c7dcc63aea8> cd tpg1/luns #进入tpg目录
/iscsi/iqn.20...ea8/tpg1/luns> create /backstores/block/disk0 #标签与设备绑定
Created LUN 0.
/iscsi/iqn.20...ea8/tpg1/luns>
6.配置访问控制列表(ACL),iSCSI设备无需密码进行验证,只需知道标签名称即可通过,因此需要在iSCSI服务端的配置文件中写入一串能够验证信息的名称,这里推荐在系统生成的标签后面加上标识符,:client参数,保证标签唯一性,同时方便区别和管理
/> cd iscsi/iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8 #进入指定标签
/iscsi/iqn.20....8c7dcc63aea8> cd tpg1/acls #进入ACL配置列表
/iscsi/iqn.20...ea8/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8:client #创建用于挂载的标签
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8:client
Created mapped LUN 0.
/iscsi/iqn.20...ea8/tpg1/acls>
7.设置iSCSI服务器的监听IP地址和端口号,即在portals参数目录中写上服务器的IP地址,接下来系统会自动开启服务器192.168.1.20的3260号端口,为外部提供共享存储服务
/> cd /iscsi/iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8/ #进入操作的标签
/iscsi/iqn.20....8c7dcc63aea8> cd tpg1/portals/ #进入端口配置
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ...................................................................... [Portals: 1]
o- 0.0.0.0:3260 ............................................................... [OK]
/iscsi/iqn.20.../tpg1/portals>
/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 192.168.1.20 #创建侦听本机
Using default IP port 3260
Created network portal 192.168.1.20:3260.
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ...................................................................... [Portals: 1]
o- 192.168.1.20:3260 .......................................................... [OK]
/iscsi/iqn.20.../tpg1/portals>
8.配置全部妥当后检查一下,没问题的话保存.
/iscsi/iqn.20.../tpg1/portals> cd /
/>
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ........................................................... [Storage Objects: 1]
| | o- disk0 ......................................................... [/dev/sdb (20.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.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8 ..... [TPGs: 1] #标签名称
| o- tpg1 .......................................................... [no-gen-acls, no-auth]
| o- acls ......................................................................... [ACLs: 1]
| | o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8:client ......... [Mapped LUNs: 1] #自定义标签
| | o- mapped_lun0 .............................................................. [lun0 block/disk0 (rw)]
| o- luns ......................................................................... [LUNs: 1]
| | o- lun0 ..................................................... [block/disk0 (/dev/sdb) (default_tg_pt_gp)]
| o- portals ...................................................................... [Portals: 1]
| o- 192.168.1.20:3260 .......................................................... [OK] #开启端口
o- loopback ........................................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@localhost ~]#
9.重启SCSI服务,到此服务器已经配置完毕
[root@localhost ~]# systemctl restart targetd
[root@localhost ~]# systemctl enable targetd
1.安装iSCSI客户端组件,在RHEL7系统中已经默认集成,如果没有请执行以下步骤,此处就略过
[root@localhost ~]# yum install -y iscsi-initiator-utils iscsi-initiator-utils-iscsiuio
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager .
Package iscsi-initiator-utils-6.2.0.874-7.el7.x86_64 already installed and latest version
Package iscsi-initiator-utils-iscsiuio-6.2.0.874-7.el7.x86_64 already installed and latest version
Nothing to do
2.编辑iSCSI客户端中的initiator名称文件,把服务端的访问控制列表名称填写进来,然后重启iscsid服务程序,并将其加入到开机自启动列表
[root@localhost ~]# vim /etc/iscsi/initiatorname.iscsi
[root@localhost ~]#
[root@localhost ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8:client
[root@localhost ~]# systemctl restart iscsid
[root@localhost ~]# systemctl enable iscsid
3.发现iSCSI服务端存储资源,其中:-m discovery 参数的目的是扫描并发现存储资源,-t st 参数为执行扫描操作的类型,-p 参数后为iSCSI服务端的IP地址
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.1.20 #下图显示,找到一个标签地址
192.168.1.20:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8
[root@localhost ~]#
4.接下来准备登陆iSCSI服务器,其中:-m node 参数为将客户端主机作为一台节点服务器,-T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8 参数为要使用的存储标签,-p 后面为iSCSI服务器的IP地址, --login 参数为登陆服务器,如果加 -u参数为卸载挂载资源
[root@localhost ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8 -p 192.168.1.20 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8, portal: 192.168.1.20,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.8c7dcc63aea8, portal: 192.168.1.20,3260] successful.
5.此时在iSCSI客户端上会多出一个/dev/sdb磁盘设备文件,接下来我们直接格式化挂在到/network-disk目录下
root@localhost ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Nov 4 11:45 /dev/sda
brw-rw----. 1 root disk 8, 1 Nov 4 11:45 /dev/sda1
brw-rw----. 1 root disk 8, 2 Nov 4 11:45 /dev/sda2
brw-rw----. 1 root disk 8, 16 Nov 4 12:06 /dev/sdb #此处就是远程的磁盘
[root@localhost ~]# mkfs.xfs /dev/sdb #格式化这个设备
meta-data=/dev/sdb isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /network-disk #创建挂载目录
[root@localhost ~]# mount /dev/sdb /network-disk/ #挂载设备
[root@localhost ~]#
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 1.2G 16G 7% /
devtmpfs 98M 0 98M 0% /dev
tmpfs 110M 0 110M 0% /dev/shm
/dev/sda1 1014M 130M 885M 13% /boot
/dev/sr0 4.4G 4.4G 0 100% /mnt
/dev/sdb 20G 33M 20G 1% /network-disk
iSCSI客户端经过以上步骤之后,这个设备文件就可以像使用本地磁盘文件一样的操作啦
6.接下来配置一下自动挂载功能,需要注意的是,挂载选项必须为_netdev,写错的话系统无法开机.
由于/dev/sdb/是一个网络设备,而iSCSI是基于TCP/IP网络传输数据的,因此在配置自动挂载是应该加入_netdev参数,说明其是一个网络设备
[root@localhost /]# ll /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root 10 Nov 4 11:45 12b3708e-7ca4-4911-bfa2-57b85960e8e5 -> ../../dm-0
lrwxrwxrwx. 1 root root 9 Nov 4 11:45 2018-03-22-19-04-59-00 -> ../../sr0
lrwxrwxrwx. 1 root root 10 Nov 4 11:45 3d4eea6b-1db9-4d30-9174-bfac6faa4cab -> ../../sda1
lrwxrwxrwx. 1 root root 10 Nov 4 11:45 e791c0bf-f6e9-4843-b18d-be40cf3964c2 -> ../../dm-1
lrwxrwxrwx. 1 root root 9 Nov 4 12:08 ff233cc4-2255-4973-a686-9d394384faf6 -> ../../sdb
[root@localhost /]# vim /etc/fstab
[root@localhost /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Oct 13 12:32:13 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=3d4eea6b-1db9-4d30-9174-bfac6faa4cab /boot xfs defaults 0 0
UUID=ff233cc4-2255-4973-a686-9d394384faf6 /network-disk xfs defaults,_netdev 0 0
[root@localhost /]# mount -a
1.单击控制面板 --> 管理工具 --> iSCSI发起程序 2.在目标选项卡 --> 输入服务器IP地址 --> 单击快速连接 3.选择配置选项卡 --> 单击更改 --> 在标签末尾加上自定义的字符,此处为:client --> 单击确定 4.单击目标选项卡 --> 单击下方的连接按钮 5.单击此电脑 --> 右键选择管理 --> 选择磁盘管理 --> 即可看到磁盘信息