使用mdadm工具實現軟RAID 0實戰案例
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
一.准備工作
1>.准備2塊磁盤
假設你剛剛從別的服務器下架了2塊磁盤設備(sdb和sdc)並安裝到了你新買的服務器,如下圖所示。
這個時候可能需要咱們手動刪除磁盤上的數據,當然,你也可以只刪除分區表,先在腦海里回憶一下如何操作,然后再繼續往下看。
2>.刪除sdb磁盤分區表
如果刪除分區表后使用"lsblk"命令查看並未同步的情況,可以參考我之前的筆記,我記錄了相關解決方案的筆記。
博主推薦閱讀:
https://www.cnblogs.com/yinzhengjie/p/12359248.html

[root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk ├─sdb1 8:17 0 100G 0 part ├─sdb2 8:18 0 200G 0 part ├─sdb3 8:19 0 1K 0 part ├─sdb5 8:21 0 100G 0 part └─sdb6 8:22 0 80G 0 part sdc 8:32 0 400G 0 disk ├─sdc1 8:33 0 100G 0 part └─sdc2 8:34 0 200G 0 part sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/dev/zero of=/dev/sdb bs=1 count=512 #只刪除磁盤的分區表信息 512+0 records in 512+0 records out 512 bytes (512 B) copied, 0.00103658 s, 494 kB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk sdc 8:32 0 400G 0 disk ├─sdc1 8:33 0 100G 0 part └─sdc2 8:34 0 200G 0 part sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]#
3>.以同樣的方式刪除sdc磁盤分區表

[root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk sdc 8:32 0 400G 0 disk ├─sdc1 8:33 0 100G 0 part └─sdc2 8:34 0 200G 0 part sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/dev/zero of=/dev/sdc bs=1 count=512 512+0 records in 512+0 records out 512 bytes (512 B) copied, 0.00135575 s, 378 kB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk sdc 8:32 0 400G 0 disk sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk sdc 8:32 0 400G 0 disk sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]#
4>.對sdb磁盤進行分區

[root@yinzhengjie.com ~]# fdisk /dev/sdb #使用"fdisk"工具對"/dev/sdb"磁盤進行分區 Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x8c3b1f6e. Command (m for help): P Disk /dev/sdb: 644.2 GB, 644245094400 bytes, 1258291200 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: 0x8c3b1f6e Device Boot Start End Blocks Id System Command (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): 1 First sector (2048-1258291199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-1258291199, default 1258291199): +100G Partition 1 of type Linux and of size 100 GiB is set Command (m for help): p #分區創建完畢后,查看一下當前的信息,注意觀察Id字段,我們需要配置RAID,因此需要修改它的值。 Disk /dev/sdb: 644.2 GB, 644245094400 bytes, 1258291200 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: 0x8c3b1f6e Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 83 Linux Command (m for help): t #使用"t"可以修改分區的Id,如果只有一個分區的話我們是無需選擇分區的,它會自動幫咱們選擇那個唯一的分區編號。 Selected partition 1 Hex code (type L to list all codes): L #使用"L"可以查看支持的Id編號 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): fd #此處我們將分區類型從83改為fd。 Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): p #再次查看分區信息,注意觀察"Id"列。 Disk /dev/sdb: 644.2 GB, 644245094400 bytes, 1258291200 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: 0x8c3b1f6e Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 fd Linux raid autodetect Command (m for help): w #需要注意的是,上面的所有操作都是在內存中完成的,要將內存的數據真正寫入磁盤,需要我們使用"w"選項喲~ The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# fdisk -l /dev/sdb Disk /dev/sdb: 644.2 GB, 644245094400 bytes, 1258291200 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: 0x8c3b1f6e Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 fd Linux raid autodetect [root@yinzhengjie.com ~]#
5>.對sdc磁盤進行分區

[root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk └─sdb1 8:17 0 100G 0 part sdc 8:32 0 400G 0 disk sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/dev/sdb of=/dev/sdc bs=1 count=512 #此處我偷懶,直接將sdb磁盤的分區表同步到sdc磁盤上啦~(這樣可以免得手動去重復上面的操作來一步步手動分區。) 512+0 records in 512+0 records out 512 bytes (512 B) copied, 0.00171811 s, 298 kB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2T 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot ├─sda3 8:3 0 2T 0 part │ ├─centos-root 253:0 0 500G 0 lvm / │ └─centos-yinzhengjie 253:1 0 1.5T 0 lvm /yinzhengjie └─sda4 8:4 0 1M 0 part sdb 8:16 0 600G 0 disk └─sdb1 8:17 0 100G 0 part sdc 8:32 0 400G 0 disk └─sdc1 8:33 0 100G 0 part sdd 8:48 0 800G 0 disk sde 8:64 0 1000G 0 disk sr0 11:0 1 918M 0 rom [root@yinzhengjie.com ~]#

[root@yinzhengjie.com ~]# fdisk -l /dev/sdc Disk /dev/sdc: 429.5 GB, 429496729600 bytes, 838860800 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: 0x8c3b1f6e Device Boot Start End Blocks Id System /dev/sdc1 2048 209717247 104857600 fd Linux raid autodetect [root@yinzhengjie.com ~]#
二.創建RAID 0塊設備實戰案例
1>.安裝mdadm工具(用於創建RAID磁盤)

[root@yinzhengjie.com ~]# yum -y install mdadm Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 4.5 kB 00:00:00 * base: mirrors.bfsu.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.huaweicloud.com * updates: mirror.bit.edu.cn base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/6): extras/7/x86_64/primary_db | 206 kB 00:00:00 (2/6): epel/x86_64/group_gz | 95 kB 00:00:00 (3/6): docker-ce-stable/x86_64/primary_db | 45 kB 00:00:00 (4/6): updates/7/x86_64/primary_db | 3.8 MB 00:00:00 (5/6): epel/x86_64/updateinfo | 1.0 MB 00:00:23 epel/x86_64/primary_db FAILED https://download.nus.edu.sg/mirror/epel/7/x86_64/repodata/c91de4e9f4240b1b26a52668116b16495413e7f52c600294e89772ce3be7b6a8-primary.sqlite.bz2: [Errno 12] Timeout on https://download.nus.edu .sg/mirror/epel/7/x86_64/repodata/c91de4e9f4240b1b26a52668116b16495413e7f52c600294e89772ce3be7b6a8-primary.sqlite.bz2: (28, 'Operation timed out after 30000 milliseconds with 0 out of 0 bytes received')Trying other mirror. (6/6): epel/x86_64/primary_db | 6.9 MB 00:00:01 Resolving Dependencies --> Running transaction check ---> Package mdadm.x86_64 0:4.1-4.el7 will be installed --> Processing Dependency: libreport-filesystem for package: mdadm-4.1-4.el7.x86_64 --> Running transaction check ---> Package libreport-filesystem.x86_64 0:2.1.11-53.el7.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================= Installing: mdadm x86_64 4.1-4.el7 base 439 k Installing for dependencies: libreport-filesystem x86_64 2.1.11-53.el7.centos base 41 k Transaction Summary ============================================================================================================================================================================================= Install 1 Package (+1 Dependent package) Total download size: 479 k Installed size: 1.0 M Downloading packages: (1/2): libreport-filesystem-2.1.11-53.el7.centos.x86_64.rpm | 41 kB 00:00:00 (2/2): mdadm-4.1-4.el7.x86_64.rpm | 439 kB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 2.4 MB/s | 479 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libreport-filesystem-2.1.11-53.el7.centos.x86_64 1/2 Installing : mdadm-4.1-4.el7.x86_64 2/2 Verifying : mdadm-4.1-4.el7.x86_64 1/2 Verifying : libreport-filesystem-2.1.11-53.el7.centos.x86_64 2/2 Installed: mdadm.x86_64 0:4.1-4.el7 Dependency Installed: libreport-filesystem.x86_64 0:2.1.11-53.el7.centos Complete! [root@yinzhengjie.com ~]#
2>.使用mdadm工具創建一個RAID0的塊設備

[root@yinzhengjie.com ~]# mdadm --help mdadm is used for building, managing, and monitoring Linux md devices (aka RAID arrays) Usage: mdadm --create device options... Create a new array from unused devices. mdadm --assemble device options... Assemble a previously created array. mdadm --build device options... Create or assemble an array without metadata. mdadm --manage device options... make changes to an existing array. mdadm --misc options... devices report on or modify various md related devices. mdadm --grow options device resize/reshape an active array mdadm --incremental device add/remove a device to/from an array as appropriate mdadm --monitor options... Monitor one or more array for significant changes. mdadm device options... Shorthand for --manage. Any parameter that does not start with '-' is treated as a device name or, for --examine-bitmap, a file name. The first such name is often the name of an md device. Subsequent names are often names of component devices. For detailed help on the above major modes use --help after the mode e.g. mdadm --assemble --help For general help on options use mdadm --help-options [root@yinzhengjie.com ~]#
[root@yinzhengjie.com ~]# lsblk /dev/sd{b,c} #注意哈,我本次試驗會用到sdb和sdc這兩塊磁盤 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 600G 0 disk └─sdb1 8:17 0 100G 0 part sdc 8:32 0 400G 0 disk └─sdc1 8:33 0 100G 0 part [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# ll /dev/md* #目前"/dev/"目錄下沒有任何以"md*"開頭的文件,一會執行命令后你就會發現存在啦~ ls: cannot access /dev/md*: No such file or directory [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# cat /proc/mdstat #觀察md的狀態 Personalities : unused devices: <none> [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# mdadm -C -a yes /dev/md001 -l 0 -n 2 /dev/sd{b,c}1 #將sdb1和sdc1分區RAID0級別,使用"-n"指定設備個數,使用"-l"指定RAID級別,使用"-C -a yes"表示初始化創建的意思。 mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md001 started. mdadm: timeout waiting for /dev/md001 [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# cat /proc/mdstat #觀察md的狀態 Personalities : [raid0] md1 : active raid0 sdc1[1] sdb1[0] 209582080 blocks super 1.2 512k chunks unused devices: <none> [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# ll /dev/md* #我們會發現多了一個塊設備,但沒有以我定義的"/dev/md001"來命名! brw-rw---- 1 root disk 9, 1 Aug 21 01:50 /dev/md1 [root@yinzhengjie.com ~]#
3>.使用mdadm命令查看RAID設備的詳細信息
[root@yinzhengjie.com ~]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Fri Aug 21 01:50:32 2020 Raid Level : raid0 #RAID級別是"raid 0" Array Size : 209582080 (199.87 GiB 214.61 GB) #這里的總容量是200G左右 Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Fri Aug 21 01:50:32 2020 State : clean #目前狀態是"clean", Active Devices : 2 #活動設備是2個 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Chunk Size : 512K #組塊大小是512K Consistency Policy : none Name : yinzhengjie.com:001 (local to host yinzhengjie.com) UUID : e7e1a4a7:f73b2990:a52b16b3:92be0561 #注意觀察這個UUID哈,下面也會用到 Events : 0 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 33 1 active sync /dev/sdc1 [root@yinzhengjie.com ~]#
4>.為RAID設備創建文件系統
[root@yinzhengjie.com ~]# mkfs.xfs /dev/md1 #我們將RAID 0設備格式化文件系統類型為XFS。 meta-data=/dev/md1 isize=512 agcount=16, agsize=3274624 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=52393984, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=25584, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# blkid /dev/sd{b,c}1 #查看sdb1和sdc1分區都用一個統一的UUID,和上面的RAID設備的UUID完全相同。但這2個分區也有各自獨立的UUID編號,當然,類型均為"linux_raid_member" /dev/sdb1: UUID="e7e1a4a7-f73b-2990-a52b-16b392be0561" UUID_SUB="595fb659-a792-aaac-3a2d-800b3e0795ac" LABEL="yinzhengjie.com:001" TYPE="linux_raid_member" /dev/sdc1: UUID="e7e1a4a7-f73b-2990-a52b-16b392be0561" UUID_SUB="78244c8b-f961-577f-9d32-af6c474e9f2b" LABEL="yinzhengjie.com:001" TYPE="linux_raid_member" [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# blkid /dev/md1 #我們也可以看到RAID 0設備(/dev/sdb1)的文件系統類型為XFS。 /dev/md1: UUID="bc7d4ffa-439e-4544-b59e-58d10228569c" TYPE="xfs" [root@yinzhengjie.com ~]#
5>.掛載RAID設備
[root@yinzhengjie.com ~]# mkdir -pv /yinzhengjie/raid #創建掛載點 mkdir: created directory ‘/yinzhengjie/raid’ [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# tail -1 /etc/fstab #你可以使用"mount"命令手動掛載,但我推薦大家寫在配置文件中,這樣重啟服務器時會自動幫咱們掛載的. UUID=bc7d4ffa-439e-4544-b59e-58d10228569c /yinzhengjie/raid xfs defaults,noatime,nodiratime 0 0 [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# mount -a #我們使用該命令可以幫咱們實現自動掛載 [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 500G 14G 486G 3% / devtmpfs 2.0G 0 2.0G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 2.0G 12M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sda2 1014M 133M 882M 14% /boot /dev/mapper/centos-yinzhengjie 1.6T 1.4G 1.6T 1% /yinzhengjie tmpfs 394M 0 394M 0% /run/user/0 /dev/md1 200G 33M 200G 1% /yinzhengjie/raid [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]#
6>.測試RAID 0設備的寫入速度

[root@yinzhengjie.com ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 500G 14G 486G 3% / devtmpfs 2.0G 0 2.0G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 2.0G 12M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sda2 1014M 133M 882M 14% /boot /dev/mapper/centos-yinzhengjie 1.6T 1.4G 1.6T 1% /yinzhengjie tmpfs 394M 0 394M 0% /run/user/0 /dev/md1 200G 33M 200G 1% /yinzhengjie/raid [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/dev/zero of=/yinzhengjie/raid/test.log bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 4.57999 s, 234 MB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/dev/zero of=/yinzhengjie/test2.log bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 9.90687 s, 108 MB/s [root@yinzhengjie.com ~]#
7>.測試RAID 0設備的讀取速度

[root@yinzhengjie.com ~]# free -h total used free shared buff/cache available Mem: 3.8G 254M 3.3G 11M 297M 3.3G Swap: 0B 0B 0B [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/yinzhengjie/test2.log of=/dev/null 2097152+0 records in 2097152+0 records out 1073741824 bytes (1.1 GB) copied, 3.84986 s, 279 MB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# free -h total used free shared buff/cache available Mem: 3.8G 257M 2.3G 11M 1.3G 3.3G Swap: 0B 0B 0B [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# sync; echo 1 > /proc/sys/vm/drop_caches [root@yinzhengjie.com ~]# sync; echo 2 > /proc/sys/vm/drop_caches [root@yinzhengjie.com ~]# sync; echo 3 > /proc/sys/vm/drop_caches [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# free -h total used free shared buff/cache available Mem: 3.8G 252M 3.5G 11M 141M 3.4G Swap: 0B 0B 0B [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# dd if=/yinzhengjie/raid/test.log of=/dev/null 2097152+0 records in 2097152+0 records out 1073741824 bytes (1.1 GB) copied, 2.79886 s, 384 MB/s [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]# free -h total used free shared buff/cache available Mem: 3.8G 252M 2.5G 11M 1.1G 3.3G Swap: 0B 0B 0B [root@yinzhengjie.com ~]# [root@yinzhengjie.com ~]#
8>.重啟服務器后再次查看掛載情況(編輯"/etc/fstab"文件后,雖說可以使用"mount -a"命令使之立即生效,但生產環境務必要重啟服務器進行測試喲)
[root@yinzhengjie.com ~]# lsblk /dev/sd{b,c} #此處我們只看磁盤/dev/sdb和/dev/sdc這兩塊設備信息。 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 600G 0 disk └─sdb1 8:17 0 100G 0 part └─md1 9:1 0 199.9G 0 raid0 /yinzhengjie/raid sdc 8:32 0 400G 0 disk └─sdc1 8:33 0 100G 0 part └─md1 9:1 0 199.9G 0 raid0 /yinzhengjie/raid [root@yinzhengjie.com ~]#