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

Debian配置Raid5和部署LVM

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

Debian配置Raid5和部署LVM

要求

在虚拟机上添加 4 个 1G 的硬盘;
创建 raid5,其中一个作为热备盘, 设备名为md0;
将 md0 设置为 LVM,设备为/dev/vg01/lv01;
格式化为 ext4 文件系统;
开机自动挂载到/data 目录

首先给虚拟机添加4块10G的网卡, 然后重启虚拟机

查看新添加的硬盘,有点奇怪,为什么原先的硬盘变成sdb了,无所谓了

root@debian:~# fdisk -l
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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 /dev/sdb: 120 GiB, 128849018880 bytes, 251658240 sectors
Disk model: VMware Virtual S
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: 0xa6af50b5

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdb1  *         2048 249657343 249655296  119G 83 Linux
/dev/sdb2       249659390 251656191   1996802  975M  5 Extended
/dev/sdb5       249659392 251656191   1996800  975M 82 Linux swap / Solaris


Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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 /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
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 /dev/sde: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

然后安装mdadm和lvm2

root@debian:~# apt install -y mdadm lvm2

创建raid5,并添加一块磁盘作为热备,当有硬盘损坏时,会自动启用热备盘

-n 3 表示使用三块硬盘(raid5最少需要3块硬盘)

-x 1 表示使用一块热备盘

-l 5 表示使用raid5

使用的磁盘注意要和自己主机上的硬盘相对应,不要弄错了

root@debian:~# mdadm -C /dev/md0 -l 5 -n 3 -x 1 /dev/sd[c-e] /dev/sda
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

查看新创建的raid5

root@debian:~# mdadm --detail /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Thu Nov 25 20:47:01 2021
        Raid Level : raid5
        Array Size : 20953088 (19.98 GiB 21.46 GB)
     Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Nov 25 20:47:53 2021
             State : clean 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : debian:0  (local to host debian)
              UUID : ad8e9446:91715e8b:d4240537:655a8eef
            Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd
       4       8       64        2      active sync   /dev/sde

       3       8        0        -      spare   /dev/sda

三块磁盘处于活跃状态,剩下的一块就是热备盘了

接下来创建lvm卷组

root@debian:~# vgcreate vg01 /dev/md0
  Physical volume "/dev/md0" successfully created.
  Volume group "vg01" successfully created

创建逻辑卷

-n 指定逻辑卷名

-L 指定逻辑卷大小

这里创建了一个1G的逻辑卷

root@debian:~# mkfs.ext4 /dev/vg01/lv01 
mke2fs 1.46.2 (28-Feb-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: bf2c26e2-50c2-4697-8761-87b8c90c1400
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
root@debian:~# lvcreate -n lv01 -L 1G vg01 
  Logical volume "lv01" created.

输入 fdisk -l 可以查看到

Disk /dev/mapper/vg01-lv01: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes

然后格式化新创建的逻辑卷

root@debian:~# mkfs.ext4 /dev/vg01/lv01 
mke2fs 1.46.2 (28-Feb-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: bf2c26e2-50c2-4697-8761-87b8c90c1400
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

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

创建挂载点并挂载

root@debian:~# cd /
root@debian:/# mkdir data
root@debian:/# mount /dev/vg01/lv01 /data/

 修改 /etc/fstab,设置开机自动挂载

首先使用blkid查看/dev/vg01./lv01的uuid,使用uuid写入到/etc/fstab中实现开机自动挂载

root@debian:/# blkid /dev/vg01/lv01 
/dev/vg01/lv01: UUID="bf2c26e2-50c2-4697-8761-87b8c90c1400" BLOCK_SIZE="4096" TYPE="ext4"
root@debian:/# vim /etc/fstab 

写入以下内容

UUID=bf2c26e2-50c2-4697-8761-87b8c90c1400	/data	ext4	defaults	00

这样在开机的时候就会自动挂载了 

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

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

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