Article directory
mdadm introduction
Management software raid tool: mdadm
mdadm is a command used to create and manage software RAID under linux. It is a modal command
Parameters of the mdadm command
-C build a new array
-A activate disk array
-a add device to array
-D print array device details
-s scan configuration file or / proc/mdstat to get array missing information
-v display details
-r remove device
-f set the equipment status as failure
-l set the level of the disk array
-n specifies the members of the disk array (number of partitions / disks)
-x specifies the number of spares in the array
Actual combat raid 0
Two new hard disks
[root@centos7-xinsz08 ~]# ll /dev/sd* BRW RW ---- 1 root disk 8, 2 / 27 14:49 /dev/sda BRW RW ---- 1 root disk 8, 1 February 27 14:49 /dev/sda1 BRW RW ---- 1 root disk 8, February 27 14:49 /dev/sda2 BRW RW ---- 1 root disk 8, February 27, 2016 14:49 / dev / SDB BRW RW ---- 1 root disk 8, 32 February 27 14:49 /dev/sdc [root@centos7-xinsz08 ~]# fdisk /dev/sdc Welcome to fdisk (util Linux 2.23.2). Changes stay in memory until you decide to write them to disk. Think twice before using the write command. Device does not contain a recognized partition table Use disk identifier 0xb7cb3eac to create a new DOS disk label. Command (enter m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): Start sector (2048-41943039, default 2048): The default value 2048 will be used Last sector, + sector or +size{K,M,G} (2048-41943039, default is 41943039): + 5G Partition 1 is set to Linux type and size is set to 5 GiB Command (enter m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): Starting sector (10487808-41943039, default is 10487808): The default value 10487808 will be used Last sector, + sector or +size{K,M,G} (10487808-41943039, default is 41943039): + 5G Partition 2 is set to Linux type and size is set to 5 GiB Command (enter m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Synchronizing disks. [root@centos7-xinsz08 ~]# ll /dev/sd* BRW RW ---- 1 root disk 8, 2 / 27 14:49 /dev/sda BRW RW ---- 1 root disk 8, 1 February 27 14:49 /dev/sda1 BRW RW ---- 1 root disk 8, February 27 14:49 /dev/sda2 BRW RW ---- 1 root disk 8, February 27, 2016 14:49 / dev / SDB BRW RW ---- 1 root disk 8, 32 February 27 14:51 /dev/sdc BRW RW ---- 1 root disk 8, 33 February 27 14:51 /dev/sdc1 BRW RW ---- 1 root disk 8, 34 February 27 14:51 /dev/sdc2
Basic idea of RAID: combine several cheap hard disks into a new hard disk array group by certain combination way, so that it can meet the requirements of high performance hard disk
RAID has three key technologies:
Image: provides data security;
Stripe (block size can also be said to be stripe granularity), which exists to improve I/O performance and provide data concurrency
Data verification: provides data security
Create raid0
[root@centos7-xinsz08 ~]# rpm -qf `which mdadm` mdadm-4.1-1.el7.x86_64 //Establish [root@centos7-xinsz08 ~]# mdadm -C -v /dev/md0 -l 0 -n 2 /dev/sdc1 /dev/sdc2 mdadm: chunk size defaults to 512K mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. //See [root@centos7-xinsz08 ~]# mdadm -D mdadm: No devices given. [root@centos7-xinsz08 ~]# mdadm -Ds ARRAY /dev/md0 metadata=1.2 name=centos7-xinsz08:0 UUID=fa65ca42:f3f9d039:7ee6fad1:1e005f45 [root@centos7-xinsz08 ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Thu Feb 27 14:57:37 2020 Raid Level : raid0 Array Size : 10475520 (9.99 GiB 10.73 GB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Thu Feb 27 14:57:37 2020 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Chunk Size : 512K Consistency Policy : none Name : centos7-xinsz08:0 (local to host centos7-xinsz08) UUID : fa65ca42:f3f9d039:7ee6fad1:1e005f45 Events : 0 Number Major Minor RaidDevice State 0 8 33 0 active sync /dev/sdc1 1 8 34 1 active sync /dev/sdc2
Remarks:
chunk value:
The stripe size is divided into many "chunks". If the Chunk size is set too small, it will increase the number of blocks occupied
Save configuration information
[root@centos7-xinsz08 ~]# mdadm -Ds ARRAY /dev/md0 metadata=1.2 name=centos7-xinsz08:0 UUID=fa65ca42:f3f9d039:7ee6fad1:1e005f45 [root@centos7-xinsz08 ~]# mdadm -Ds > /etc/mdadm.conf [root@centos7-xinsz08 ~]# cat !$ cat /etc/mdadm.conf ARRAY /dev/md0 metadata=1.2 name=centos7-xinsz08:0 UUID=fa65ca42:f3f9d039:7ee6fad1:1e005f45 [root@centos7-xinsz08 ~]#
Create partition on raid 0
[root@centos7-xinsz08 ~]# fdisk /dev/md0 Welcome to fdisk (util Linux 2.23.2). Changes stay in memory until you decide to write them to disk. Think twice before using the write command. Device does not contain a recognized partition table Use disk identifier 0xa26b921f to create a new DOS disk label. Command (enter m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): 1 Start sector (2048-20951039, default 2048): The default value 2048 will be used Last sector, + sector or +size{K,M,G} (2048-20951039, default is 20951039): + 2G Partition 1 is set to Linux type and size is set to 2 GiB Command (enter m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Synchronizing disks. [root@centos7-xinsz08 ~]# ll /dev/md* BRW RW ---- 1 root disk 9, February 27, 0 15:17 / dev / md0 BRW RW ---- 1 root disk 259, January February 27 15:17 /dev/md0p1
Format partition and mount
[root@centos7-xinsz08 ~]# mkfs.xfs /dev/md0p1 meta-data=/dev/md0p1 isize=512 agcount=8, agsize=65408 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=523264, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@centos7-xinsz08 ~]# [root@centos7-xinsz08 ~]# mkdir /raid0 [root@centos7-xinsz08 ~]# mount /dev/md0p1 /raid0/ [root@centos7-xinsz08 ~]# df -h |tail -1 /dev/md0p1 2.0G 33M 2.0G 2% /raid0 [root@centos7-xinsz08 ~]#
Set up auto mount after power on
[root@centos7-xinsz08 ~]# umount /raid0/ [root@centos7-xinsz08 ~]# df -h |tail -1 tmpfs 378M 0 378M 0% /run/user/0 [root@centos7-xinsz08 ~]# mount -a [root@centos7-xinsz08 ~]# df -h //File system capacity used% free used% mount point devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 13M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 4.7G 13G 28% / /dev/sda1 1014M 219M 796M 22% /boot tmpfs 378M 12K 378M 1% /run/user/42 tmpfs 378M 0 378M 0% /run/user/0 [root@centos7-xinsz08 ~]# vim /etc/fstab /dev/md0p1 /raid0 xfs defaults 0 0 [root@centos7-xinsz08 ~]# mount -a [root@centos7-xinsz08 ~]# df -h //File system capacity used% free used% mount point /dev/md0p1 2.0G 33M 2.0G 2% /raid0