制作raid1
raid1(速率不好,数据保护好,50%)
1.添加3块磁盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 409M 0 disk
└─sdb1 8:17 0 408M 0 part
sdc 8:32 0 409M 0 disk
└─sdc1 8:33 0 408M 0 part
sdd 8:48 0 409M 0 disk
└─sdd1 8:49 0 408M 0 part
2.分区并设置类型(type)
[root@localhost ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x485d2350.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-837631, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-837631, default 837631):
Using default value 837631
Partition 1 of type Linux and of size 408 MiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.创建raid1
[root@localhost ~]# mdadm -C /dev/md1 -l 1 -n 3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
4.查看md1的详情
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Apr 3 22:37:34 2022
Raid Level : raid1
Array Size : 416768 (407.00 MiB 426.77 MB)
Used Dev Size : 416768 (407.00 MiB 426.77 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sun Apr 3 22:37:35 2022
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : d893bd10:f2a820d3:b74df6f4:fd01fb79
Events : 17
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
5.格式化md1
[root@localhost ~]# mkfs.ext3 /dev/md1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
104448 inodes, 416768 blocks
20838 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
51 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
6.创建文件夹,挂载,测试
[root@localhost ~]# mkdir wenhan1
[root@localhost ~]# mount /dev/md1 wenhan1
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 17G 4.5G 13G 27% /
devtmpfs devtmpfs 974M 0 974M 0% /dev
tmpfs tmpfs 991M 0 991M 0% /dev/shm
tmpfs tmpfs 991M 11M 980M 2% /run
tmpfs tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 166M 849M 17% /boot
tmpfs tmpfs 199M 4.0K 199M 1% /run/user/42
tmpfs tmpfs 199M 20K 199M 1% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64
/dev/md1 ext3 387M 136M 231M 38% /root/wenhan1
7.复制文件到wenhan1文件夹里面
[root@localhost ~]# cp -r /boot/* wenhan1/
[root@localhost ~]# cd wenhan1
[root@localhost wenhan1]# ls
config-3.10.0-957.el7.x86_64 lost+found
efi symvers-3.10.0-957.el7.x86_64.gz
grub System.map-3.10.0-957.el7.x86_64
grub2 vmlinuz-0-rescue-b6186d2beda149fdb531e31451f798ac
initramfs-0-rescue-b6186d2beda149fdb531e31451f798ac.img vmlinuz-3.10.0-957.el7.x86_64
initramfs-3.10.0-957.el7.x86_64.img
8.移除其中一块硬盘
[root@localhost ~]# mdadm /dev/md1 -f /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md1
9.重启并查看(重启后要挂载)
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 409M 0 disk
└─sdb1 8:17 0 408M 0 part
sdc 8:32 0 409M 0 disk
└─sdc1 8:33 0 408M 0 part
└─md1 9:1 0 407M 0 raid1
sdd 8:48 0 409M 0 disk
└─sdd1 8:49 0 408M 0 part
└─md1 9:1 0 407M 0 raid1
10.进入wenhan1文件夹查看之前复制的文件时候还在
[root@localhost ~]# cd wenhan1
[root@localhost wenhan1]# ls
config-3.10.0-957.el7.x86_64 lost+found
efi symvers-3.10.0-957.el7.x86_64.gz
grub System.map-3.10.0-957.el7.x86_64
grub2 vmlinuz-0-rescue-b6186d2beda149fdb531e31451f798ac
initramfs-0-rescue-b6186d2beda149fdb531e31451f798ac.img vmlinuz-3.10.0-957.el7.x86_64
initramfs-3.10.0-957.el7.x86_64.img
11.将之前卸载下来的硬盘,添加上去
[root@localhost ~]# mdadm /dev/md1 -a /dev/sdb1
mdadm: added /dev/sdb1
12.查看(恢复后的硬盘)
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 409M 0 disk
└─sdb1 8:17 0 408M 0 part
└─md1 9:1 0 407M 0 raid1 /root/wenhan1
sdc 8:32 0 409M 0 disk
└─sdc1 8:33 0 408M 0 part
└─md1 9:1 0 407M 0 raid1 /root/wenhan1
13.查看创建的raid
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1] [raid0]
md0 : active raid0 sdg1[2] sdf1[1] sde1[0]
933888 blocks super 1.2 512k chunks
md1 : active raid1 sdd1[2] sdc1[1]
416768 blocks super 1.2 [3/2] [_UU]
完结,撒花
本文来自博客园,作者:Cloudservice,转载请注明原文链接:https://www.cnblogs.com/whwh/p/16095983.html,只要学不死,就往死里学!