服务端server1
[root@server1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb:6 GiB,6442450944 字节,12582912 个扇区
磁盘型号:VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x81eb201b
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sdb1 2048 4196351 4194304 2G 83 Linux
[root@server1 ~]# yum install targetcli
[root@server1 ~]# systemctl start target
[root@server1 ~]# systemctl enable target
[root@server1 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.54
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create uos_disk /dev/sdb1
Created block storage object uos_disk using /dev/sdb1.
#####/> /iscsi create iqn.nananana.uosexam:server1
######WWN not valid as: iqn, naa, eui
/> /iscsi create iqn.2022-06.com.uosexam:server1
Created target iqn.2022-06.com.uosexam:server1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> /iscsi/iqn.2022-06.com.uosexam:server1/tpg1/acls create iqn.2022-06.com.uosexam:client2
Created Node ACL for iqn.2022-06.com.uosexam:client2
/> /iscsi/iqn.2022-06.com.uosexam:server1/tpg1/luns create /backstores/block/uos_disk
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2022-06.com.uosexam:client2
/> saveconfig
Configuration saved to /etc/target/saveconfig.json
/>exit
[root@server1 ~]# targetcli ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 1]
| | o- uos_disk ........................................................................ [/dev/sdb1 (2.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-06.com.uosexam:server1 ................................................................................... [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 1]
| | o- iqn.2022-06.com.uosexam:client2 ...................................................................... [Mapped LUNs: 1]
| | o- mapped_lun0 .............................................................................. [lun0 block/uos_disk (rw)]
| o- luns .......................................................................................................... [LUNs: 1]
| | o- lun0 .................................................................. [block/uos_disk (/dev/sdb1) (default_tg_pt_gp)]
| o- portals .................................................................................................... [Portals: 1]
| o- 0.0.0.0:3260 ..................................................................................................... [OK]
o- loopback ......................................................................................................... [Targets: 0]
o- vhost ............................................................................................................ [Targets: 0]
o- xen-pvscsi ....................................................................................................... [Targets: 0]
[root@server1
客户端server2
[root@server2 ~]# yum install open-iscsi -y
[root@server2 ~]# systemctl start iscsi
[root@server2 ~]# systemctl start iscsid
[root@server2 ~]# systemctl enable iscsid
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.
[root@server2 ~]# systemctl enable iscsi
[root@server2 ~]#
[root@server2 ~]# vi /etc/iscsi/initiatorname.iscsi
[root@server2 ~]#
[root@server2 ~]# more /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2022-06.com.uosexam:client2
[root@server2 ~]# systemctl restart iscsid
[root@server2 ~]#
发现共享磁盘
[root@server2 ~]# iscsiadm --mode discoverydb --type sendtargets --portal server1 --discover
192.168.122.1:3260,1 iqn.2022-06.com.uosexam:server1
[root@server2 ~]# iscsiadm -m node -T iqn.2022-06.com.uosexam:server1 server1:3260 -l
Logging in to [iface: default, target: iqn.2022-06.com.uosexam:server1, portal: 192.168.122.1,3260]
Login to [iface: default, target: iqn.2022-06.com.uosexam:server1, portal: 192.168.122.1,3260] successful.
[root@server2 ~]#
[root@server2 ~]# fdisk -l /dev/sda
Disk /dev/sda:2 GiB,2147483648 字节,4194304 个扇区
磁盘型号:uos_disk
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 4194304 字节
[root@server2 ~]#
[root@server2 ~]# fdisk -l /dev/sda
Disk /dev/sda:2 GiB,2147483648 字节,4194304 个扇区
磁盘型号:uos_disk
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 4194304 字节
磁盘标签类型:dos
磁盘标识符:0x64f14507
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sda1 8192 2105343 2097152 1G 83 Linux
[root@server2 ~]#
[root@server2 ~]# mkfs.ext4 /dev/sda1
mke2fs 1.45.6 (20-Mar-2020)
创建含有 262144 个块(每块 4k)和 65536 个inode的文件系统
文件系统UUID:ecb26796-3845-403f-84be-28103db471ce
超级块的备份存储于下列块:
32768, 98304, 163840, 229376
正在分配组表: 完成
正在写入inode表: 完成
创建日志(8192 个块)完成
写入超级块和文件系统账户统计信息: 已完成
[root@server2 ~]# blkid /dev/sda1
/dev/sda1: UUID="ecb26796-3845-403f-84be-28103db471ce" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="64f14507-01"
[root@server2 ~]#
[root@server2 ~]#
[root@server2 ~]# mkdir /mnt/bbb
[root@server2 ~]#
[root@server2 ~]# vi /etc/fstab
[root@server2 ~]# mount -a
[root@server2 ~]# more /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu May 11 08:43:58 2023
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/uos-root / xfs defaults 0 0
UUID=0f68e7ca-1bf9-4fac-96f0-94540dbc8d34 /boot xfs defaults 0 0
/dev/mapper/uos-home /home xfs defaults 0 0
/dev/mapper/uos-swap none swap defaults 0 0
UUID="ecb26796-3845-403f-84be-28103db471ce" /mnt/bbb ext4 defaults 0 0
[root@server2 ~]#
[root@server2 ~]# mount -a
服务端删除所有配置
/> clearconfig confirm=true
All configuration cleared
/> exit