首頁 > 運維 > linux運維 > mdadm指令詳解

mdadm指令詳解

藏色散人
發布: 2020-02-20 09:45:51
原創
10750 人瀏覽過

mdadm指令詳解

mdadm指令詳解

mdadm指令詳解及實驗過程

線上學習影片分享:linux影片教學課程

一.概念

        mdadm是multiple devices admin的簡稱,它是Linux下的一款標準的軟體RAID 管理工具,作者是Neil Brown

#二.特點

        mdadm能夠診斷、監控和收集詳細的陣列資訊 

        mdadm是一個單獨整合化的程式而非一些分散程序的集合,因此對不同RAID管理指令有共通點的語法 

        mdadm能夠執行幾乎所有的功能而不需要配置文件(也沒有默認的配置文件)

三.作用(引用)        

             

##         目前以MD(Multiple Devices)虛擬塊設備的方式實現軟體RAID,利用多個底層的區塊設備虛擬出一個新的虛擬設備,並且利用條帶化(stripping)技術將資料塊均勻分佈到多個磁碟上來提高虛擬設備的讀寫性能,利用不同的資料冗餘演算法來保護用戶資料不會因為某個塊設備的故障而完全丟失,而且還能在設備被替換後將丟失的數據恢復到新的設備上.

        目前MD支援linear,multipath,raid0(stripping),raid1(mirror),raid4,raid5,raid6,raid10等不同的冗餘層級和層級方式,當然也能支援多個RAID陳列的層疊組成raid1 0,raid5 1等類型的陳列

四.實驗

    試題:建立4個大小為1G的磁盤,並將其中3個創建為raid5的陣列磁盤, 1個為熱備份磁碟。測試熱備份磁碟替換陣列中的磁碟並同步資料。移除損壞的磁碟,新增一個新磁碟作為熱備份磁碟。最後要求開機自動掛載。

4.1建立磁碟

 [root@xiao ~]# fdisk /dev/sda
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
First cylinder (10486-13054, default 10486): 
Using default value 10486
Last cylinder, +cylinders or +size{K,M,G} (10486-13054, default 13054): +1G
Command (m for help): n
First cylinder (10618-13054, default 10618): 
Using default value 10618
Last cylinder, +cylinders or +size{K,M,G} (10618-13054, default 13054): +1G
Command (m for help): n
First cylinder (10750-13054, default 10750): 
Using default value 10750
Last cylinder, +cylinders or +size{K,M,G} (10750-13054, default 13054): +1G
Command (m for help): n
First cylinder (10882-13054, default 10882): 
Using default value 10882
Last cylinder, +cylinders or +size{K,M,G} (10882-13054, default 13054): +1G
Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): fd
Changed system type of partition 8 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-8): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-8): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-8): 5  
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)
Command (m for help): p 
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0008ed57
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26       10225    81920000   83  Linux
/dev/sda3           10225       10486     2097152   82  Linux swap / Solaris
/dev/sda4           10486       13054    20633279    5  Extended
/dev/sda5           10486       10617     1058045   fd  Linux raid autodetect
/dev/sda6           10618       10749     1060258+  fd  Linux raid autodetect
/dev/sda7           10750       10881     1060258+  fd  Linux raid autodetect
/dev/sda8           10882       11013     1060258+  fd  Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
登入後複製

4.2載入核心

[root@xiao ~]# partx -a /dev/sda5 /dev/sda

[ root@xiao ~]# partx -a /dev/sda6 /dev/sda

#[root@xiao ~]# partx -a /dev/sda7 /dev/sda

[root@ xiao ~]# partx -a /dev/sda8 /dev/sda

4.3建立raid5及其熱備份磁碟

[root@xiao ~]# mdadm -C /dev/md0 -l 5 -n 3 -x 1   /dev/sda{5,6,7,8}
mdadm: /dev/sda5 appears to be part of a raid array:
    level=raid5 devices=3 ctime=Wed Dec 17 00:58:24 2014
mdadm: /dev/sda6 appears to be part of a raid array:
    level=raid5 devices=3 ctime=Wed Dec 17 00:58:24 2014
mdadm: /dev/sda7 appears to be part of a raid array:
    level=raid5 devices=3 ctime=Wed Dec 17 00:58:24 2014
mdadm: /dev/sda8 appears to be part of a raid array:
    level=raid5 devices=3 ctime=Wed Dec 17 00:58:24 2014
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
登入後複製

4.4初始化時間和磁碟陣列的讀寫的應用相關,使用cat /proc/mdstat資訊查詢RAID陣列目前重構的速度和預期的完成時間。

[root@xiao ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4] 
md0 : active raid5 sda7[4] sda8[3](S) sda6[1] sda5[0]
      2113536 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [=========>...........]  recovery = 45.5% (482048/1056768) finish=0.3min speed=30128K/sec
      
unused devices: <none>
[root@xiao ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4] 
md0 : active raid5 sda7[4] sda8[3](S) sda6[1] sda5[0]
      2113536 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      
unused devices: <none>
 [root@xiao ~]# mke2fs -t ext3 /dev/md0        //格式化raid
登入後複製

4.5掛載raid到/mnt目錄下,並查看是否正常(顯示lost found為正常)

[root@xiao ~]# mount /dev/md0 /mnt
[root@xiao ~]# ls /mnt
lost+found
登入後複製

 

4.6查看raid陣列的詳細資訊

[root@xiao ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Dec 17 03:38:08 2014
     Raid Level : raid5
     Array Size : 2113536 (2.02 GiB 2.16 GB)
  Used Dev Size : 1056768 (1032.17 MiB 1082.13 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent
    Update Time : Wed Dec 17 03:55:11 2014
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 512K
           Name : xiao:0  (local to host xiao)
           UUID : bce110f2:34f3fbf1:8de472ed:633a374f
         Events : 18
    Number   Major   Minor   RaidDevice State
       0       8        5        0      active sync   /dev/sda5
       1       8        6        1      active sync   /dev/sda6
       4       8        7        2      active sync   /dev/sda7
       3       8        8        -      spare   /dev/sda8
登入後複製

4.7模擬損壞其中的一個磁盤,這裡我選擇 /dev/sda6磁碟

[root@xiao ~]# mdadm /dev/md0 --fail /dev/sda6
mdadm: set /dev/sda6 faulty in /dev/md0
登入後複製

4.7查看raid陣列詳細信息,發現/dev/sda8自動替換了損壞的/dev/sda6磁碟。

[root@xiao ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Dec 17 03:38:08 2014
     Raid Level : raid5
     Array Size : 2113536 (2.02 GiB 2.16 GB)
  Used Dev Size : 1056768 (1032.17 MiB 1082.13 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent
    Update Time : Wed Dec 17 04:13:59 2014
          State : clean, degraded, recovering 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 512K
 Rebuild Status : 43% complete
           Name : xiao:0  (local to host xiao)
           UUID : bce110f2:34f3fbf1:8de472ed:633a374f
         Events : 26
    Number   Major   Minor   RaidDevice State
       0       8        5        0      active sync   /dev/sda5
       3       8        8        1      spare rebuilding   /dev/sda8
       4       8        7        2      active sync   /dev/sda7
       1       8        6        -      faulty   /dev/sda6
[root@xiao ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4] 
md0 : active raid5 sda7[4] sda8[3] sda6[1](F) sda5[0]
登入後複製

      2113536 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]   #正常的情況會是[UUU],第一個磁碟損壞則顯示[ _UUUUUUC ].

##4.8 移除損壞的硬碟

[root@xiao ~]# mdadm /dev/md0 -r /dev/sda6
mdadm: hot removed /dev/sda6 from /dev/md0
登入後複製

4.9新增一個新硬碟作為熱備份磁碟

[root@xiao ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It&#39;s strongly recommended to
         switch off the mode (command &#39;c&#39;) and change display units to
         sectors (command &#39;u&#39;).
Command (m for help): n
First cylinder (11014-13054, default 11014): 
Using default value 11014
Last cylinder, +cylinders or +size{K,M,G} (11014-13054, default 13054): +1G
Command (m for help): t
Partition number (1-9): 9
Hex code (type L to list codes): fd
Changed system type of partition 9 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0008ed57
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26       10225    81920000   83  Linux
/dev/sda3           10225       10486     2097152   82  Linux swap / Solaris
/dev/sda4           10486       13054    20633279    5  Extended
/dev/sda5           10486       10617     1058045   fd  Linux raid autodetect
/dev/sda6           10618       10749     1060258+  fd  Linux raid autodetect
/dev/sda7           10750       10881     1060258+  fd  Linux raid autodetect
/dev/sda8           10882       11013     1060258+  fd  Linux raid autodetect
/dev/sda9           11014       11145     1060258+  fd  Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@xiao ~]# partx -a /dev/sda9 /dev/sda
[root@xiao ~]# mdadm /dev/md0 --add /dev/sda9
mdadm: added /dev/sda9
 
[root@xiao ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Dec 17 03:38:08 2014
     Raid Level : raid5
     Array Size : 2113536 (2.02 GiB 2.16 GB)
  Used Dev Size : 1056768 (1032.17 MiB 1082.13 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent
    Update Time : Wed Dec 17 04:39:35 2014
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 512K
           Name : xiao:0  (local to host xiao)
           UUID : bce110f2:34f3fbf1:8de472ed:633a374f
         Events : 41
    Number   Major   Minor   RaidDevice State
       0       8        5        0      active sync   /dev/sda5
       3       8        8        1      active sync   /dev/sda8
       4       8        7        2      active sync   /dev/sda7
       5       8        9        -      spare   /dev/sda9
登入後複製

5.開機自動掛載

#編輯/etc/ fsab檔案

/dev/md0  /mnt   ext3 defaults 0 0

:wq

 

#6.mdadm中文man(引用)

基本語法: mdadm [mode] [options]

[mode] 有7種:

Assemble:將先前定義的某個陣列加入目前在用陣列。

Build:Build a legacy array ,每個device 沒有superblocks

Create:建立一個新的陣列,每個device 具有superblocks

Manage: 管理陣列,例如add或remove

Misc:允許單獨對陣列中的某個device 做操作,例如抹去superblocks 或終止在用的陣列。

Follow or Monitor:監控raid 1,4,5,6 和multipath 的狀態

Grow:改變raid 容量或陣列中的device 數目

可用的[options ]:

-A, --assemble:加入一個先前定義的陣列

-B, --build:Build a legacy array without superblocks.

#-C, --create:建立一個新的陣列

-Q, --query:查看一個device,判斷它為一個md device 或是一個md 陣列的一部分

#-D, -- detail:列印一個或多個md device 的詳細資訊

-E, --examine:列印device 上的md superblock 的內容

-F, --follow, --monitor:選擇Monitor 模式

-G, --grow:改變在用陣列的大小或形態

-h, --help:幫助訊息,用在以上選項後,則顯示該選項訊息

--help-options

-V, --version

#-v, --verbose:顯示細節

#-b, -- brief:較少的細節。用於--detail 和--examine 選項

-f, --force

-c, --config= :指定設定文件,缺省為/etc/mdadm/mdadm. conf

-s, --scan:掃描設定檔或/proc/mdstat以搜尋遺失的資訊。設定檔/etc/mdadm/mdadm.conf

create 或build 使用的選項:

-c, --chunk=:Specify chunk size of kibibytes. 預設為64.

--rounding=: Specify rounding factor for linear array (==chunk size)

-l, --level=:設定raid level.

#--create可用: linear, raid0, 0, stripe, raid1,1, mirror, raid4, 4, raid5, 5, raid6, 6, multipath, mp.

--build可用:linear, raid0, 0, stripe.

-p, --parity=:設定raid5 的奇偶校驗規則:eft-asymmetric, left-symmetric, right-asymmetric, right-symmetric, la, ra, ls, rs.缺省為left -symmetric

--layout=:類似於--parity

-n, --raid-devices=:指定陣列中可用device 數目,這個數目只能由--grow 修改

-x, --spare-devices=:指定初始陣列的富餘device 數目

-z, --size=:組成RAID1/4/5/6後從每個device取得的空間總數

--assume-clean:目前僅用於--build 選項

#-R, --run:陣列中的某一部分出現在其他陣列或檔案系統中時,mdadm會確認該陣列。此選項將不作確認。

-f, --force:通常mdadm不允許只用一個device 建立陣列,而且在建立raid5時會使用一個device作為missing drive。此選項正相反。

-a, --auto{=no,yes,md,mdp,part,p}{NN}:

更多程式相關內容,請關注php中文網程式設計入門欄位!

以上是mdadm指令詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板