Linux系统下实现ISCSI磁盘网络共享

一、ISCSI基础信息

1.ISCSI 概念

  • SCSI(Internet SCSI) 支持从客户端 ( 发起端 ) 通过 IP 向远程 服务器上的 iSCSI 存储设备 ( 目标 )
    发送 SCSI 命令。
  • iSCSI 限定名称用于确定发起端和目标 , 并采用 iqn.yyyy-mm. {reverse domain}:label 的格式
  • 默认情况下 , 网络通信是至 iSCSI 目标上的端口 3260/tcp 的明 文端口

2.ISCSI 名称设定

  • iSCSI 发起端 : 需要访问原始 SAN 存储的客户端

  • iSCSI 目标 : 从 iSCSI 服务器提供的远程硬盘磁盘 , 或“目标门 户”

  • iSCSI 目标门户 : 通过网络向发起端提供目标的服务器。

  • iqn:“iSCSI 限定名称”。每个发起端和目标需要唯一名称进行标识最好的做法是使用一个在 Internet 上可能独一无二的名称

  • iqn: iSCSI Qualified Name(iSCSI合格名称)

二、磁盘网络共享

服务端:
安装策略软件

 [root@server ~]# yum install targetcli.noarch  -y

开启服务

[root@server ~]# systemctl start target
[root@server ~]# systemctl stop firewalld

建立共享的分区

[root@server ~]# fdisk /dev/vdb ##分一个2G的分区出来vdb1

配置targetcli

[root@server ~]# targetcli
/> /backstores/block create hello:storage1 /dev/vdb1  ##命名设备块
Created block storage object hello:storage1 using /dev/vdb1.
/> /iscsi create iqn.2018-06.com.example:storage1##生成共享设备
Created target iqn.2018-06.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2018-06.com.exqmple:storage1/tpg1/acls create iqn.2018-06.com.example:hellokey ##生成共享设备的钥匙
Created Node ACL for iqn.2018-06.com.example:hellokey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1 ##创造共享设备指向本地设备的链接
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-06.com.example:hellokey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals create 172.25.254.205 ##添加共享设备的端口
Using default IP port 3260
Created network portal 172.25.254.205:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

最后的目录
这里写图片描述

客户端:

[root@client westos]# yum install iscsi-initiator-utils.x86_64 -y
[root@client iscsi]# vim   initiatorname.iscsi 
1 InitiatorName=iqn.2018-06.com.example:westoskey ##名称和服务端生成的key一致
[root@client iscsi]# systemctl restart iscsi
[root@client iscsi]# iscsiadm -m discovery -t st -p 172.25.254.205 
##-m表示动作,使用检测的方式进行iscsiadm命令 ;-t表示st类型 ;-p(ip:port)表示从205主机获取iscsi设备与端口,不写端口就是默认的3260
172.25.254.205:3260,1 iqn.2018-06.com.example:storage1
[root@client iscsi]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.205 -l
##-m node,表示找到目前本纪上所有检测的target信息;-T ,目标名称;-l,表示登录
Logging in to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.205,3260] (multiple)
Login to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.205,3260] successful.

查看共享的磁盘

[root@client iscsi]# fdisk -l

这里写图片描述

三、设置开机自动挂载

1.对共享磁盘进行划分

[root@client iscsi]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0x6a3af068.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):  
Using default response p
Partition number (1-4, default 1): 
First sector (8192-4194303, default 8192): 
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

2.进行格式化

[root@client ~]# mkfs.xfs /dev/sda1 

3.编辑文件

[root@client ~]# vim /etc/fstab 
/dev/sda1       /mnt    xfs     defaults,_netdev 0 0 

这里写图片描述
reboot 第一次需要手动关机 rht-vmctl poweroff desktop

四、共享设备的删除

[root@client iscsi]# yum install tree.x86_64  -y
[root@client iscsi]# tree  /var/lib/iscsi/

树形图显示iscsi
这里写图片描述

[root@client ~]# umount /mnt/ ##卸载设备
[root@client ~]# vim /etc/fstab ##删除挂载的内容
[root@client ~]# iscsiadm -m node -T  iqn.2018-06.com.example:storage1 -P 172.25.254.205 -u ##登出,但是重启之后sdb1又会显示
[root@client ~]# iscsiadm -m node -T  iqn.2018-06.com.example:storage1 -P 172.25.254.205 -o delete ##需要删除其相关文件
[root@client ~]# tree /var/lib/iscsi/

删除之后的树形图
这里写图片描述

[root@client iscsi]# systemctl restart iscsi  
[root@client iscsi]# fdisk -l ##已经没有sdb1

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41476978/article/details/80598376
今日推荐