iSCSI简介:
iSCSI(Internet Small Computer System Interface,发音为/ˈаɪskʌzi/),Internet小型计算机系统接口,又称为IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术,由IETF提出,并于2003年2月11日成为正式的标准。基于C/S架构的虚拟磁盘技术服务器提供磁盘空间,客户机连接并当成本地磁盘使用。
iSCSI磁盘的构成
backstore,后端存储:
对应到服务端提供实际存储空间的设备,需要一个管理名称 target,磁盘组:
是客户端的访问目标,作为一个框架,由多个lun组成 lun,逻辑单元:
每一个lun需要关联到某一个后端存储设备,在客户端会视为一块虚拟磁盘。
发布iSCSI网络磁盘
1. 添加一块磁盘并分区:
[root@localhost ~
]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 1G 0 part
[SWAP
]
└─sda3 8:3 0 18.5G 0 part /
sdb 8:16 0 20G 0 disk --可以看的出来添加了一块新的磁盘20G
sr0 11:0 1 4.3G 0 rom /mnt
[root@localhost ~
]
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
(0 primary, 0 extended, 4 free
)
e extended
Select
(default p
): p
Partition number
(1-4, default 1
):
First sector
(2048-41943039, default 2048
):
Using default value 2048
Last sector, +sectors or +size
{K,M,G
} (2048-41943039, default 41943039
):
Using default value 41943039
Partition 1 of
type Linux and of size 20 GiB is
set
Command
(m
for help
): w
The partition table has been altered
!
Calling ioctl
() to re-read partition table.
Syncing disks.
----这里把所有磁盘分为一个分区为20G
[root@localhost ~
]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 1G 0 part
[SWAP
]
└─sda3 8:3 0 18.5G 0 part /
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 20G 0 part
sr0 11:0 1 4.3G 0 rom /mnt
2. 使用targetcli建立配置:
ISCSI Qualified Name 名称规范:iqn.yyyy-mm.倒序域名:自定义标识名称示例:iqn.2020-10.com.ys:server0 ; iqn.2020-10.com.ys:client0基本交互操作:
/backstore/block create 后端存储名 实际设备路径/iscsi create 磁盘组的IQN名称/iscsi/磁盘组名/tpg1/luns create 后端存储路径/iscsi/磁盘组名/tpg1/acls create 客户端IQN标识/iscsi/磁盘组名/tpg1/portals create IP地址 端口号
yum -y
install targetcli
systemctl start target.service
systemctl
enable target.service
[root@localhost ~
]
/
> backstores/block create iscsi_ys /dev/sdb1 ---创建后端存储
/
> iscsi/ create iqn.2020-10.com.ys:server0 ---创建iqn对象
/
> iscsi/iqn.2020-10.com.ys:server0/tpg1/luns create /backstores/block/iscsi_ys ---将iqn对象与后端存储绑定
/
> iscsi/iqn.2020-10.com.ys:server0/tpg1/acls create iqn.2020-10.com.ys:client0 ----设置客户端的iqn
/
> iscsi/iqn.2020-10.com.ys:server0/tpg1/portals/ create 0.0.0.0 3260 ----开启本地监听的IP地址与端口
/
> ls
o- /
.........................................................................................................................
[...
]
o- backstores
.............................................................................................................. [...
]
| o- block
.................................................................................................. [Storage Objects: 1
]
| | o- iscsi_ys
.......................................................................
[/dev/sdb1
(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.2020-10.com.ys:server0
........................................................................................ [TPGs: 1
]
| o- tpg1
...............................................................................................
[no-gen-acls, no-auth
]
| o- acls
.......................................................................................................... [ACLs: 1
]
| | o- iqn.2020-10.com.ys:client0
...........................................................................
[Mapped LUNs: 1
]
| | o- mapped_lun0
.............................................................................. [lun0 block/iscsi_ys
(rw
)]
| o- luns
.......................................................................................................... [LUNs: 1
]
| | o- lun0
.................................................................. [block/iscsi_ys
(/dev/sdb1
) (default_tg_pt_gp
)]
| o- portals
.................................................................................................... [Portals: 1
]
| o- 0.0.0.0:3260
.....................................................................................................
[OK
]
o- loopback
.........................................................................................................
[Targets: 0
]
3. 客户端配置:
在centos 7系统中,已经默认安装了iSCSI客户端服务程序initiator。如果您的系统没有安装的话,可以使用Yum软件仓库手动安装。
yum -y
install iscsi-initiator-utils
[root@localhost ~
]
InitiatorName
=iqn.2020-10.com.ys:client0
[root@localhost ~
]
1. iscsiadm是用于管理、查询、插入、更新或删除iSCSI数据库配置文件的命令行工具。
2. 用户需要先使用这个工具扫描发现远程iSCSI服务端,然后查看找到的服务端上有哪些可用的共享存储资源。
3. -m discovery参数的目的是扫描并发现可用的存储资源,
4. -t st参数为执行扫描操作的类型,
5. -p 192.168.245.128参数为iSCSI服务端的IP地址.
6. 可通过
man iscsiadm
| grep \\-mode 来查看帮助。
[root@localhost ~
]
192.168.2.10:3260,1 iqn.2020-10.com.ys:server0
[root@localhost ~
]
[root@localhost ~
]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 1G 0 part
[SWAP
]
└─sda3 8:3 0 18.5G 0 part /
sdb 8:16 0 20G 0 disk ---可以看的出来这里多了一个磁盘
sr0 11:0 1 4.3G 0 rom /mnt
以上配置可以发现客户端多了一个新的磁盘可以参考磁盘分区规划及使用、LVM逻辑卷进行使用