ipsan远程块存储
- iscsi介绍
- iscsi服务器共享设备
- iscsi客户端连接共享
一、iscsi介绍
1)数据存储技术
DSA (Direct Attacted Storage 直接附加存储)
本地磁盘接口:IDE SATA SAS SCSI
NAS (Network Attacted Storage 网络附加存储)
网络服务共享:共享的是文件夹。比如samba、NFS
SAN (Network Attacted Storage 网络附加存储)
网络服务共享:共享的是设备。比如iscsi
2)iscsi介绍
iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的、可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI是一种新储存技术,它是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
iscsi internet小型计算机系统接口是一个基于tcp/ip的协议,用于通过IP网络仿真scsi高性能本地存储总线,从而为远程块存储设备提供数据传输和管理。
scsi协议套件提供基于设备总线通信协议的命令描述器块(CBD)命令集,iscsi同样保留了CBD命令集,通过标准tcp/ip封装的iscsi系统之间执行总线通信。
将设备通过tcp/ip的方式共享到客户端,仿真为本地设备
ISCSI之间通信是一种C/S架构。
客户端:
叫做Initator(发起者 C)
服务端:
这里称之为Target:(目标 S),每个Target可包含多个LUN(Logical Unit Number 逻辑单元)。真正提供服务的是LUN。
二、iscsi服务器部署
image1)创建共享设备
我分两种方式给大家做了设备,第一种是设备磁盘分区,第二种是硬盘文件
[root@241 ~]# fdisk -l /dev/sdb
磁盘 /dev/sdb:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xa1f3452a
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
/dev/sdb2 20973568 41945087 10485760 83 Linux
制作设备文件,方便后续共享
[root@241 ~]# dd if=/dev/zero of=/opt/sdb3 bs=1M count=300
记录了300+0 的读入
记录了300+0 的写出
314572800字节(315 MB)已复制,0.244591 秒,1.3 GB/秒
2)安装iscsi服务
安装服务端
[root@241 ~]# yum -y install targetcli
target iscsi server
targetcli target命令行管理工具
启动服务并设置开机启动
[root@241 ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@241 ~]# systemctl start targe
3)通过targetcli命令设置设备共享
- 将设备加入到backstores存储库
- 设置设备全球唯一标识名称IQN
- 设置tpg组定义谁可以从哪个IP及端口访问IQN标识对应的哪些设备。
将设备加入到iscsi存储的backstores存储库中
[root@241 ~]# 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]
备注
/代表存储的根目录
/backstores 代表后端存储,iscsi通过使用文件、逻辑卷或任何类型的磁盘作为底层存储来仿真呈现为目标的scsi设备
block 后端存储是个块设备
fileio 后端存储是一个文件
pscsi 物理scsi设备
ramdisk 后端存储是内存上的空间,在内存上创建一个指定大小的ramdisk设备
可以通过help命令来打印可用命令
添加设备到/backstores
/> cd backstores/
/backstores> block/ create block1 /dev/sdb1
Created block storage object block1 using /dev/sdb1.
/backstores> block/ create block2 /dev/sdb2
Created block storage object block2 using /dev/sdb2.
/backstores> fileio/ create block3 /opt/sdb3
Created fileio block3 with size 314572800
/backstores> ls
o- backstores ................................................................................................................ [...]
o- block .................................................................................................... [Storage Objects: 2]
| o- block1 ........................................................................... [/dev/sdb1 (0 bytes) write-thru activated]
| | o- alua ..................................................................................................... [ALUA Groups: 1]
| | o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
| o- block2 ........................................................................... [/dev/sdb2 (0 bytes) write-thru activated]
| o- alua ..................................................................................................... [ALUA Groups: 1]
| o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
o- fileio ................................................................................................... [Storage Objects: 1]
| o- file1 ........................................................................... [/opt/sdb3 (300.0MiB) write-back activated]
| o- alua ..................................................................................................... [ALUA Groups: 1]
| o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
o- pscsi .................................................................................................... [Storage Objects: 0]
o- ramdisk .................................................................................................. [Storage Objects: 0]
/backstores>
设置IQN标识
创建全球唯一标识设备名
/iscsi> create iqn.2019-04.com.ayitula:block1
Created target iqn.2019-04.com.ayitula:block1.
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-04.com.ayitula:block1 ...................................................................................... [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]
TPG:目标门户组,某个特定iscsi目标将要监听的IP地址和tcp端口的集合。
设置tgp1选项中的访问控制 lun设备 访问地址及端口
备注:设备标示符必须按照统一格式
iqn.年-月.二级域名倒写:共享名
设置TPG组中对应的三个问题 谁 从哪里 访问什么设备
设置谁可以访问共享IQN对应的设备共享
/iscsi> cd iqn.2019-04.com.ayitula:block1/tpg1/
/iscsi/iqn.20...a:block1/tpg1> acls/ create iqn.2019-04.com.ayitula:client1
Created Node ACL for iqn.2019-04.com.ayitula:client1
/iscsi/iqn.20...a:block1/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
o- acls ................................................................................................................ [ACLs: 1]
| o- iqn.2019-04.com.ayitula:client1 ............................................................................ [Mapped LUNs: 0]
o- luns ................................................................................................................ [LUNs: 0]
o- portals .......................................................................................................... [Portals: 1]
o- 0.0.0.0:3260 ........................................................................................................... [OK]
指定tpg组中的Lun设备,可以添加多个设备
/iscsi/iqn.20...a:block1/tpg1> luns/ create /backstores/block/block1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-04.com.ayitula:client1
/iscsi/iqn.20...a:block1/tpg1> luns/ create /backstores/block/block2
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2019-04.com.ayitula:client1
/iscsi/iqn.20...a:block1/tpg1> luns/ create /backstores/fileio/file1
Created LUN 2.
Created LUN 2->2 mapping in node ACL iqn.2019-04.com.ayitula:client1
/iscsi/iqn.20...a:block1/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
o- acls ................................................................................................................ [ACLs: 1]
| o- iqn.2019-04.com.ayitula:client1 ............................................................................ [Mapped LUNs: 3]
| o- mapped_lun0 ...................................................................................... [lun0 block/block1 (rw)]
| o- mapped_lun1 ...................................................................................... [lun1 block/block2 (rw)]
| o- mapped_lun2 ...................................................................................... [lun2 fileio/file1 (rw)]
o- luns ................................................................................................................ [LUNs: 3]
| o- lun0 .......................................................................... [block/block1 (/dev/sdb1) (default_tg_pt_gp)]
| o- lun1 .......................................................................... [block/block2 (/dev/sdb2) (default_tg_pt_gp)]
| o- lun2 .......................................................................... [fileio/file1 (/opt/sdb3) (default_tg_pt_gp)]
o- portals .......................................................................................................... [Portals: 1]
o- 0.0.0.0:3260 ........................................................................................................... [OK]
/iscsi/iqn.20...a:block1/tpg1>
三、iscsi客户端连接共享
1)安装客户端包
[root@251 ~]# yum -y install iscsi-initiator-utils
2)设置客户端iscsi名称
[root@251 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2019-04.com.ayitula:client1
3)启动iscsi客户端服务
[root@251 ~]# systemctl enable iscsi;systemctl start iscsi
在客户端有两个服务iscsi iscsid
这两个的区别是什么呢? iscsi VS iscsid
iscsid是在后台运行的守护进程,同时处理iscsi配置和管理连接。ISCSID实现了ISCSI协议的控制路径和一些管理工具。
例如,可以根据持久性iSCSI数据库的内容,将守护进程配置为在启动时自动重新启动发现。
iscsi作业是执行其主配置文件locate@/etc/iscsi/iscsid.conf,这当然有助于带来与iscsi相关的套接字。作为其中的一部分,
它还带来了在/etc/iscsi/initiatorname.iscsi中设置的iscsi目标。但是,只有在主配置文件中设置了“node.startup=automatic”
时才会发生这种情况。
4) 发现远程服务器的共享
[root@251 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.11.241 --discover
192.168.11.241:3260,1 iqn.2019-04.com.ayitula:block1
5) 连接共享
发现远程共享
[root@251 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.11.241 --discover
192.168.11.241:3260,1 iqn.2019-04.com.ayitula:block1
连接远程共享
[root@251 ~]# iscsiadm --mode node --targetname iqn.2019-04.com.ayitula:block1 --portal 192.168.11.241:3260 --login
Logging in to [iface: default, target: iqn.2019-04.com.ayitula:block1, portal: 192.168.11.241,3260] (multiple)
Login to [iface: default, target: iqn.2019-04.com.ayitula:block1, portal: 192.168.11.241,3260] successful.
查看连接过来的设备
[root@251 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 79G 0 part
├─centos-root 253:0 0 47.8G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 23.3G 0 lvm /home
sdb 8:16 0 10G 0 disk
sdc 8:32 0 10G 0 disk
sdd 8:48 0 300M 0 disk
sr0 11:0 1 4.2G 0 rom
6)分区格式化
参考linux从入门到精通中的磁盘管理一章:[http://book.ayitula.com/linux-cong-ru-men-dao-jing-tong/ci-pan-guan-li.html](http://book.ayitula.com/linux-cong-ru-men-dao-jing-tong/ci-pan-guan-li.html)
7)自动挂载
[root@251 ~]# cat /etc/fstab
[root@251 ~]# mkdir /opt/block{1..2}
[root@251 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar 15 05:39:44 2019
#
# 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/centos-root / xfs defaults 0 0
UUID=16073bb5-ac9e-496e-ae00-8585bbf37e48 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /opt/block1 ext4 _netdev 0 0
/dev/sdd1 /opt/block2 xfs _netdev 0 0
备注:权限 一定要写_netdev 代表其实从远端挂载,否则机器无法启动
8)重启验证
[root@251 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 48G 1.9G 46G 4% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 12M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 130M 885M 13% /boot
/dev/mapper/centos-home xfs 24G 33M 24G 1% /home
/dev/sdb1 ext4 9.8G 37M 9.2G 1% /opt/block1
/dev/sdd1 xfs 293M 15M 278M 6% /opt/block2
tmpfs tmpfs 797M 0 797M 0% /run/user/0
9)关于iscsiadm命令
Discover targets at a given IP address:
iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover
Login, must use a node record id found by the discovery:
iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --login
Logout:
iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --logout
List node records:
iscsiadm --mode node
Display all data for a given node record:
iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260
网友评论