RHEL6.5 部署RAID1

# uname -a
Linux hs105.localdomain2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64GNU/Linux
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4(Santiago)

使用rpm 安裝mdadm

[root@hs105 ~]# mount /dev/cdrom/mnt/cdrom/
mount: block device /dev/sr0 iswrite-protected, mounting read-only
[root@hs105 ~]# cd /mnt/cdrom/Packages/
[root@hs105 Packages]# rpm -ivhmdadm-3.2.5-4.el6.x86_64.rpm
Preparing...               ########################################### [100%]
       package mdadm-3.2.5-4.el6.x86_64 is already installed

查看安裝文件

 

[root@hs105 Packages]# rpm -qa mdadm
mdadm-3.2.5-4.el6.x86_64
[root@hs105 Packages]# rpm -qc mdadm
/etc/cron.d/raid-check
/etc/sysconfig/raid-check

 

格式化硬盤

 

[root@hs105 Packages]# fdisk /dev/sdb
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xe4366023.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon't be recoverable.
 
Warning: invalid flag 0x0000 of partitiontable 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): d
No partition is defined yet!
 
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-3916, default 3916):
Using default value 3916
 
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!
 
Calling ioctl() to re-read partition table.
Syncing disks.

 

創建RAID1

 

[root@hs105 Packages]#  mdadm -Cv /dev/md0 -l1 -n2  /dev/sdc /dev/sdb
mdadm: /dev/sdc appears to contain anext2fs file system
   size=31457280K  mtime=Thu Aug 1414:57:50 2014
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
mdadm: /dev/sdb appears to contain anext2fs file system
   size=31457280K  mtime=Thu Aug 1414:44:05 2014
mdadm: /dev/sdb appears to be part of araid array:
   level=raid0 devices=0 ctime=Thu Jan 1 08:00:00 1970
mdadm: partition table exists on /dev/sdbbut will be lost or
      meaningless after creating array
mdadm: size set to 31440768K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@hs105 Packages]# cd /
[root@hs105 /]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb[1] sdc[0]
     31440768 blocks super 1.2 [2/2] [UU]
     [===>.................]  resync= 16.4% (5166208/31440768) finish=2.1min speed=206648K/sec
unused devices: <none>

 

 

格式化    RAID

[root@hs105 /]# mkfs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7860192 blocks
393009 blocks (5.00%) reserved for thesuper user
First data block=0
Maximum filesystem blocks=4294967296
240 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
       4096000
 
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystemaccounting information: done
 
This filesystem will be automaticallychecked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

RAID卷掛載到 /DATA 目錄下

[root@hs105 /]# mount /dev/md0 /DATA

 

 

將文件寫入DATA

[root@hs105 /]#cd DATA
[root@hs105 DATA]# ll
total 16
drwx------. 2 root root 16384 Aug 14 15:06lost+found
[root@hs105 DATA]# touch 123.txt
[root@hs105 DATA]# touch 456.txt
[root@hs105 DATA]# touch 789.txt
[root@hs105 DATA]# vi 123.txt
[root@hs105 DATA]# cat 123.txt
12345678asfghrtyjuk
T

 

模擬磁盤壞掉

wKioL1PskrWxoIs8AABNtBJicqc409.jpg

wKiom1PskZ2S532wAAFO-pryqWI255.jpg

wKioL1PskraAgvQ8AAFOpqb-ZVE190.jpg

wKiom1PskZ2Q3sxcAAEDtrtR2vw285.jpg



可以看到此時連接虛擬機的的磁盤只有兩個

wKioL1PskrbT5KhdAAE5nmakoV8232.jpg


進入虛擬機

查看/DATA 目錄

 

 

發現原文件依然存在


wKiom1PskZ7gEZORAAYBanxzCBk422.jpg


查看系統日誌

[root@hs105 DATA]# tail -f/var/log/messages
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] CDB: Read(10): 28 00 03 bf ff f8 00 00 0                             8 00
Aug 14 15:19:15 hs105 kernel: Buffer I/Oerror on device sdb, logical block 7864319
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] Unhandled error code
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] Result: hostbyte=DID_NO_CONNECT driverby                             te=DRIVER_OK
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] CDB: Read(10): 28 00 03 bf ff f8 00 00 0                             8 00
Aug 14 15:19:15 hs105 kernel: Buffer I/O erroron device sdb, logical block 7864319
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] Unhandled error code
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] Result: hostbyte=DID_NO_CONNECT driverby                             te=DRIVER_OK
Aug 14 15:19:15 hs105 kernel: sd 2:0:1:0:[sdb] CDB: Read(10): 28 00 00 00 00 00 00 00 0                             8 00
Aug 14 15:19:15 hs105 kernel: Buffer I/Oerror on device sdb, logical block 0


接下來進行RAID1的Rebuild


wKiom1PskZ7yFSpqAAJEnF7UXpU128.jpg

wKioL1Pskreh2vA4AAMa6PTICss355.jpg

wKioL1Pskrew-uA6AABaN61ZyWk103.jpg


查看raid卷狀態

wKiom1PskZ_wkuEeAAaVteD15Fs558.jpg


[root@hs105 ~]# cat /proc/mdstat
Personalities : [raid1]
md127 : active (auto-read-only) raid1sdb[1]
     31440768 blocks super 1.2 [2/1] [_U]
 
unused devices: <none>

發現/dev/md0 自動更名爲md127

md127上存在sdb

於是我們將sdc格式化

格式化操作參考之前的格式化RAID部分

接下來sdc掛載到md127裏面

 

[root@hs105 DATA]# mdadm /dev/md127 -a/dev/sdc
mdadm: added /dev/sdc
 
查看raid卷狀態
[root@hs105 DATA]# cat
/proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdb[2] sdc[1]
     
31438720 blocks super 1.2 [2/1] [_U]
     
[=>...................] 
recovery =  7.0%
(2201920/31438720) finish=2.4min speed=200174K/sec
 
unused devices: <none>

 

查看/DATA

 

[root@hs105 DATA]# cd /DATA
[root@hs105 DATA]# ll
total 4
-rw-r--r--. 1 root root 23 Aug 14 15:48123.txt
-rw-r--r--. 1 root root  0 Aug 14 15:47 456.txt
-rw-r--r--. 1 root root  0 Aug 14 15:47 789.txt


wKioL1PskrqC9PIvAABBqb5X34E374.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章