Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285746
  • 博文数量: 22
  • 博客积分: 2929
  • 博客等级: 上尉
  • 技术积分: 774
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-24 12:00
文章分类

全部博文(22)

文章存档

2013年(1)

2012年(2)

2011年(6)

2010年(11)

2009年(2)

分类: LINUX

2011-05-23 08:31:48

接上篇,我们已经创建好了raid卷组和lvm卷组,现在我们模拟磁盘损坏的情况
模拟一个磁盘损坏
[root@test ~]# mdadm /dev/md0 -f /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md0

移除磁盘:
[root@test ~]# mdadm /dev/md0 -r /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md0

检查md状态:
[root@test ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd1[4] sdb1[0] sde1[3]
      4190208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]unused devices:

重新添加sdc1:
[root@test ~]# mdadm /dev/md0 -a /dev/sdc1
mdadm: re-added /dev/sdc1

检查md状态:
[root@test ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdc1[1](S) sdd1[4] sdb1[0] sde1[3]
      4190208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]unused devices:
此时,卷组原来的spare盘sde1加入到使用中磁盘,sdc1成为spare磁盘,磁盘损坏及修复模拟完成.
 
下面实验raid卷组扩容及lvm扩容:
 
大家应该还记得,我虚拟机添加了5个2G的硬盘,现在sdf还没使用呢,我们来加入sdf到卷组中.
先添加/dev/sdf1:
[root@test ~]# mdadm /dev/md0 -a /dev/sdf1
mdadm: added /dev/sdf1

此时有两个spare:

[root@test ~]# mdadm -D -s /dev/md0

/dev/md0:
        Version : 1.2
  Creation Time : Thu May 19 20:55:31 2011
     Raid Level : raid5
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
   Raid Devices : 3
  Total Devices : 5
    Persistence : Superblock is persistent    Update Time : Thu May 19 21:27:12 2011
          State : clean
Active Devices : 3
Working Devices : 5
Failed Devices : 0
  Spare Devices : 2         Layout : left-symmetric
     Chunk Size : 512K           Name : test:0  (local to host test)
           UUID : 628587c6:e00ecd89:62b64fe6:2c88ac63
         Events : 42    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       3       8       65        1      active sync   /dev/sde1
       4       8       49        2      active sync   /dev/sdd1

       1       8       33        -      spare   /dev/sdc1
       5       8       81        -      spare   /dev/sdf1


扩容:
  mdadm --grow /dev/md0 --raid-disks=4
mdadm: Need to backup 3072K of critical section..

再次检查raid卷:
[root@test ~]# mdadm -D -s /dev/md0
/dev/md127:
        Version : 1.2
  Creation Time : Thu May 19 20:55:31 2011
     Raid Level : raid5
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
   Raid Devices : 4
  Total Devices : 5
    Persistence : Superblock is persistent    Update Time : Thu May 19 21:29:45 2011
          State : clean, recovering
Active Devices : 4
Working Devices : 5
Failed Devices : 0
  Spare Devices : 1         Layout : left-symmetric
     Chunk Size : 512K Reshape Status : 56% complete
  Delta Devices : 1, (3->4)           Name : test:0  (local to host test)
           UUID : 628587c6:e00ecd89:62b64fe6:2c88ac63
         Events : 65    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       3       8       65        1      active sync   /dev/sde1
       4       8       49        2      active sync   /dev/sdd1
       5       8       81        3      active sync   /dev/sdf1       1       8       33        -      spare   /dev/sdc1

只剩下一个spare磁盘.
此时,lv还是4G大小.
扩展pv空间:

[root@test ~]# pvresize /dev/md0

  Physical volume "/dev/md0" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized


再次查看pv:
[root@test ~]# pvdisplay /dev/md0
  --- Physical volume ---
  PV Name               /dev/md0
  VG Name               testvg
  PV Size               5.99 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              1534
  Free PE               512
  Allocated PE          1022
  PV UUID               eyudnw-heK0-Oce2-OYwz-qqZx-rZWh-00jBVN

扩展lv:
[root@test ~]#  lvextend /dev/testvg/lvol0 -l +512
  Extending logical volume lvol0 to 5.99 GiB
  Logical volume lvol0 successfully resized

检查结果:
[root@test ~]# vgdisplay
  --- Volume group ---
  VG Name               testvg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               5.99 GiB
  PE Size               4.00 MiB
  Total PE              1534
  Alloc PE / Size       1534 / 5.99 GiB
  Free  PE / Size       0 / 0
  VG UUID               ShZwhx-qZ3J-GQMQ-FgRs-CnK3-hOzX-3SJMON

扩展分区:
[root@test ~]# resize2fs /dev/testvg/lvol0
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/testvg/lvol0' first.

根据提示先执行e2fsck -f /dev/testvg/lvol0
[root@test ~]# e2fsck -f /dev/testvg/lvol0
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/lvol0: 11/261632 files (0.0% non-contiguous), 34862/1046528 blocks

再次执行resize2fs
[root@test ~]# resize2fs /dev/testvg/lvol0
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/testvg/lvol0 to 1570816 (4k) blocks.
The filesystem on /dev/testvg/lvol0 is now 1570816 blocks long.

重新挂载,df -h检查下:
[root@test ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             7.9G  1.8G  5.7G  24% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/mapper/testvg-lvol0
                      5.9G   72M  5.6G   2% /data
磁盘扩容成功.
 
实验完成,我们实现了raid5卷组有一个hotspare磁盘,并且在上面做了lvm,同时实验了扩容了raid卷和lvm卷.
 
阅读(5652) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

yonghengxinyuan2015-07-16 10:17:24

分享无私 ,好文,大赞一个