栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

网络文件系统——下(iscsi对磁盘设备进行共享)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

网络文件系统——下(iscsi对磁盘设备进行共享)

目录

一、添加设备

二、安装共享策略管理软件

三、使用共享策略管理软件共享设备

四、在客户端的操作

五、删除共享设备

1、删除客户端的共享设备

 2、清空服务器中iscsi共享设备


一、添加设备

  • 列出设备,可以看到现在有两块硬盘 

  •  分区

二、安装共享策略管理软件
[root@westosa100 ~]# dnf install targetcli -y
[root@westosa100 ~]# systemctl enable --now target
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.

三、使用共享策略管理软件共享设备
[root@westosa100 ~]# 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'.

/> /backstores/block create westos_storagel1 /dev/vdb1
Created block storage object westos_storagel1 using /dev/vdb1.
/> /iscsi create iqn.2021-08.org.westos:stragel
Created target iqn.2021-08.org.westos:stragel.
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.2021-08.org.westos:stragel/tpg1/luns create /backstores/block/westos_storagel1 
Created LUN 0.
/> /iscsi/iqn.2021-08.org.westos:stragel/tpg1/acls create iqn.2021-08.org.westos:westoskey
Created Node ACL for iqn.2021-08.org.westos:westoskey
Created mapped LUN 0.
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json

四、在客户端的操作
[root@westos_student50 Desktop]# dnf install iscsi-initiator-utils.x86_64 -y
[root@westos_student50 Desktop]# iscsiadm  -m discovery -t st -p 172.25.254.100
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
iscsiadm: cannot make connection to 172.25.254.100: No route to host
^Ciscsiadm: caught SIGINT, exiting...
[root@westosa100 ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@westosa100 ~]# firewall-cmd --reload 
success
[root@westos_student50 Desktop]# iscsiadm  -m discovery -t st -p 172.25.254.100
172.25.254.100:3260,1 iqn.2021-08.org.westos:stragel
[root@westos_student50 Desktop]# iscsiadm -m node -T iqn.2021-08.org.westos:stragel -p 172.25.254.100 -l
Logging in to [iface: default, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260]
iscsiadm: Could not login to [iface: default, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
[root@westos_student50 Desktop]# vim /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.2021-08.org.westos:westoskey
[root@westos_student50 Desktop]# systemctl restart iscsid.service 
[root@westos_student50 Desktop]# iscsiadm -m node -T iqn.2021-08.org.westos:stragel -p 172.25.254.100 -l
Logging in to [iface: default, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260]
Login to [iface: default, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260] successful.
[root@westos_student50 Desktop]# fdisk -l
[root@westos_student50 Desktop]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x83df74ca.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-4194303, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): 

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@westos_student50 Desktop]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=131008 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=524032, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@westos_student50 Desktop]# mount /dev/sdb1 /mnt/
[root@westos_student50 Desktop]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
devtmpfs         1893192        0   1893192   0% /dev
tmpfs            1921028        0   1921028   0% /dev/shm
tmpfs            1921028    18424   1902604   1% /run
tmpfs            1921028        0   1921028   0% /sys/fs/cgroup
/dev/sda3       79127812 29544316  49583496  38% /
/dev/sda1         518816   220672    298144  43% /boot
/dev/loop0       8238560  8238560         0 100% /var/www/html/source
tmpfs             384204       16    384188   1% /run/user/42
tmpfs             384204       24    384180   1% /run/user/0
/dev/sdb1        2085888    47580   2038308   3% /mnt

  • 因为在客户端中未指定服务端的共享key,所以无法登录

  • 指定客户端的共享key

  • 重启后再次登录共享设备,成功登录!!!! 

  •  列出设备,可以看到多出一块硬盘,大小为2G,说明共享成功

  •  使用此共享设备,分区,对设备可视化,挂载

  • 挂载成功

五、删除共享设备

1、删除客户端的共享设备
[root@westos_student50 Desktop]# umount /mnt/
[root@westos_student50 Desktop]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2021-08.org.westos:stragel
│       └── 172.25.254.100,3260,1
│           └── default
├── send_targets
│   └── 172.25.254.100,3260
│       ├── iqn.2021-08.org.westos:stragel,172.25.254.100,3260,1,default -> /var/lib/iscsi/nodes/iqn.2021-08.org.westos:stragel/172.25.254.100,3260,1
│       └── st_config
├── slp
└── static

10 directories, 2 files
[root@westos_student50 Desktop]# iscsiadm -m node -T iqn.2021-08.org.westos:stragel -p 172.25.254.100 -u
Logging out of session [sid: 2, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260]
Logout of [sid: 2, target: iqn.2021-08.org.westos:stragel, portal: 172.25.254.100,3260] successful.
[root@westos_student50 Desktop]# iscsiadm -m node -T iqn.2021-08.org.westos:stragel -p 172.25.254.100 -o delete
[root@westos_student50 Desktop]# fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x58fb11e5

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   1050623   1048576  512M 83 Linux
/dev/sda2       1050624   9439231   8388608    4G 82 Linux swap / Solaris
/dev/sda3       9439232 167772159 158332928 75.5G 83 Linux




Disk /dev/loop0: 7.9 GiB, 8436842496 bytes, 16478208 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x47055c33

Device       Boot Start      End  Sectors  Size Id Type
/dev/loop0p1 *        0 16478207 16478208  7.9G  0 Empty
/dev/loop0p2      23900    44279    20380   10M ef EFI (FAT-12/16/32)
[root@westos_student50 Desktop]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│   └── 172.25.254.100,3260
│       └── st_config
├── slp
└── static

  • 卸载

  •  退出共享设备

  • 删除客户机共享设备的数据 

 2、清空服务器中iscsi共享设备
[root@westosa100 ~]# targetcli
targetcli shell version 2.1.51
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> clearconfig confirm=True
All configuration cleared

  •  可以看到共享数据没有了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/618328.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号