首页 > 系统相关 >CentOS7 - 软raid

CentOS7 - 软raid

时间:2022-09-26 19:13:55浏览次数:94  
标签:raid 10G Devices CentOS7 dev 252 md0 ###

前言


参考链接:https://blog.csdn.net/u011130086/article/details/119172119

有台服务器没有 RAID 卡,虽然数据不太重要,但是真要丢失了还是会存在一些麻烦。因此考虑用 软 RAID 的方式实现数据的冗余。


实现过程


首先,在虚拟机上模拟这个过程,环境如下:

OS:	CentOS Linux release 7.9.2009
Kernel:	3.10.0-1160.el7.x86_64

Raid disk:
vdb             252:16   0   10G  0 disk
vdc             252:32   0   10G  0 disk

以上两块10G 的盘,做一个 RAID-1 :

yum install -y mdadm

### 执行创建命令:
# -C : create 创建
# -a : auto 
# -l : level RAID 组
# -n : 磁盘数量
# /dev/vd{b,c} : vdb/vdc

> mdadm -C /dev/md0 -a yes -l 1 -n 2 /dev/vd{b,c}
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

创建成功后,可以查看初始化执行进度:

### 静态查看:
> cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 vdc[1] vdb[0]
      10478400 blocks super 1.2 [2/2] [UU]
      [============>........]  resync = 62.4% (6549120/10478400) finish=0.8min speed=75277K/sec
     
### 动态查看:
> watch -n 1 cat /proc/mdstat

两个命令查看创建结果:

> mdadm -Q /dev/md0
/dev/md0: 9.99GiB raid1 2 devices, 0 spares. Use mdadm --detail for more detail.

> mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Sep 26 15:03:23 2022
        Raid Level : raid1
        Array Size : 10478400 (9.99 GiB 10.73 GB)
     Used Dev Size : 10478400 (9.99 GiB 10.73 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Mon Sep 26 15:06:02 2022
             State : clean
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : 85f49180:c8da6dad:fe8b2f7d:d63baa9e
            Events : 17

    Number   Major   Minor   RaidDevice State
       0     252       16        0      active sync   /dev/vdb
       1     252       32        1      active sync   /dev/vdc

创建文件系统:

> mkfs.xfs /dev/md0
meta-data=/dev/md0               isize=512    agcount=4, agsize=654900 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2619600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载:

### 临时挂载:
> mkdir /test
> mount /dev/md0 /test/
> df | egrep test
/dev/md0                xfs        10G   33M   10G   1% /test

### 开机挂载:
> egrep test /etc/fstab
/dev/md0                /test                   xfs     defaults        0 0

创建并修改 RAID 开机启动文件:

> mdadm --detail /dev/md0 | egrep UUID > /etc/mdadm.conf
### 修改如下:
> cat /etc/mdadm.conf
### UUID 为上面命令获取的
ARRAY   /dev/md0              UUID=85f49180:c8da6dad:fe8b2f7d:d63baa9e

做完上面的配置后,重启主机尝试。

> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sr0              11:0    1 1024M  0 rom
vda             252:0    0  100G  0 disk
├─vda1          252:1    0    1G  0 part  /boot
└─vda2          252:2    0   99G  0 part
  ├─centos-root 253:0    0 91.1G  0 lvm   /
  └─centos-swap 253:1    0  7.9G  0 lvm   [SWAP]
vdb             252:16   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test
vdc             252:32   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test

> reboot

>lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sr0              11:0    1 1024M  0 rom
vda             252:0    0  100G  0 disk
├─vda1          252:1    0    1G  0 part  /boot
└─vda2          252:2    0   99G  0 part
  ├─centos-root 253:0    0 91.1G  0 lvm   /
  └─centos-swap 253:1    0  7.9G  0 lvm   [SWAP]
vdb             252:16   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test
vdc             252:32   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test
>touch /test/abc
>ls /test/
abc

测试


模拟损坏一块硬盘,查看 RAID 状态

### 直接通过宿主机将这块盘模拟拔出
> virsh detach-disk 192_168_1_108 /kvm_images/192_168_1_108_vdc.qcow2 --live --config

查看 RAID状态:

>mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Sep 26 15:03:23 2022
        Raid Level : raid1
        Array Size : 10478400 (9.99 GiB 10.73 GB)
     Used Dev Size : 10478400 (9.99 GiB 10.73 GB)
      Raid Devices : 2
     Total Devices : 1
       Persistence : Superblock is persistent

       Update Time : Mon Sep 26 15:17:36 2022
             State : clean, degraded	### 状态也出现了 degraded
    Active Devices : 1
   Working Devices : 1
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : 85f49180:c8da6dad:fe8b2f7d:d63baa9e
            Events : 20

    Number   Major   Minor   RaidDevice State
       0     252       16        0      active sync   /dev/vdb
       -       0        0        1      removed			### 可以发现已经处于 removed状态

查看数据是否还存在:

>lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sr0              11:0    1 1024M  0 rom
vda             252:0    0  100G  0 disk
├─vda1          252:1    0    1G  0 part  /boot
└─vda2          252:2    0   99G  0 part
  ├─centos-root 253:0    0 91.1G  0 lvm   /
  └─centos-swap 253:1    0  7.9G  0 lvm   [SWAP]
vdb             252:16   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test

### 数据依然存在。
root@localhost(192.168.1.108)~>ls /test/
abc

模拟加入新硬盘:

> virsh attach-disk 192_168_1_108 /kvm_images/192_168_1_108_vdc.qcow2  vdc --config --live
> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sr0              11:0    1 1024M  0 rom
vda             252:0    0  100G  0 disk
├─vda1          252:1    0    1G  0 part  /boot
└─vda2          252:2    0   99G  0 part
  ├─centos-root 253:0    0 91.1G  0 lvm   /
  └─centos-swap 253:1    0  7.9G  0 lvm   [SWAP]
vdb             252:16   0   10G  0 disk
└─md0             9:0    0   10G  0 raid1 /test
vdd             252:48   0   10G  0 disk	### 卸载的是vdc 再次装载变成 vdd


### 加入新RAID组
> mdadm --manage /dev/md0 --add /dev/vdd
> mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Sep 26 18:22:08 2022
        Raid Level : raid1
        Array Size : 10478400 (9.99 GiB 10.73 GB)
     Used Dev Size : 10478400 (9.99 GiB 10.73 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Mon Sep 26 18:30:43 2022
             State : clean, degraded, recovering
    Active Devices : 1
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

    Rebuild Status : 6% complete

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : c9297ee4:5c04d6d9:d0552494:2f27df9a
            Events : 27

    Number   Major   Minor   RaidDevice State
       0     252       16        0      active sync   /dev/vdb
       2     252       48        1      spare rebuilding   /dev/vdd	### 处于 rebuilding 阶段


### 正在重建
> cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 vdd[2] vdb[0]
      10478400 blocks super 1.2 [2/1] [U_]
      [==========>..........]  recovery = 50.3% (5271168/10478400) finish=1.1min speed=76393K/sec
      


### 重建成功
> mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Sep 26 18:22:08 2022
        Raid Level : raid1
        Array Size : 10478400 (9.99 GiB 10.73 GB)
     Used Dev Size : 10478400 (9.99 GiB 10.73 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Mon Sep 26 18:32:57 2022
             State : clean
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : c9297ee4:5c04d6d9:d0552494:2f27df9a
            Events : 43

    Number   Major   Minor   RaidDevice State
       0     252       16        0      active sync   /dev/vdb
       2     252       48        1      active sync   /dev/vdd
       
### 查看数据
> ls /test/
abc		### 数据未丢失


--- EOF ---

标签:raid,10G,Devices,CentOS7,dev,252,md0,###
From: https://www.cnblogs.com/hukey/p/16732024.html

相关文章

  • 第十九章 Centos7下Docker安装Tomcat
    一、查找Tomcat镜像[root@staging~]#dockersearchtomcat二、拉取Tomcat镜像[root@staging~]#dockerpulltomcat三、运行Tomcat#在/root目录下创建tomcat......
  • 第十六章 Centos7下Docker安装GitLab
    一、查找Gitlab镜像[root@staging~]#dockersearchgitlab二、拉取Gitlab镜像[root@staging~]#dockerpullgitlab/gitlab-ce:latest三、运行GitLab[root@sta......
  • Centos7安装Python虚拟环境之virtualenv
    一、安装自己需要的python版本步骤略二、安装virtualenv模块并创建虚拟环境[root@localhost~]#/usr/local/python3.6.8/bin/pip3installvirtualenv[root@localh......
  • CentOS7 程序开机自启
    1、新建自启服务cd/usr/lib/systemd/systemvimjava_system.service【java_system.service】[Unit]#描述Description=java-system#配置自启顺序(在哪些程序启动......
  • Centos7 安装遇到的问题小结Centos7 安装遇到的问题小结
    安装桌面desktop步骤因为centos7选择了最小化安装的,默认都是不带XWINDOWS的,所以在安装这些桌面之前得先安装一下XWINDOWS,这个控制功能。#yumupgrade#yum-ygroupi......
  • CentOS7下安装python3.7
    以原码编译的方式安装1.官网下载python3.7软件包2.上传至Linux中,并解压 tar-zxvfpython-3.7.2.tgz3.安装gcc和python所需依赖yum-yinstallgccyuminstallzli......
  • Centos7上安装ElasticSearch
    我这里选择的版本是Elasticsearch7.17.6,下载链接为Elasticsearch7.17.6|Elastic下载完毕后解压到想要安装的文件夹,我这里是/data/elasticsearch-7.17.6由于我......
  • CentOS7内置Realtek网卡驱动r8169降级r8168
    前几天装了几台服务器测试,在使用的过程中发现,每次重启系统,登录界面会弹出网卡提示 “r81690000:02:00eth0Invalidocpreg17758!”经过测试发现:1、开机前将et......
  • CentOS7安装Git
    目录参考资料下载地址步骤1.下载包2.git-2.9.5.tar.gz和git-manpages-2.9.5.tar.gz上传服务器3.解压并编译参考资料官网GitProBook安装说明下载地址https://gi......
  • Vmware部署Linux无人值守安装Centos7系统
    Linux-无人值守安装服务#需求分析-使用光盘镜像来安装Linux系统的方式;坦白讲,该方法适用于只安装少量Linux系统的情况,如果生产环境中有数百台服务器都需安......