题目要求:
• 添加 1 块大小为 10G 的硬盘;
• 安装 iSCSI 服务端 targetcli;
• 使用新增加的硬盘创建卷组,名称为 iscsivg,再创建 iSCSI 共享逻辑卷,逻辑卷名称为 iscsistore,大小为 5G;
• 使用上述逻辑卷创建后端存储,名称为 server02.iscsistore;
• 定义 iSCSI 的 IQN 为 iqn.2022-03.com.rj.iscsi:server02;
• IQN 下添加提供 iSCSI 服务的 IP 地址与端口,其中 IP 地址为服务器地址,端口为 3260;
• 使用后端存储创建 LUN0,并在属性设置中关闭认证;
• 仅允许 Client 进行连接访问。
题目实施:
server01服务器端:
添加一块10g的硬盘
创建逻辑卷:
[root@server02 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@server02 ~]# vgcreate iscsivg /dev/sdb
Volume group "iscsivg" successfully created
[root@server02 ~]# lvcreate -n iscsistorg -L 5G iscsivg
Logical volume "iscsistorg" created.
查看逻辑卷:
[root@server02 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/iscsivg/iscsistorg
LV Name iscsistorg
VG Name iscsivg
LV UUID AXJVx0-lKJA-A9KK-Rlgo-oGJU-ezV7-5b5IoG
LV Write Access read/write
LV Creation host, time server02, 2022-12-12 20:51:09 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID rqCGRJ-Ej2D-pdR0-km7h-g1MB-3tsW-0nI19H
LV Write Access read/write
LV Creation host, time localhost, 2022-06-07 03:04:09 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID WoQUmg-BuZp-dVJP-hpru-Lsu0-zPkG-Ughp6i
LV Write Access read/write
LV Creation host, time localhost, 2022-06-07 03:04:10 +0800
LV Status available
# open 1
LV Size 46.99 GiB
Current LE 12030
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
安装软件包:
[root@server02 ~]# yum install targetcli -y
进入iscsi配置:
[root@server02 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> ls #ls查看
建立后端存储:
#后端存储/块 backstores/block
#创建 create
#设备dev= dev=/dev/iscsivg/iscsistorg
#名称 name= name=server02.iscsistore
/> backstores/block create dev=/dev/iscsivg/iscsistorg name=server02.iscsistore
Created block storage object server02.iscsistore using /dev/iscsivg/iscsistorg.
/> ls #ls查看
定义iSCSI的IQN(target磁盘组):
/> iscsi/ create iqn.2022-03.com.rj.iscsi:server02
Created target iqn.2022-03.com.rj.iscsi:server02.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls #ls查看
添加ip地址与端口:
删除默认的端口和地址
/> iscsi/iqn.2022-03.com.rj.iscsi:server02/tpg1/portals/ delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
添加新的地址与端口
/> iscsi/iqn.2022-03.com.rj.iscsi:server02/tpg1/portals create 192.168.88.88 3260
Using default IP port 3260
Created network portal 192.168.88.88:3260.
/> ls #ls查看
后端存储关联LUN0:
#Iscisi/iqn/目标(tpg1)/关联 luns 创建 后端存储
iscsi/iqn.2021-03.com.rj.iscsi:server02/tpg1/luns create /backstores/block/server02.iscsistore
/> iscsi/iqn.2022-03.com.rj.iscsi:server02/tpg1/luns create /backstores/block/server02.iscsistore
Created LUN 0.
/> ls #ls查看
仅允许客户端访问:
#Iscisi/iqn/目标(tpg1)/访问控制 acls 创建 client 命名
/> iscsi/iqn.2022-03.com.rj.iscsi:server02/tpg1/acls create iqn.2022-03.com.rj.iscsi:client
Created Node ACL for iqn.2022-03.com.rj.iscsi:client
Created mapped LUN 0.
关闭防火墙:
[root@server02 ~]# systemctl stop firewalld
客户端配置
安装iscsi客户端软件包:
[root@cilent ~]# yum install iscsi-initiator-utils -y
修改客户端配置文件:
[root@cilent ~]# vim /etc/iscsi/initiatorname.iscsi
#添加
InitiatorName=iqn.2022-03.com.rj.iscsi:client
重启和自启服务:
[root@cilent ~]# systemctl restart iscsid
[root@cilent ~]# systemctl enable iscsid
发现服务端iSCSI:
-m discovery:扫描并发现可用的存储资源
-t st:执行扫描操作的类型
-p:iSCSI 服务端的 IP 地址
[root@client ~]# iscsiadm -m discovery -t st -p 192.168.88.88
192.168.88.88:3260,1 iqn.2022-03.com.rj.iscsi:server02
连接iSCSI:
[root@client ~]# iscsiadm -m node -T iqn.2022-03.com.rj.iscsi:server02 -l
Logging in to [iface: default, target: iqn.2022-03.com.rj.iscsi:server02, portal: 192.168.88.88,3260] (multiple)
Login to [iface: default, target: iqn.2022-03.com.rj.iscsi:server02, portal: 192.168.88.88,3260] successful.
#表示成功
[root@client ~]#
查看已连接的iscsi:
[root@client ~]# iscsiadm -m node
192.168.88.88:3260,1 iqn.2022-03.com.rj.iscsi:server02
设置开机自动连接:
[root@client ~]# iscsiadm -m node -T iqn.2022-03.com.rj.iscsi:server02 --op update -n node.startup -v automatic
断开连接iSCSI:
[root@client ~]# iscsiadm -m node -T iqn.2022-03.com.rj.iscsi:server02 -u
Logging out of session [sid: 1, target: iqn.2022-03.com.rj.iscsi:server02, portal: 192.168.88.88,3260]
Logout of [sid: 1, target: iqn.2022-03.com.rj.iscsi:server02, portal: 192.168.88.88,3260] successful.
[root@client ~]#