使用iSCSI共享存储服务
一:简介
iSCSI(Internet Small Computer System Interface),Internet小型计算机系统接口,又称为IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术,由IETF提出,并于2003年2月11日成为正式的标准。与传统的SCSI技术比较起来,iSCSI技术有以下三个革命性的变化:
- 把原来只用于本机的SCSI协议透过TCP/IP网络发送,使连接距离可作无限的地域延伸;
- 连接的服务器数量无限(原来的SCSI-3的上限是15);
- 由于是服务器架构,因此也可以实现在线扩容以至动态部署。
二:iSCSI磁盘的构成
backstore 后端存储
对应到服务端提供实际存储空间的设备,需要起一个管理名称
target 磁盘组
是客户端的访问目标,作为一个框架,由多个lun组成
lun 逻辑单元
每一个lun需要关联到某一个后端存储设备,在客户端会视为一块虚拟硬盘
三:服务端部署
Ⅰ 准备工作:
1.准备一台服务器设置ip
[root@localhost ~]# ifconfig ens33 | grep inet
inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255
2.准备一个空闲的未分区的磁盘
[root@localhost ~]# ls /dev/sdb
/dev/sdb
3.使用fdisk对此磁盘进行分区
[root@localhost ~]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 20G 0 part
Ⅱ 安装配置iSCSI服务端
1.安装targetcli软件包
[root@localhost ~]# yum -y install targetcli
2.使用targetcli命令进行配置,此命令是交互式的
[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.51
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
#1.创建后端存储
/> backstores/block create dev=/dev/sdb1 name=test
Created block storage object test using /dev/sdb1.
#2.创建磁盘组
/> iscsi/ create wwn=iqn.2022-08.com.test:server
Created target iqn.2022-08.com.test:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
#3.进行lun关联
/> iscsi/iqn.2022-08.com.test:server/tpg1/luns create /backstores/block/test
Created LUN 0.
#4.设置访问控制,设置客户端声称的名字
/> iscsi/iqn.2022-08.com.test:server/tpg1/acls create iqn.2022-08.com.test:client
Created Node ACL for iqn.2022-08.com.test:client
Created mapped LUN 0.
#5.查看配置信息
/> ls
o- / ............................................................................................................ [...]
o- backstores ................................................................................................. [...]
| o- block ..................................................................................... [Storage Objects: 1]
| | o- test .............................................................. [/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.2022-08.com.test:server .......................................................................... [TPGs: 1]
| o- tpg1 .................................................................................. [no-gen-acls, no-auth]
| o- acls ............................................................................................. [ACLs: 1]
| | o- iqn.2022-08.com.test:client ............................................................. [Mapped LUNs: 1]
| | o- mapped_lun0 ..................................................................... [lun0 block/test (rw)]
| o- luns ............................................................................................. [LUNs: 1]
| | o- lun0 ......................................................... [block/test (/dev/sdb1) (default_tg_pt_gp)]
| o- portals ....................................................................................... [Portals: 1]
| o- 0.0.0.0:3260 ........................................................................................ [OK]
o- loopback ............................................................................................ [Targets: 0]
#6.退出
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
3.重启target服务
[root@localhost ~]# systemctl restart target
4.关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
四:客户端配置
1.安装iscsi-initiator-utils
[root@localhost ~]# yum -y install iscsi-initiator-utils
2.修改配置文件/etc/iscsi/initiatorname.iscsi
修改名称为服务端中客户端声称的名字
[root@localhost ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2022-08.com.test:client
3.重启iscsid服务
[root@localhost ~]# systemctl restart iscsid
4.发现服务端共享存储
[root@localhost ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.100.10 --discover
192.168.100.10:3260,1 iqn.2022-08.com.test:server
5.重启iscsi服务,使用共享存储
[root@localhost ~]# systemctl restart iscsi
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
五:注意点
使用targetcli建立配置
ISCSI Qualified Name名称规范
iqn.yyyy-mm.倒序域名:自定义标识
用来识别target磁盘组,也用来识别客户机身份
名称示范
iqn.2022-08.com.test:server
iqn.2022-08.com.test:client
六:总结
1.服务端配置思路(默认端口号3260)
①关闭防火墙
②安装target软件包
③使用targetcli命令进行配置(可以使用tab键补齐命令)
a.建立后端存储
b.建立target磁盘组
c.关联lun
d.设置acl访问控制,客户端生成的名字
2.客户端配置思路
①安装iscsi-initiator-utils软件包
②修改/etc/iscsi/initiatorname.iscsi文件中客户端声称的名字
③重启iscsid服务,刷新客户端标识
④使用客户端发现命令,可参照man iscsiadm中的示例
⑤重启iscsi服务,加载共享存储