利用iSCSI服务部署IP SAN网络存储服务

一、配置环境(Vmware WorkStation虚拟环境)

服务端与客户端OS:openEuler 22.03-LTS

CPU:1U1C

内存:2G

硬盘:5个SCSI磁盘,其中一个作为系统盘,另外四个配置为RAID5阵列

服务器IP:192.168.17.200

二、详细配置过程

1、配置RAID5

bash 复制代码
mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde

其中,-Cv参数为创建阵列并显示过程,/dev/md0为生成的阵列组名称,-n 3参数为创建RAID 5磁盘阵列所需的硬盘个数,-l 5参数为RAID磁盘阵列的级别,-x 1参数为磁盘阵列的备份盘个数。

执行以下命令查看RAID5阵列详情

bash 复制代码
mdadm -D /dev/md0

2、配置iSCSI服务端

(1)在服务器上安装iSCSI服务软件包

bash 复制代码
dnf install -y targetcli

(2)配置iSCSI服务端共享资源

  • 查看iSCSI服务端共享资源
bash 复制代码
[root@ipsan ~]# targetcli
targetcli shell version 2.1.54
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]
  o- vhost ................................................................................................ [Targets: 0]
  o- xen-pvscsi ........................................................................................... [Targets: 0]
  • 将前面创建的RAID 5磁盘阵列md0作为iSCSI共享设备
bash 复制代码
/> cd /backstores/block
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
/backstores/block> cd /
/> ls
o- / ............................................................................................................. [...]
  o- backstores .................................................................................................. [...]
  | o- block ...................................................................................... [Storage Objects: 1]
  | | o- disk0 ............................................................. [/dev/md0 (40.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]
  o- vhost ................................................................................................ [Targets: 0]
  o- xen-pvscsi ........................................................................................... [Targets: 0]
  • 创建iSCSI target名称及配置共享资源
bash 复制代码
/> cd iscsi 
/iscsi> create 
Created target iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195.
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.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195 ................................................. [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> cd iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195/
/iscsi/iqn.20....a54ce739d195> cd tpg1/luns
/iscsi/iqn.20...195/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
  • 设置访问控制列表(ACL)

iSCSI协议通过客户端名称进行验证的。即iSCSI客户端的名称与服务端中设置的访问控制列表中某一名称条目一致即可。acls参数目录用于存放能够访问iSCSI服务端共享存储资源的客户端名称,推荐在前面系统生成的iSCSI target后面追加上类似于:client的参数,这样既能保证客户端的名称具有唯一性,又非常便于管理和阅读。

bash 复制代码
/iscsi/iqn.20...195/tpg1/luns> cd ../acls 
/iscsi/iqn.20...195/tpg1/acls> create iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195:client
Created mapped LUN 0.
  • 设置iSCSI服务端的监听IP地址和端口号

默认情况下,iSCSI允许所有网卡提供iSCSI服务,但这种配置存在安全隐患,可以删除默认配置,然后指定服务接口IP地址。

bash 复制代码
/iscsi/iqn.20...195/tpg1/acls> cd ../portals/
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ................................................................................................ [Portals: 1]
  o- 0.0.0.0:3260 ................................................................................................. [OK]
/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.17.200
Using default IP port 3260
Created network portal 192.168.17.200:3260.
  • 查看并确认配置
bash 复制代码
/iscsi/iqn.20.../tpg1/portals> cd /
/> ls
o- / ............................................................................................................. [...]
  o- backstores .................................................................................................. [...]
  | o- block ...................................................................................... [Storage Objects: 1]
  | | o- disk0 ............................................................... [/dev/md0 (40.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.ipsan.x8664:sn.a54ce739d195 ............................................... [TPGs: 1]
  |   o- tpg1 ................................................................................... [no-gen-acls, no-auth]
  |     o- acls .............................................................................................. [ACLs: 1]
  |     | o- iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195:client ........................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ..................................................................... [lun0 block/disk0 (rw)]
  |     o- luns .............................................................................................. [LUNs: 1]
  |     | o- lun0 .......................................................... [block/disk0 (/dev/md0) (default_tg_pt_gp)]
  |     o- portals ........................................................................................ [Portals: 1]
  |       o- 192.168.17.200:3260 .................................................................................. [OK]
  o- loopback ............................................................................................. [Targets: 0]
  o- vhost ................................................................................................ [Targets: 0]
  o- xen-pvscsi ........................................................................................... [Targets: 0]
  • 保存配置
bash 复制代码
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json

3、配置防火墙,放行iSCSI服务

bash 复制代码
[root@ipsan ~]# firewall-cmd --permanent --zone=public --add-port=3260/tcp
[root@ipsan ~]# firewall-cmd --reload

4、配置iSCSI客户端

以下操作在iSCSI客户端完成

(1)安装iSCSI客户端服务程序initiator

bash 复制代码
dnf install iscsi-initiator-utils

(2)编辑iSCSI客户端配置文件

bash 复制代码
CNA01:~ # vi /etc/iscsi/initiatorname.iscsi 

InitiatorName=iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195:client

(3)重启iSCSI服务

bash 复制代码
systemctl restart iscsid
systemctl enable  iscsid

(3)扫描发现远程iSCSI服务端

bash 复制代码
iscsiadm -m discovery -t st -p 192.168.17.200

其中,-m discovery参数的目的是扫描并发现可用的存储资源,-t st参数为执行扫描操作的类型,-p 192.168.17.200参数为iSCSI服务端的IP地址

(4)登录iSCSI服务端

bash 复制代码
CNA01:~ # iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195 -p 192.168.17.200 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195, portal: 192.168.17.200,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195, portal: 192.168.17.200,3260] successful.

其中,-m node参数为将客户端所在主机作为一台节点服务器,-T参数为要使用的存储资源,-p 192.168.17.200参数为iSCSI服务端的IP地址,--login或-l参数表示登录。

(4)查看共享设备

在iSCSI客户端成功登录之后,会在客户端主机上多出一块名为/dev/sdb的设备文件。

bash 复制代码
CNA01:~ #  ls -l /dev/sdb
brw-rw---- 1 root disk 8, 16 Feb 21 05:19 /dev/sdb
CNA01:~ # file /dev/sdb 
/dev/sdb: block special (8/16)

(5)格式化共享设备

bash 复制代码
CNA01:~ # mkfs.ext4 /dev/sdb
mke2fs 1.45.0 (6-Mar-2019)
/dev/sdb is apparently in use by the system; will not make a filesystem here!

若出现上述错误,则执行以下命令解决问题

bash 复制代码
CNA01:~ # dmsetup remove_all
CNA01:~ # dmsetup status

正常格式化共享设备的输出信息如下

bash 复制代码
CNA01:~ # mkfs.ext4 /dev/sdb
mke2fs 1.45.0 (6-Mar-2019)
Creating filesystem with 10477056 4k blocks and 2621440 inodes
Filesystem UUID: f012928f-9e69-4631-b0bc-1d97e75a305b
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done

(6)编辑/etc/fstab配置文件

因是网络共享设备,通常采用UUID进行挂载,且挂载选项中选用_netdev参数。

bash 复制代码
CNA01:~ # blkid | grep /dev/sdb
/dev/sdb: UUID="f012928f-9e69-4631-b0bc-1d97e75a305b" TYPE="ext4" 

CNA01:~ # vi /etc/fstab
......在文件末尾添加以下挂载信息......
UUID="f012928f-9e69-4631-b0bc-1d97e75a305b" /iscsi      ext4    defaults,_netdev 0 0 

(7)挂载共享设备

bash 复制代码
CNA01:~ # mkdir /iscsi
CNA01:~ # mount -a

注:如果不再需要使用iSCSI共享设备资源了,可以用iscsiadm命令的-u参数将其设备卸载,命令如下:

bash 复制代码
iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.ipsan.x8664:sn.a54ce739d195 -u
相关推荐
Jason-河山26 分钟前
【自动化更新,让商品信息跳舞】——利用API返回值的幽默编程之旅
运维·自动化
饮浊酒30 分钟前
Linux操作系统 ------(3.文本编译器Vim)
linux·vim
lihuhelihu38 分钟前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算
哲讯智能科技40 分钟前
SAP Business One市场价格解析
运维·sap·erp
矛取矛求1 小时前
Linux系统性能调优技巧
linux
山东布谷科技官方1 小时前
布谷直播源码部署服务器关于数据库配置的详细说明
运维·服务器·数据库·直播系统源码·直播源码·直播系统搭建·直播软件开发
One_Blanks1 小时前
渗透测试-Linux基础(1)
linux·运维·安全
Perishell1 小时前
无人机避障——大疆与Airsim中的角速度信息订阅获取
linux·动态规划·无人机
爱吃喵的鲤鱼1 小时前
linux进程的状态之环境变量
linux·运维·服务器·开发语言·c++
dessler1 小时前
Linux系统-ubuntu系统安装
linux·运维·云计算