ISCSI:后端卷以LVM 的方式配置 ISCSI 目标启动器
1写在前面
-
准备考试整理相关笔记 -
博文内容涉及使用 LVM 做ISCSI 目标后端块存储 Demo -
理解不足小伙伴帮忙指正
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
2目标端配置
配置 servera
提供一个 iSCSI 服务,磁盘名为 iqn.2014-11.com.example:servera
,并符合下列 要求:
-
服务端口为 3260
-
使用 iscsi_store
作其后端卷 其大小为3G
-
此服务只能被 serverb.lab.example.com
访问 -
后端卷为 LVM
形式
LVM 准备
查看磁盘情况
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
给 vda 做一个分区
[root@servera iscsi-review]# fdisk /dev/vda
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.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (20971487-41943039, default 20971520):
Last sector, +sectors or +size{K,M,G,T,P} (20971520-41943039, default 41943039):
Created a new partition 2 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@servera iscsi-review]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 10G 0 part /
└─vda2 252:2 0 10G 0 part
vdb 252:16 0 5G 0 disk
创建 物理卷,卷组,逻辑卷
在卷组 myvg 中创建一个名为 myvg 的逻辑卷(Logical Volume),大小为 3GB
[root@servera iscsi-review]# pvcreate /dev/vd
vda vda1 vda2 vdb
[root@servera iscsi-review]# pvcreate /dev/vda2
Physical volume "/dev/vda2" successfully created.
[root@servera iscsi-review]# vgcreate myvg /dev/vda2
Volume group "myvg" successfully created
[root@servera iscsi-review]# lvcreate -n myvg -L 3G myvg
Logical volume "myvg" created.
ISCSI 相关配置
安装 targetcli 软件包并启用 target 服务。
[root@servera iscsi-review]# yum -y install targetcli >> /dev/null
[root@servera iscsi-review]# systemctl enable --now target.service
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@servera iscsi-review]#
-
使用 targetcli 工具进入交互式命令行界面。 -
创建了一个块存储对象 iscsi_store,并将 /dev/myvg/myvg 分配给它。 -
创建了一个名为 iqn.2014-11.com.example:servera 的 iSCSI 目标。 -
在 iqn.2014-11.com.example:servera 目标的 TPG1 下创建了一个 LUN,并将 iscsi_store 块存储对+ 象映射到该 LUN。 -
创建了一个 ACL,允许名为 iqn.2014-11.com.example:serverb 的 iSCSI Initiator 访问上述目标。 -
删除了一个名为 0.0.0.0:3260 的网络端口。 -
创建了一个新的网络端口 172.25.250.10:3260。
[root@servera ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create iscsi_store /dev/myvg/myvg
Created block storage object iscsi_store using /dev/myvg/myvg.
/> /iscsi create iqn.2014-11.com.example:servera
Created target iqn.2014-11.com.example:servera.
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.2014-11.com.example:servera/tpg1/luns create /backstores/block/iscsi_store
Created LUN 0.
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/acls create iqn.2014-11.com.example:serverb
Created Node ACL for iqn.2014-11.com.example:serverb
Created mapped LUN 0.
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/portals delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/portals create 172.25.250.10 3260
Using default IP port 3260
Created network portal 172.25.250.10:3260.
查看配置情况
/> ls /
o- / ............................................................................................ [...]
o- backstores ................................................................................. [...]
| o- block ..................................................................... [Storage Objects: 1]
| | o- iscsi_store ................................... [/dev/myvg/myvg (3.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.2014-11.com.example:servera ...................................................... [TPGs: 1]
| o- tpg1 .................................................................. [no-gen-acls, no-auth]
| o- acls ............................................................................. [ACLs: 1]
| | o- iqn.2014-11.com.example:serverb ......................................... [Mapped LUNs: 1]
| | o- mapped_lun0 .............................................. [lun0 block/iscsi_store (rw)]
| o- luns ............................................................................. [LUNs: 1]
| | o- lun0 ............................. [block/iscsi_store (/dev/myvg/myvg) (default_tg_pt_gp)]
| o- portals ....................................................................... [Portals: 1]
| o- 172.25.250.10:3260 .................................................................. [OK]
o- loopback ............................................................................ [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
使用 systemctl 命令重启 target 服务。这将重新启动 iSCSI 目标服务,以应用任何配置更改或修复可能的问题。使用 firewall-cmd 命令将 iscsi-target 服务添加到防火墙的永久规则中
[root@servera ~]# systemctl restart target.service
[root@servera ~]# firewall-cmd --permanent --add-service=iscsi-target
success
[root@servera ~]# firewall-cmd --reload
success
3启动器配置
配置 serverb 使其能连接 在node1上提供的 iqn.2014-11.com.example:servera 并符合以下要 求:
-
iSCSI设备在系统启动的期间自动加载 -
块设备iSCSI上包含一个大小为 2100MiB 的分区,并格式化为 ext4 -
此分区挂载在 /mnt/data 上,同时在系统启动的期间自动挂载
[root@serverb ~]# yum search iscsi
[root@serverb ~]# yum -y install iscsi-initiator-utils
[root@serverb ~]# cat /etc/iscsi/initiatorname.iscsi
[root@serverb ~]# echo "InitiatorName=iqn.2014-11.com.example:servera" > /etc/iscsi/initiatorname.iscsi
[root@serverb ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2014-11.com.example:servera
[root@serverb ~]# systemctl enable --now iscsid.service
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.
[root@serverb ~]# man iscsiadm
通过 iSCSI 发现操作找到了目标服务器的 IP 地址和名称,并使用 iscsiadm 命令登录到该目标。然后使用 lsblk 命令确认已连接的块设备
[root@serverb ~]# iscsiadm --mode discoverydb --type sendtargets --portal 172.25.250.10 --discover
172.25.250.10:3260,1 iqn.2014-11.com.example:servera
[root@serverb ~]# man iscsiadm
[root@serverb ~]# iscsiadm --mode node --targetname iqn.2014-11.com.example:servera --portal 172.25.
250.10:3260 -l
Logging in to [iface: default, target: iqn.2014-11.com.example:servera, portal: 172.25.250.10,3260]
Login to [iface: default, target: iqn.2014-11.com.example:servera, portal: 172.25.250.10,3260] successful.
[root@serverb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3G 0 disk
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
[root@serverb ~]# lsblk --fs /dev/sda
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
通过 fdisk 命令创建了一个新的分区表,并在 /dev/sda 上创建了一个 2.1GB 大小的主分区 /dev/sda1。然后使用 mkfs.ext4 命令在该分区上创建了 ext4 文件系统,验证分区和文件系统的创建情况。
[root@serverb ~]# fdisk /dev/sda
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 0xf9fbdda4.
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-6291455, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455, default 6291455): +2100M
Created a new partition 1 of type 'Linux' and of size 2.1 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@serverb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3G 0 disk
└─sda1 8:1 0 2.1G 0 part
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
[root@serverb ~]# mkfs.ext4 /dev/sda1
mke2fs 1.44.6 (5-Mar-2019)
Creating filesystem with 537600 4k blocks and 134640 inodes
Filesystem UUID: 74d0c4f2-cc5f-46cc-a80d-5750690b5f56
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@serverb ~]# lsblk --fs /dev/sda1
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 ext4 74d0c4f2-cc5f-46cc-a80d-5750690b5f56
将 /dev/sda1 分区(文件系统类型为 ext4)挂载到 /mnt/data 目录,并将该挂载配置添加到 /etc/fstab 文件中,以便在系统启动时自动挂载该文件系统。
[root@serverb ~]# blkid /dev/sda1
/dev/sda1: UUID="74d0c4f2-cc5f-46cc-a80d-5750690b5f56" TYPE="ext4" PARTUUID="f9fbdda4-01"
[root@serverb ~]# mkdir /mnt/data
[root@serverb ~]# echo "UUID='74d0c4f2-cc5f-46cc-a80d-5750690b5f56' /mnt/data ext4 _netdev 0 0" >> /
etc/fstab
[root@serverb ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Oct 29 16:26:01 2019
#
# 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.
#
UUID=f7614c41-2835-4125-bb13-50772dc2f30c / xfs defaults 0 0
servera.lab.example.com:/nfsshare /share nfs defaults 0 0
UUID='74d0c4f2-cc5f-46cc-a80d-5750690b5f56' /mnt/data ext4 _netdev 0 0
[root@serverb ~]# mount /mnt/data
[root@serverb ~]# df -ht ext4
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.0G 6.2M 1.9G 1% /mnt/data
[root@serverb ~]#
4博文部分内容参考
© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知
红帽服务管理与自动化(RH358)
授课笔记
© 2018-2023 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)
- 点赞
- 收藏
- 关注作者
评论(0)