兩塊30G硬碟做RAID1

來源:互聯網
上載者:User

標籤:網路

做這個實驗我們需要新添加兩塊30G的硬碟

[[email protected] ~]# uname -a


Linux ZZSRV1.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux


我們可以不用重啟就能顯示出磁碟

[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host1/scan

[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

查看磁碟

[[email protected] ~]# fdisk -l


Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0003747c


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048    83886079    41430016   8e  Linux LVM


Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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 /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 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


安裝mdadm

[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/

[[email protected] ~]# cd /mnt/cdrom/Packages/

[[email protected] Packages]# ls mdadm*

mdadm-3.2.6-31.el7.x86_64.rpm


[[email protected] Packages]# rpm -ivh mdadm-3.2.6-31.el7.x86_64.rpm

warning: mdadm-3.2.6-31.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Preparing...                          ################################# [100%]

        package mdadm-3.2.6-31.el7.x86_64 is already installed


給磁碟分割

[[email protected] Packages]# fdisk /dev/sdb

[[email protected] Packages]# fdisk /dev/sdc


建立RAID1卷

[[email protected] ~]# mdadm -Cv /dev/md0 -l1 -n2  /dev/sdc1 /dev/sdb1

mdadm: /dev/sdc1 appears to contain an ext2fs file system

    size=31456256K  mtime=Thu Jan  1 08:00:00 1970

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: /dev/sdb1 appears to contain an ext2fs file system

    size=31456256K  mtime=Thu Jan  1 08:00:00 1970

mdadm: size set to 31439744K

Continue creating array? (y/n) y

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.


[[email protected] ~]# cd /

[[email protected] /]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[1] sdc1[0]

      31439744 blocks super 1.2 [2/2] [UU]

      [========>............]  resync = 41.6% (13101184/31439744) finish=1.5min speed=199772K/sec


unused devices: <none>


格式化RAID卷

[[email protected] Packages]# mkfs.ext4 /dev/md0

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

1310720 inodes, 5238496 blocks

261924 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2153775104

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000


Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done



[[email protected] Packages]# mkdir /data

[[email protected] Packages]# mount /dev/md0 /data

[[email protected] Packages]# ll /data/

total 16

drwx------ 2 root root 16384 Aug 15 00:31 lost+found

[[email protected] Packages]# mdadm -Ds

ARRAY /dev/md0 metadata=1.2 name=ZZSRV1.localdomain:0 UUID=c2fe6a35:461511e9:7e9bf672:9baeb95c

[[email protected] Packages]# mdadm -Ds >> /etc/mdadm.conf



[[email protected] Packages]# vi /etc/fstab

在最後添加

/dev/md0        /data                              ext4        defaults    0 0


[[email protected] Packages]# mdadm -Ds

ARRAY /dev/md0 metadata=1.2 name=ZZSRV1.localdomain:0 UUID=c2fe6a35:461511e9:7e9bf672:9baeb95c

[[email protected] Packages]# mdadm -Ds >> /etc/mdadm.conf


[[email protected] Packages]# reboot

[[email protected] ~]# mount

/dev/mapper/VolGroup-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

/dev/md0 on /data type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


[[email protected] ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[0] sdc1[1]

      31438720 blocks super 1.2 [2/2] [UU]


unused devices: <none>


我們可以類比故障

將一塊30G的硬碟刪除

查看日誌會出現     需要等一會


sd 2:0:1:0: [sdb] Unhandled error code

sd 2:0:1:0: [sdb] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK

sd 2:0:1:0: [sdb] CDB: Write(10): 2a 00 00 00 00 47 00 00 01 00

md: super_written gets error=-5, uptodate=0

md/raid1:md0: Disk failure on sdb1, disabling device.

md/raid1:md0: Operation continuing on 1 devices.

RAID1 conf printout:

 --- wd:1 rd:2

 disk 0, wo:1, o:0, dev:sdb1

 disk 1, wo:0, o:1, dev:sdc1

RAID1 conf printout:

 --- wd:1 rd:2

 disk 1, wo:0, o:1, dev:sdc1

sd 2:0:1:0: [sdb] Unhandled error code

sd 2:0:1:0: [sdb] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK

sd 2:0:1:0: [sdb] CDB: Write(10): 2a 00 00 00 00 47 00 00 01 00

md: super_written gets error=-5, uptodate=0

md/raid1:md0: Disk failure on sdb1, disabling device.

md/raid1:md0: Operation continuing on 1 devices.



[[email protected] ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[0](F) sdc1[1]

      31438720 blocks super 1.2 [2/1] [_U]


unused devices: <none>


有了故障我們就需要重建RAID1

類比恢複,添加一塊新的30G硬碟


[[email protected] ~]# 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 / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x9b6ff607


   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    62914559    31456256   83  Linux 



線上加入新組成單元  



[[email protected] ~]# mdadm /dev/md0 -a /dev/sdb1

mdadm: added /dev/sdb1

[[email protected] ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[2] sdc1[1]

      31438720 blocks super 1.2 [2/1] [_U]

      [=>...................]  recovery =  7.0% (2201920/31438720) finish=2.4min speed=200174K/sec


unused devices: <none>


在日誌中我們可以看到重建過程

md: bind<sdb1>

md: recovery of RAID array md0

md: minimum _guaranteed_  speed: 1000 KB/sec/disk.

md: using maximum available idle IO bandwidth (but not more than 200000 KB/sec) for recovery.

md: using 128k window, over a total of 31438720k.

md: md0: recovery done.


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.