Centos 创建软Raid +扩容

Centos 创建软Raid

系统:Centos 7

硬盘:4块

/dev/sdb

/dev/sdc

/dev/sdd

/dev/sde

1、先进行硬盘初始化

[root@localhost ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9874ecda.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 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): p

Disk /dev/sdd: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x9874ecda

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 
Value out of range.
Partition number (1-4): 
Value out of range.
Partition number (1-4): 1
First cylinder (1-652, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 
Using default value 652

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

Calling ioctl() to re-read partition table.
Syncing disks.

2、四块磁盘进行Raid 5

mdadm -v -C /dev/md5 -l 5 -n 3 -x 1  -c32 /dev/sd{b,c,d,e}

参数解释:
-C:创建设备
-l:RAID级别 
-n:磁盘个数
-a:自动创建设备文件

[root@localhost ~]# mdadm -v -C /dev/md5 -l 5 -n 3 -x 1  -c32 /dev/sd{b,c,d,e}
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: /dev/sdb appears to be part of a raid array:
    level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sdb but will be lost or
       meaningless after creating array
mdadm: /dev/sdc appears to be part of a raid array:
    level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sdc but will be lost or
       meaningless after creating array
mdadm: /dev/sdd appears to be part of a raid array:
    level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sdd but will be lost or
       meaningless after creating array
mdadm: /dev/sde appears to be part of a raid array:
    level=raid0 devices=0 ctime=Wed Dec 31 16:00:00 1969
mdadm: partition table exists on /dev/sde but will be lost or
       meaningless after creating array
mdadm: size set to 5238752K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]# mdadm -D /dev/md5 
/dev/md5:
        Version : 1.2
  Creation Time : Wed Feb 10 02:26:51 2021
     Raid Level : raid5
     Array Size : 10477504 (9.99 GiB 10.73 GB)
  Used Dev Size : 5238752 (5.00 GiB 5.36 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Feb 10 02:27:16 2021
          State : clean, degraded, recovering 
 Active Devices : 2
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 2

         Layout : left-symmetric
     Chunk Size : 32K

 Rebuild Status : 95% complete                #######正在创建

           Name : localhost.localdomain:5  (local to host localhost.localdomain)
           UUID : 7ff84f85:fcaa1154:ec868782:c3485533
         Events : 16

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      spare rebuilding   /dev/sdd

       3       8       64        -      spare   /dev/sde

 

[root@localhost ~]# mdadm -D /dev/md5 
/dev/md5:
        Version : 1.2
  Creation Time : Wed Feb 10 02:26:51 2021
     Raid Level : raid5
     Array Size : 10477504 (9.99 GiB 10.73 GB)
  Used Dev Size : 5238752 (5.00 GiB 5.36 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Feb 10 02:27:17 2021
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 32K

           Name : localhost.localdomain:5  (local to host localhost.localdomain)
           UUID : 7ff84f85:fcaa1154:ec868782:c3485533
         Events : 20

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      active sync   /dev/sdd

       3       8       64        -      spare   /dev/sde

查看raid情况

 

[root@localhost raid5]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdb[0] sde[3] sdd[4] sdc[1]
      15716256 blocks super 1.2 level 5, 32k chunk, algorithm 2 [4/4] [UUUU]
      
unused devices: <none>
[root@localhost raid5]# 

3、更新Raid配置 

mdadm -Dsv > /etc/mdadm.conf   //更新配置文件

4、格式化Raid盘

先查看一下Raid盘情况

​
Disk /dev/md5: 10.7 GB, 10728964096 bytes       #####好像有点小,四块5G的盘为啥只有10.7G?
2 heads, 4 sectors/track, 2619376 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 32768 bytes / 65536 bytes
Disk identifier: 0x00000000

​

初始化Raid 盘

[root@localhost usr]# mkfs.ext4 /dev/md5 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=8 blocks, Stripe width=16 blocks
655360 inodes, 2619376 blocks
130968 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

5、挂载硬盘

 

创建 /usr/raid5/ 

挂载 mount /dev/md5  /usr/raid5/ 

查看

[root@localhost raid5]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        18G  2.4G   15G  15% /
tmpfs           491M   72K  491M   1% /dev/shm
/dev/sda1       291M   34M  242M  13% /boot
/dev/md5        9.9G  151M  9.2G   2% /usr/raid5
[root@localhost raid5]# 

至此,阵列已经完成,并正常使用。

 二、向当前阵列内添加新盘

1、向当前阵列内添加新盘(需要文件备份)

限制:

1、磁盘类型一致,

2、大小一致,

3、格式化设置一致。

 

格式化硬盘

将硬盘添加到当前阵列

[root@localhost raid5]# mdadm /dev/md5 -a /dev/sdf  ###新加硬盘
mdadm: added /dev/sdf
[root@localhost raid5]# 

 查看阵列状态

mdadm -D /dev/md5
/dev/md5:
        Version : 1.2
  Creation Time : Wed Feb 10 02:26:51 2021
     Raid Level : raid5
     Array Size : 15716256 (14.99 GiB 16.09 GB)
  Used Dev Size : 5238752 (5.00 GiB 5.36 GB)
   Raid Devices : 4
  Total Devices : 5
    Persistence : Superblock is persistent

    Update Time : Wed Feb 10 03:13:23 2021
          State : clean 
 Active Devices : 4
Working Devices : 5
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 32K

           Name : localhost.localdomain:5  (local to host localhost.localdomain)
           UUID : 7ff84f85:fcaa1154:ec868782:c3485533
         Events : 60

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      active sync   /dev/sdd
       3       8       64        3      active sync   /dev/sde

       5       8       80        -      spare   /dev/sdf
[root@localhost raid5]# 

2、重新初始化raid盘,把新盘初始化,这一步不做新盘依然不可用。

先取消挂载,然后初始化

[root@localhost ~]# 
[root@localhost ~]# mkfs.ext4 /dev/md5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=8 blocks, Stripe width=16 blocks
983040 inodes, 3929064 blocks
196453 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# 
[root@localhost ~]# 

 再次查看硬盘状态

Disk /dev/md5: 16.1 GB, 16093446144 bytes
2 heads, 4 sectors/track, 3929064 cylinders, total 31432512 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 32768 bytes / 65536 bytes
Disk identifier: 0x00000000

[root@localhost ~]# 

挂载即可。

 

上一篇:Python pandas.DataFrame.as_blocks和as_matrix函数方法的使用


下一篇:Oracle的高水位线