操作添加硬盘添加两块硬盘,大小为30GB


使硬盘生效有两种方法:
1、重启:[root@ns2 ~]#reboot
2、输入以下命令
[root@ns2 ~]# echo "- - -">/sys/class/scsi_host/host0/scan
[root@ns2~]# echo "- - -" >/sys/class/scsi_host/host1/scan
[root@ns2~]# echo "- - -" >/sys/class/scsi_host/host2/scan
我们采用第二种
显示系统版本
[root@ns2~]# uname -a
Linux ns2.yyp.local 2.6.32-358.el6.x86_64#1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@ns2~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4(Santiago)

硬盘分区硬盘详情
[root@ns2~]# fdisk -l
. . . . . . . . . 
Disk /dev/sdb:32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
. . . . . . . . 
Disk /dev/sdc:32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000



磁盘分区并转换成磁盘阵列特有的格式
磁盘所有空间用完
[root@ns2~]# fdisk /dev/sdb
n  p   +29G  t   fd
/sdc上做类似的操作
[root@ns2~]# fdisk /dev/sdc
n  p   +29G  t   fd


查看磁盘格式
[root@ns2~]# fdisk -l /dev/sdb
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xe410bd9d


  Device Boot      Start         End      Blocks  Id  System
/dev/sdb1               1        3787   30419046   fd  Linux raid autodetect
[root@ns2 ~]# fdisk -l /dev/sdc
Disk /dev/sdc: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x50b24a29
Device Boot      Start         End      Blocks  Id  System
/dev/sdc1               1        3787   30419046   fd  Linux raid autodetect



建立RAID1[root@ns2~]# mdadm -C /dev/md0 -l 1 -n 2 /dev/sd[bc]1
mdadm: Note: this array has metadata at thestart 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.


在日志中可以看到相关的信息
[root@ns2~]# tail -f /var/log/messages



创建文件系统格式化该磁盘阵列
[root@ns2~]# mkfs.ext4 /dev/md0
新建挂载目录
[root@ns2~]# mkdir /data
挂载磁盘到新建的目录
[root@ns2~]# mount /dev/md0 /data
查看目录信息
[root@ns2~]# ll /data
total 16
drwx------ 2 root root 16384 Aug 15 03:54lost+found


将其设置为开机自动挂载
编辑
[root@ns2~]# vi /etc/fstab
添加以下内容
/dev/md0                /data                ext4        defaults       0 0


[root@ns2~]# mdadm -Ds
ARRAY /dev/md0 metadata=1.2name=ns2.yyp.local:0 UUID=000c6956:c552cc97:cdfff93c:167e3e72
写入到配置文件
[root@ns2~]# mdadm -Ds >> /etc/mdadm.conf


重新启动验证是否是自动挂载
[root@ns2 ~]# reboot



模拟故障删除一个硬盘


查看日志
在挂载目录写入东西,日志有变化



[root@ns2~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1](F) sdb1[0]
     30402560 blocks super 1.2 [2/1] [U_]


unused devices: <none>


RAID1重建模拟恢复,还是30GB的硬盘,添加新的磁盘



[root@ns2~]# fdisk -l /dev/sdb


Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xe410bd9d


  Device Boot      Start         End      Blocks  Id  System
/dev/sdb1               1        3787   30419046   fd  Linux raid autodetect


fdisk -l/dev/sdb


Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9b6ff607


   DeviceBoot      Start         End      Blocks  Id  System
/dev/sdb1               1        3916   31455238+  fd  Linux raid autodetect


添加的新磁盘需重复“硬盘分区”的操作


[root@ns2~]# mdadm /dev/md0 -a /dev/sdc1
mdadm: added /dev/sdc1
[root@ns2~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[2] sdb1[0]
     30402560 blocks super 1.2 [2/2] [UU]


unused devices: <none>
查看日志
md: bind<sdc1>
md:recovery of RAID array md0
md:minimum _guaranteed_  speed: 1000KB/sec/disk.
md:using maximum available idle IO bandwidth (but n
forrecovery.
md:using 128k window, over a total of 30402560k.
md:md0: recovery done.