RAID1创建

建立raid1
    创建raid1
    添加1G热备盘
    模拟磁盘故障,自动顶替故障盘
    卸载阵列并删除整个阵列
    环境:创建分区c1 c2 c3  大小为1G
环境的准备
[root@ZQ ~]# fdisk /dev/sdc
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 0x05c92672.

Command (m for help): p

Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
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 label type: dos
Disk identifier: 0x05c92672

   Device Boot      Start         End      Blocks   Id  System

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): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-20971519, default 2099200): 
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4196352-20971519, default 4196352): 
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +1G
Partition 3 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
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 label type: dos
Disk identifier: 0x05c92672

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     2099199     1048576   83  Linux
/dev/sdc2         2099200     4196351     1048576   83  Linux
/dev/sdc3         4196352     6293503     1048576   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ZQ ~]# ll /dev/sdc*
brw-rw----. 1 root disk 8, 32 Jun  4 06:18 /dev/sdc
brw-rw----. 1 root disk 8, 33 Jun  4 06:18 /dev/sdc1
brw-rw----. 1 root disk 8, 34 Jun  4 06:18 /dev/sdc2
brw-rw----. 1 root disk 8, 35 Jun  4 06:18 /dev/sdc3

创建raid1
[root@ZQ ~]# mdadm -C -v /dev/md1 -l 1 -n 2 -x 1 /dev/sdc1 /dev/sdc2 /dev/sdc3 
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
mdadm: size set to 1047552K
Continue creating array? 
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@ZQ ~]# ll /dev/md1
brw-rw----. 1 root disk 9, 1 Jun  4 06:24 /dev/md1


查看创建阵列信息生成配置文件检查配置文件
[root@ZQ ~]# cat /proc/mdstat 
Personalities : [raid0] [raid1] 
md1 : active raid1 sdc3[2](S) sdc2[1] sdc1[0]    #s 备用盘
      1047552 blocks super 1.2 [2/2] [UU]  #状态
      
md0 : active raid0 sdb2[1] sdb1[0]
      2095104 blocks super 1.2 512k chunks
      
unused devices: <none>
[root@ZQ ~]# mdadm -Ds > /etc/mdadm.conf 
[root@ZQ ~]# cat !$
cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=ZQ:0 UUID=00d9284f:6fd6b3b0:afc571c6:c5441608
ARRAY /dev/md1 metadata=1.2 spares=1 name=ZQ:1 UUID=137b8247:e0ced5a2:625805ac:e9b31692



将创建好的raid1磁盘格式化分区,生成系统文件,挂载正常使用
[root@ZQ ~]# mkfs.ext4 /dev/md1p1 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65408 inodes, 261632 blocks
13081 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

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

[root@ZQ ~]# mkdir /raid1
[root@ZQ ~]# mount /dev/md1p1 /raid1
[root@ZQ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        15G  3.6G   12G  24% /
devtmpfs        474M     0  474M   0% /dev
tmpfs           489M  156K  489M   1% /dev/shm
tmpfs           489M  7.0M  482M   2% /run
tmpfs           489M     0  489M   0% /sys/fs/cgroup
/dev/sda1       197M  131M   67M  67% /boot
tmpfs            98M  8.0K   98M   1% /run/user/1000
/dev/sr0        4.1G  4.1G     0 100% /run/media/zq/CentOS 7 x86_64
tmpfs            98M     0   98M   0% /run/user/0
/dev/md0p1      2.0G  6.1M  1.9G   1% /raid0
/dev/md1p1      990M  2.6M  921M   1% /raid1


[root@ZQ ~]# cp /etc/passwd /raid1
[root@ZQ ~]# ls !$
ls /raid1
lost+found  passwd


模拟故障
raid1中sdc1故障,观察sdc3备用盘能否自动顶替故障盘
将sdc1指定为故障盘,cat/proc/mdstat 查看阵列状态
稍等片刻阵列重新重建成功,发现/sdc3【s】消失了,成功顶替
移除故障盘/sdc1
[root@ZQ ~]# mdadm -f /dev/md1 /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md1
[root@ZQ ~]# watch -n 1 cat /proc/mdstat 
[root@ZQ ~]# cat /proc/mdstat 
Personalities : [raid0] [raid1] 
md1 : active raid1 sdc3[2] sdc2[1] sdc1[0](F)
      1047552 blocks super 1.2 [2/2] [UU]
      
md0 : active raid0 sdb2[1] sdb1[0]
      2095104 blocks super 1.2 512k chunks
      
unused devices: <none>

[root@ZQ ~]# mdadm -r /dev/md1 /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md1
[root@ZQ ~]# cat /proc/mdstat 
Personalities : [raid0] [raid1] 
md1 : active raid1 sdc3[2] sdc2[1]
      1047552 blocks super 1.2 [2/2] [UU]
      
md0 : active raid0 sdb2[1] sdb1[0]
      2095104 blocks super 1.2 512k chunks
      
unused devices: <none>


[root@ZQ ~]# mdadm -Ds > /etc/mdadm.conf 
[root@ZQ ~]# cat /etc/mdadm.conf 
ARRAY /dev/md0 metadata=1.2 name=ZQ:0 UUID=00d9284f:6fd6b3b0:afc571c6:c5441608
ARRAY /dev/md1 metadata=1.2 name=ZQ:1 UUID=137b8247:e0ced5a2:625805ac:e9b31692
[root@ZQ ~]# 

 

posted @ 2017-06-03 22:58  rumenzq  阅读(1572)  评论(0编辑  收藏  举报