iscsi linux system disk sharing network

iscsi

The main storage device ISCSI is made possible to provide the server side disk, and then through iscsi Initiator (iscsi user initialization) function, use is made can be used to mount iscsi provided to apply the disks. In other words, iscsi this architecture will be the main storage device and the host used is divided into two parts, namely:

  • (1) iscsi target: the end is a storage device, storage disks or RAID devices.
  • (2) iscsi initiator: the user is able to use the target side, typically the server. Before you can use other words, you want to connect to the iscsi target server must also install a disk-related functions iscsi target iscsi initistor provided.

1, disk sharing settings

Server
1) division as a shared disk partition:
shared disk partitions can be physical disk partition, but once set up after the physical disk partitions to share mount is completed, the space will determine the urine, the capacity can not be changed. It is recommended to use the lvm logical volumes to share, you can easily achieve the expansion of shared partitions.

Create a shared partition:
[root @ Server ~] # fdisk / dev / VDB # disk partitions to divide
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.

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

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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
Disk label type: dos
Disk identifier: 0x09ee18d7

Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 8e Linux LVM
/dev/vdb2 1026048 3074047 1024000 8e Linux LVM

Command (m for help): wq
The partition table has been altered!

Ioctl Calling () to Re-Partition the Read the Table
[root @ Server ~] # # partprobe refresh loading area list

Here Insert Picture Description

创建 LVM
[root@server ~]# pvcreate /dev/vdb2 #创建物理卷
Physical volume “/dev/vdb2” successfully created
[root@server ~]# vgcreate vg1 /dev/vdb2 #创建物理卷组 vg0
Volume group “vg1” successfully created
[root@server ~]# lvcreate -L 500M -n lv0 vg1 # 在卷组vg1中创建逻辑卷
Logical volume “lv0” created
[root@server ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
vo vg0 -wi-ao---- 400.00m
lv0 vg1 -wi-a----- 500.00m
Here Insert Picture Description

2)安装支持共享软件:

yum install targetcli -y #安装共享策略编辑器
systemctl start target #启动服务
systemctl enable target.service #设置服务开机自动启动

targetcli #使用共享编辑器对磁盘进行处理的命令

  [root@server ~]# targetcli         #进入共享软件
  Warning: Could not load preferences file /root/.targetcli/prefs.bin.
  targetcli shell version 2.1.fb34
 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]

Here Insert Picture Description

    /> /backstores/block create yang /dev/vg1/lv0    #添加已创建的逻辑卷到 Backstores 项下,命名为yang,向当于起了一个别名
 Created block storage object yang using /dev/vg1/lv0.
 /> iscsi/ create iqn.2019-05.com.westos:yang       ##创建新的 Target(服务器上的共享资源),服务器共享的资源的名称
 Created target iqn.2019-05.com.westos:yang.
 Created TPG 1.

Here Insert Picture Description

   /> iscsi/iqn.2019-05.com.westos:yang/tpg1/acls create iqn.2019-05.com.westos:westoskey1    ##在 TPG 项下,新建 ACL 访问权限列表 ,限制仅客户端InitiatorName 的值为iqn.2019-05.com.lala:totokey 的可以访问该共享资源

Here Insert Picture Description

   /> iscsi/iqn.2019-05.com.westos:yang/tpg1/luns create /backstores/block /westos:yang         ##添加 Backstores 下的磁盘到 LUN 项下,并且将该磁盘与茶创建的共享资源进行关联   

Here Insert Picture Description

  /> iscsi/iqn.2019-05.com.westos:yang/tpg1/portals/ create 172.25.254.11  #添加本机 IP 和端口    
 Using default IP port 3260
 Created network portal 172.25.254.11:3260.

Here Insert Picture Description
/> exit #退出策略编辑器,并对生成的策略进行保存

 Global pref auto_save_on_exit=true
 Last 10 configs saved in /etc/target/backup.
 Configuration saved to /etc/target/saveconfig.json     

Here Insert Picture Description
防火墙设置:
firewall-cmd --permanent --add-port=3260/tcp #添加防火墙允许3260端口 上面使用
firewall-cmd --reload #重新加载防火墙配置

Here Insert Picture Description
Here Insert Picture Description

客户端
yum install iscsi-initiator-utils -y #安装网络磁盘共享客户端软件
vim /etc/iscsi/initiatorname.iscsi # 编辑配置文件

   InitiatorName=iqn.2019-05.com.westos:yangkey       #指定客户端的nitiatorName 值,与服务端的权限列表中的生成加密一致,才能使用

Here Insert Picture Description
systemctl enable iscsi #设置服务开机自动启动
systemctl start iscsi # 启动服务
systemctl restart iscsi.service #重新启动服务,加载配置
iscsiadm -m discovery -t st -p 172.25.254.11 #寻找发现服务端已设置好的共享资源
iscsiadm -m node -T iqn.2019-05.com.westos:yang -p 172.25.254.11 -l #登录服务端已设置好的 共享资源

测试:
fdisk -l #查看客户端的磁盘设备,出现共享资源

Here Insert Picture Description
2、客户端对共享资源的使用。

fdisk -l #查看系统存在的磁盘分区
划分出一个100M的分区
Here Insert Picture Descriptionfdisk /dev/sda #对共享磁盘进行分区

Here Insert Picture Descriptionmkfs.xfs /dev/sda1 # 格式化文件系统
mount /dev/sda1 /opt #进行挂载

Here Insert Picture Description
Here Insert Picture Description进入共享磁盘进行创建文件等操作
Here Insert Picture Description设置开机自动挂载
vim /etc/fstab # 编辑文件,设定开机自动挂载

  UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /opt xfs  defaults,_netdev 0  0    

使用UUID的方式指定要被挂载的设备,比较稳定。
_netdev 参数表示这是一个网络挂载,提醒系统在网络启动之后进行挂载。

Here Insert Picture Description
reboot #重新启动系统。
Here Insert Picture Description注意:设置完成后可能无法自动正常关机,需要强制进行关机后,重新开机。

Here Insert Picture Description3、扩展共享资源

当共享分区容量不够使用的时候,由于为我们使用的是lvm 所有可以进行扩展。

Here Insert Picture Description服务端增加共享的分区的大小

Here Insert Picture Description客户端退出该共享分区之后重新登陆共享分区,共享分区变成增加后的大小。

iscsiadm -m node -T iqn.2019-05.com.westos:yang -p 172.25.254.11-u #退出

iscsiadm -m node -T iqn.2019-05.com.westos:yang -p 172.25.254.11 -l #登陆

再次查看共享分区大小变成增加后的800M ,扩展成功

4、取消共享分区

  • 取消的时候,必须确保客户端没有使用该共享分区。

客户端:

umount /opt #卸载共享分区的挂载
iscsiadm -m node -T iqn.2019-05.com.westos:yang -p 172.25.254.11 -u #退出共享分区
iscsiadm -m node -T iqn.2019-05.com.westos:yang -p 172.25.254.11 -o delete #删除共享数据
vim /etc/fstab #在该文件中删除设置的自动挂载。否则再次开机出现异常。
Here Insert Picture Description
服务端:

targetcli # to enter a shared policy editor
/> clearconfig confirm = True # Clear all sharing settings

Here Insert Picture Description
It can also be created in the same time and, step by step removed, but will create command to create into delete.

Guess you like

Origin blog.csdn.net/Y950904/article/details/89925804