天天看點

linux下通過mdadm指令實作軟體RAID配置

linux下通過mdadm指令實作軟體RAID配置

1.配置yum源

2. yum install mdadm -y

3.man mdadm

mdadm常用模式:

Assemble:裝配模式,将原來屬于一個陣列的每個塊裝置組裝為陣列

Build:建立一個不需要中繼資料的陣列(超級塊),沒個裝置沒有中繼資料塊

Create:建立一個新的陣列,每個裝置都有超級塊

–create == -C 建立一個新的陣列

–level == -l 設定RAID組級别

–raid-devices == -n 設定裝置活動個數

–spare-devices == -x 設定備用盤的個數

–chunk == -c chunk預設64K

Monitor:監控模式,監控RAID狀态,可以實作全局熱備

–follow -F 選擇監控模式

–syslog == -y 事件日志記錄

–delay == -d 設定raid輪循,預設時間60s

–test == -t 生成警告資訊

Grow:修改陣列屬性(陣列磁盤個數,使用容量)

–grow == -G 修改陣列大小或裝置數量

–raid-devices == -n 活動裝置個數

–chunk == -c 設定CHUNK大小

–level == -l 設定等級

–name == -N 設定陣列名稱

Incremental Assembly:添加一個裝置帶陣列中

Misc:報告或者修改陣列中相關裝置資訊

–query-Q 查詢一個RAID或者RAID元件裝置資訊

–detail == -D 檢視RAID組詳細資訊

–stop==—S 停止RAID組

Auto-detect:要求在linux核心啟動時自動檢測陣列

#RAID0實作過程

1.進行軟體安裝安裝跟新:

yum install mdadm -y

2.準備倆塊raid0的成員盤并進行分區

fdisk /dev/sdb

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition ‘Linux’ to ‘Linux raid autodetect’

Command (m for help): p

		Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe2b54778

		   Device Boot      Start         End      Blocks   Id  System
		/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

		Command (m for help): w
		The partition table has been altered!


	fdisk /dev/sdc同上   
3.準備完磁盤後,檢查磁盤是否正确定義RAID
	[[email protected] ~]# mdadm --examine /dev/sd[b-c]
	/dev/sdb:
	   MBR Magic : aa55
	Partition[0] :     41940992 sectors at         2048 (type fd)
	/dev/sdc:
	   MBR Magic : aa55
	Partition[0] :     41940992 sectors at         2048 (type fd)
	[[email protected] ~]# mdadm --examine /dev/sd[b-c]1
	mdadm: No md superblock detected on /dev/sdb1.
	mdadm: No md superblock detected on /dev/sdc1.
	[[email protected] ~]# 
4.建立RAID0(/dev/md0)
	mdadm -C /dev/md0  -l raid0 -n 2 /dev/sd[b-c]1


	[[email protected] ~]# mdadm --create /dev/md0 --level=stripe --raid-devices=2 /dev/sd[bc]1
	mdadm: Defaulting to version 1.2 metadata
	mdadm: array /dev/md0 started.
	[[email protected] ~]# 

5.檢視RAID組狀态:
	[[email protected] ~]# cat /proc/mdstat 
	Personalities : [raid0] 
	md0 : active raid0 sdc1[1] sdb1[0]
	      41939968 blocks super 1.2 512k chunks
	      
	unused devices: <none>
	[[email protected] ~]# 
檢視RAID組級别:
	[[email protected] ~]# mdadm -E /dev/sd[bc]1

檢視RAID組裝置
	[[email protected] ~]# mdadm --detail /dev/md0

6.針對RAID組進行檔案系統建立
	[[email protected] ~]# mkfs -t ext4 /dev/md0 
7.建立挂載目錄并進行永久挂載
	[[email protected] ~]# mkdir /mnt/raid0
	[[email protected] ~]# mount /dev/md0 /mnt/raid0/
	[[email protected] ~]# df -hT

	永久挂載:
		[[email protected] ~]# vim /etc/fstab 
		[[email protected] ~]# cat /etc/fstab 

		#
		# /etc/fstab
		# Created by anaconda on Wed Jul  4 21:57:46 2018
		#
		# Accessible filesystems, by reference, are maintained under '/dev/disk'
		# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
		#
		/dev/mapper/rhel-root   /                       xfs     defaults        1 1
		UUID=cce16428-f4df-48c8-96a4-1e7e68e9343b /boot                   xfs     defaults        1 2
		/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
		/dev/md0	/mnt/raid0	ext4	defaults	0 0 
		[[email protected] ~]# mount -a
8.儲存RAID組配置:
	[[email protected] ~]# mdadm --detail --scan  --verbose >> /etc/mdadm.conf
	[[email protected] ~]# cat /etc/mdadm.conf 
	ARRAY /dev/md0 level=raid0 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=da3e0615:320a0e62:6115b620:3775dce4
	   devices=/dev/sdb1,/dev/sdc1
	[[email protected] ~]# 
9.使用RAID組:
	echo "這是一個RAID0陣列測試檔案" > /mnt/raid0/test.conf
           

繼續閱讀