磁盘管理(四)

创建2G的RAID 1(添加两块磁盘,每隔2G)
方式:2个2G
实施过程:
[root@ns1 ~]# fdisk -l


Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c417f


  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          66      524288   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              66         327     2097152   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             327        2611    18349056   83  Linux


Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000




Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@ns1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xfe0e4259.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').


Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfe0e4259


  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  fd  Linux raid autodetect


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


Calling ioctl() to re-read partition table.
Syncing disks.
[root@ns1 ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7b1f71c6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').


Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7b1f71c6


  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         262     2104483+  fd  Linux raid autodetect


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


Calling ioctl() to re-read partition table.
Syncing disks.

[root@ns1 ~]# partprobe /dev/sd{b,c}
[root@ns1 ~]# cat /proc/partitions //确保分区可用
major minor  #blocks  name


  8        0   20971520 sda
  8        1     524288 sda1
  8        2    2097152 sda2
  8        3   18349056 sda3
  8       16    5242880 sdb
  8       17    2104483 sdb1
  8       32    5242880 sdc
  8       33    2104483 sdc1
[root@ns1 ~]# mdadm -C /dev/md1 -a yes -n 2 -l 1 /dev/sdb1 /dev/sdc1
[root@ns1 ~]# cat /proc/mdstat 
Personalities : [raid1] 
md1 : active raid1 sdc1[1] sdb1[0]
 2102400 blocks super 1.2 [2/2] [UU]
 
unused devices: <none>
注意:如果磁盘同步较慢,会在上述显示信息中看到同步过程
使用:
格式化:[root@ns1 ~]# mke2fs -j /dev/md1
[root@ns1 ~]# fdisk -l
[root@ns1 ~]# mount /dev/md1 /media/
[root@ns1 ~]# ls /media/
lost+found
注意:有时候在创建好md#编号,重启系统会发现编号变了,解决方法:
mdadm -Ds > /etc/mdadm.conf
init 6
验证:cat /proc/mdstat
测试:
[root@ns1 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
 Creation Time : Tue Apr 17 09:22:05 2018
Raid Level : raid1
Array Size : 2102400 (2.01 GiB 2.15 GB)
 Used Dev Size : 2102400 (2.01 GiB 2.15 GB)
  Raid Devices : 2
 Total Devices : 2
Persistence : Superblock is persistent


Update Time : Tue Apr 17 09:31:41 2018
 State : clean 
Active Devices : 2
Working Devices : 2
Failed Devices : 0
 Spare Devices : 0


  Name : ns1.zyg:1  (local to host ns1.zyg)
  UUID : 634fb747:4b185603:b096a1d6:88d4a208
Events : 17


Number   Major   Minor   RaidDevice State
  0       8       17        0      active sync   /dev/sdb1
  1       8       33        1      active sync   /dev/sdc1
[root@ns1 ~]# mdadm -f /dev/md1 /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md1
备注:摘除该分区,显示/dev/sdc1被模拟损坏
[root@ns1 ~]# cat /media/inittab
备注:显示能够正常访问
[root@ns1 ~]# mdadm -r /dev/md1 /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md1
备注:将损坏的磁盘删除
[root@ns1 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
 Creation Time : Tue Apr 17 09:22:05 2018
Raid Level : raid1
Array Size : 2102400 (2.01 GiB 2.15 GB)
 Used Dev Size : 2102400 (2.01 GiB 2.15 GB)
  Raid Devices : 2
 Total Devices : 1
Persistence : Superblock is persistent


Update Time : Tue Apr 17 09:40:34 2018
 State : clean, degraded 
Active Devices : 1
Working Devices : 1
Failed Devices : 0
 Spare Devices : 0


  Name : ns1.zyg:1  (local to host ns1.zyg)
  UUID : 634fb747:4b185603:b096a1d6:88d4a208
Events : 20


Number   Major   Minor   RaidDevice State
  0       8       17        0      active sync   /dev/sdb1
  2       0        0        2      removed
备注:再次查看/dev/sdc1没有了,表示移除
如何修复呢
[root@ns1 ~]# fdisk /dev/sdd
Command (m for help): n   
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p
Disk identifier: 0xa52d0b11


  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         262     2104483+  fd  Linux raid autodetect


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


Calling ioctl() to re-read partition table.
Syncing disks.

[root@ns1 ~]# mdadm -a /dev/md1 /dev/sdd1
[root@ns1 ~]# mdadm -D /dev/md1
[root@ns1 ~]# cat /proc/mdstat
这个过程中,如果数据比较大,同步时间会长一些,期间可以采用watch命令查看同步过程(打开另一个终端)
watch:周期性的执行制定命令,并以全屏方式显示结果
参数:-n #:指定周期长度,单位为秒,默认为2秒
格式:watch -n # 'COMMAND'
例:[root@ns1 ~]# watch -n 1 'cat /proc/mdstat'
备注:按Ctrl+C退出,如果不信,还可以再次模拟/dev/sdc1故障损坏(略)
停止RAID 1 阵列
[root@ns1 ~]# umount /media/
[root@ns1 ~]# mdadm --stop /dev/md1
显示结果:mdadm: stopped /dev/md1
[root@ns1 ~]# cat /proc/mdstat
[root@ns1 ~]# rm -rf /dev/md1 //这样就彻底删除了md1,视情况而定
重新装咋RAID 1阵列
[root@ns1 ~]# mdadm -A /dev/md1 /dev/sdb1 /dev/sdd1
显示结果:mdadm: /dev/md1 has been started with 2 drives.
[root@ns1 ~]# mdadm -D /dev/md1
[root@ns1 ~]# mdadm -D /dev/md1
备注:实际工作中很难记清每块磁盘,所有还有种很实用的办法
[root@ns1 ~]# mdadm -D --scan
ARRAY /dev/md0 metadata=1.2 name=ns1.zyg:1 UUID=634fb747:4b185603:b096a1d6:88d4a208
ARRAY /dev/md1 metadata=1.2 name=ns1.zyg:1 UUID=634fb747:4b185603:b096a1d6:88d4a208
[root@ns1 ~]# mdadm -D --scan > /etc/mdadm.conf
备注:将显示的磁盘内容定向到配置文件,当再次装载时就不用指定具体的磁盘了
[root@ns1 ~]# mdadm -S /dev/md1
mdadm: stopped /dev/md1
备注:停止RAID 1
[root@ns1 ~]# mdadm -A /dev/md1
显示结果:mdadm: /dev/md1 has been started with 2 drives.
备注:激活RAID 1



创建4G的RAID 5(3块磁盘,每个2G)
[root@ns1 ~]# fdisk -l
[root@ns1 ~]# fdisk /dev//sdb
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


Disk identifier: 0x404199b8


Device Boot      Start         End      Blocks   Id  System
/dev//sdb1               1         262     2104483+  fd  Linux raid autodetect


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


Calling ioctl() to re-read partition table.
Syncing disks.

[root@ns1 ~]# fdisk /dev/sdcCommand (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


Disk identifier: 0x57b88411


  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         262     2104483+  fd  Linux raid autodetect


Command (m for help): w

[root@ns1 ~]# fdisk /dev/sdd

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +2G


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


Disk identifier: 0xdf2a50f2


  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         262     2104483+  fd  Linux raid autodetect


Command (m for help): w

[root@ns1 ~]# partprobe /dev/sd{b,c,d}
[root@ns1 ~]# cat /proc/partitions 
major minor  #blocks  name


  8        0   20971520 sda
  8        1     524288 sda1
  8        2    2097152 sda2
  8        3   18349056 sda3
  8       16    5242880 sdb
  8       17    2104483 sdb1
  8       32    5242880 sdc
  8       33    2104483 sdc1
  8       48    5242880 sdd
  8       49    2104483 sdd1
备注:确保分区可用
[root@ns1 ~]# mdadm -C /dev/md2 -a yes -n 3 -l 5 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.
[root@ns1 ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md2 : active raid5 sdd1[3] sdc1[1] sdb1[0]
 4204544 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
 
unused devices: <none>
使用:
格式化:
[root@ns1 ~]# mke2fs -j -E stride=128 -b 4096 /dev/md2
显示md0的大小:
[root@ns1 ~]# fdisk -l
挂载验证:
[root@ns1 ~]# mount /dev/md2 /media/
[root@ns1 ~]# ls /media/
lost+found
优化:
[root@ns1 ~]# mdadm -D --scan
ARRAY /dev/md2 metadata=1.2 name=ns1.zyg:2 UUID=118d8abc:884af13b:23f8c848:4501e643
[root@ns1 ~]# mdadm -D --scan > /etc/mdadm.conf
[root@ns1 ~]# mdadm -a /dev/md2 /dev/sde1(备用)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值