Centos7挂载iSCSI存储

Centos7挂载iSCSI存储

查看、安装iSCSI软件包

[root@cloudreve ~]# rpm -qa | grep iscsi   
[root@cloudreve ~]# 
[root@cloudreve ~]# yum install -y iscsi-initiator-utils

rpm -qa查询为空,则需要手动安装

开启iSCSI服务,并设置开机自启

[root@cloudreve ~]# systemctl start iscsid
[root@cloudreve ~]# systemctl enable iscsid
[root@cloudreve ~]# systemctl start iscsi
[root@cloudreve ~]# systemctl enable iscsi

发现、注册、开机自动注册iSCSI目标

  1. 发现
[root@cloudreve ~]#  iscsiadm -m discovery -t sendtargets -p 192.168.3.240:3260
192.168.3.240:3260,1 iqn.1995-05.com.seagate:seagate-d4.iscsi5
[root@cloudreve ~]#

192.168.3.254为iSCSI目标端,3260为默认端口

  1. 注册
[root@cloudreve ~]# iscsiadm -m node -T iqn.1995-05.com.seagate:seagate-d4.iscsi5 -p 192.168.3.240:3260 -l
Logging in to [iface: default, target: iqn.1995-05.com.seagate:seagate-d4.iscsi5, portal: 192.168.3.240,3260] (multiple)
Login to [iface: default, target: iqn.1995-05.com.seagate:seagate-d4.iscsi5, portal: 192.168.3.240,3260] successful.
[root@cloudreve ~]#
[root@cloudreve ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   10G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0    9G  0 part
  ├─centos-root 253:0    0    8G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
sdb               8:16   0  2.7T  0 disk
sr0              11:0    1 1024M  0 rom

注册后可以看到新增了sdb磁盘,即iSCSI目标

  1. 设置开机自动注册
[root@cloudreve ~]# iscsiadm -m node -T iqn.1995-05.com.seagate:seagate-d4.iscsi5 -p 192.168.3.240:3260 --op update -n node.startup -v automatic
[root@cloudreve ~]#

设置分区类型,格式化分区

  1. 设置分区类型为GPT
[root@cloudreve ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SEAGATE iSCSI Storage (scsi)
Disk /dev/sdb: 2941GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      8389kB  2941GB  2941GB

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart primary 0% 100%
(parted) print
Model: SEAGATE iSCSI Storage (scsi)
Disk /dev/sdb: 2941GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      8389kB  2941GB  2941GB               primary

(parted) quit
Information: You may need to update /etc/fstab.

由于iSCSI目标大于2T,无法使用fdisk分区,使用parted将分区格式设置成GPT

  1. 格式化成ext4分区格式
[root@cloudreve ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=2048 blocks
179511296 inodes, 718017578 blocks
35900878 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2866806784
21913 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

挂载、开机自动挂载分区

  1. 创建/data,并将iSCSI目标自动挂载到/data下
[root@cloudreve ~]# mkdir /data
mkdir: cannot create directory ‘/data’: File exists
[root@cloudreve ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Aug 16 20:55:40 2022
#
# 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=3973dd39-521f-46c1-9497-851fa6d6c694 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb        /data   ext4    defaults,_netdev        0 0
[root@cloudreve ~]#
[root@cloudreve ~]# mount -a
[root@cloudreve ~]#
[root@cloudreve ~]#
[root@cloudreve ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G  9.1M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       8.0G  2.1G  5.9G  27% /
/dev/sda1               xfs      1014M  137M  878M  14% /boot
tmpfs                   tmpfs     799M     0  799M   0% /run/user/0
/dev/sdb                ext4      2.7T   89M  2.5T   1% /data
[root@cloudreve ~]#

注意,fstab文件中必须指定_netdev,不然重启无法正常开机,详细挂载配置见上文

posted @   小白的路  阅读(2762)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示