现状:共有2块硬盘当做数据盘,一块 500G(sda), 另一块 2T(sdb)
要实现的:sda 和 sdb 其中的 500G 组成 raid1, sdb 剩下的当做普通数据盘,并且当 raid 出现问题的时候,发送邮件通知你
使用 sudo fdisk /dev/sdx 命令进行分区,按照提示操作就可以了
分区之后情况如下
- Disk /dev/sda: 500.1 GB, 500107862016 bytes
- 45 heads, 63 sectors/track, 344540 cylinders, total 976773168 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 identifier: 0x3184df24
-
- Device Boot Start End Blocks Id System
- /dev/sda1 2048 976773167 488385560 83 Linux
-
- Disk /dev/sdb: 2000.4 GB, 2000365289472 bytes
- 255 heads, 63 sectors/track, 243197 cylinders, total 3906963456 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 identifier: 0xe0894113
-
- Device Boot Start End Blocks Id System
- /dev/sdb1 2048 976773167 488385560 83 Linux
- /dev/sdb2 976773168 3906963455 1465095144 83 Linux
-
下面开始将 sda1 和 sdb1 组建成 raid1
- $ sudo fdisk /dev/sda
-
- 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): w
- The partition table has been altered!
-
修改好之后分区情况如下
- Disk /dev/sda: 500.1 GB, 500107862016 bytes
- 45 heads, 63 sectors/track, 344540 cylinders, total 976773168 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 identifier: 0x3184df24
-
- Device Boot Start End Blocks Id System
- /dev/sda1 2048 976773167 488385560 fd Linux raid autodetect
-
- Disk /dev/sdb: 2000.4 GB, 2000365289472 bytes
- 255 heads, 63 sectors/track, 243197 cylinders, total 3906963456 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 identifier: 0xe0894113
-
- Device Boot Start End Blocks Id System
- /dev/sdb1 2048 976773167 488385560 fd Linux raid autodetect
- /dev/sdb2 976773168 3906963455 1465095144 83 Linux
-
- sudo apt-get install mdadm
-
- sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
-
出现 “mdadm: array /dev/md0 started.”, 就算成功了
看似创建好了,实际上还没有,还在后台进行同步,同步完成之后才算彻底完工,但是现在就可以正常使用了
- Personalities : [raid1]
- md0 : active raid1 sdb1[1] sda1[0]
- 488254336 blocks super 1.2 [2/2] [UU]
- [>....................] resync = 0.1% (942528/488254336) finish=469.6min speed=17292K/sec
-
- unused devices: <none>
-
可用 sudo mdadm --detail /dev/md0 命令查看磁盘阵列 md0 的详细信息- sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
-
- sudo mkfs.ext4 /dev/md0
-
- /dev/md0 /media/data ext4 defaults 0 0
-
磁盘阵列出现问题的时候,发送邮件通知你
好心发给你可别忽略了,要不然你会付出代价的
- sudo apt-get install ssmtp
-
- #
- # Config file for sSMTP sendmail
- #
- # The person who gets all mail for userids < 1000
- # Make this empty to disable rewriting.
- root=postmaster
-
- # The place where the mail goes. The actual machine name is required no-
- # MX records are consulted. Commonly mailhosts are named mail.domain.com
- mailhub=smtp.gmail.com:587
-
- # Where will the mail seem to come from?
- #rewriteDomain=
-
- # The full hostname
- hostname=YourHostname
-
- # Are users allowed to set their own From: address?
- # YES - Allow the user to specify their own From: address
- # NO - Use the system generated From: address
- FromLineOverride=YES
- UseSTARTTLS=YES
- UseTLS=YES
- AuthUser=YourUsername@gmail.com
- AuthPass=YourPassword
-
- sudo chmod 660 /etc/ssmtp/ssmtp.conf
-
- echo "ssmtp-test" | sudo ssmtp mwum@dreamxu.com
-
- # 填写你自己的邮箱
- MAILADDR mwum@dreamxu.com
- MAILFROM YourUsername@gmail.com
-
- sudo mdadm --monitor /dev/md0 --test
-
到这,你就可以安心睡觉了
删除需谨慎,都是满满的数据
- sudo mdadm --stop /dev/md0
-
- sudo mdadm --zero-superblock /dev/sda1
- sudo mdadm --zero-superblock /dev/sdb1
-
对一些情况进行处理
- $ cat /proc/mdstat
-
- Personalities : [raid1]
- md0 : active raid1 sdb1[1] sda1[0](F)
- 488254336 blocks super 1.2 [2/1] [_U]
-
- unused devices: <none>
-
- sudo mdadm /dev/md0 --remove /dev/sda1
-
- sudo mdadm /dev/md0 --add /dev/sda1
-
- sudo mdadm /dev/md0 --fail /dev/sdb1
-
- Disk /dev/sdd: 500.1 GB, 500107862016 bytes
- 45 heads, 63 sectors/track, 344540 cylinders, total 976773168 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 identifier: 0x3184df24
-
- Device Boot Start End Blocks Id System
- /dev/sdd1 2048 976773167 488385560 fd Linux raid autodetect
-
- Disk /dev/md127: 500.0 GB, 499972440064 bytes
- 2 heads, 4 sectors/track, 122063584 cylinders, total 976508672 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 identifier: 0x00000000
-
- Disk /dev/md127 doesn't contain a valid partition table
-
- Disk /dev/sde: 2000.4 GB, 2000365289472 bytes
- 255 heads, 63 sectors/track, 243197 cylinders, total 3906963456 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 identifier: 0xe0894113
-
- Device Boot Start End Blocks Id System
- /dev/sde1 2048 976773167 488385560 fd Linux raid autodetect
- /dev/sde2 976773168 3906963455 1465095144 83 Linux
-
- sudo mdadm --stop /dev/md127
-
然后执行这个命令,如果没有自动重组,那么直接执行这个命令即可
- sudo mdadm --assemble /dev/md0 /dev/sdd1 /dev/sde1
-
- sudo mdadm --create --verbose /dev/md0 --level=1 --force --raid-devices=1 /dev/sde1
-
- sudo mount /dev/md0 /mnt