linux 软件组建raid1加raid0配置方案

作者: admin 分类: linux 发布时间: 2018-04-30 13:30

  配置软件RAID1+0

  N(偶数,N>=4)块盘两两镜像后,在组合成一个RAID 0 。容量为N/2,N/2块盘同时写入,写速度一般,N快盘同时读取,读速度较快。性能高,可靠性高。

  在虚拟机中,新增四块20G的新硬盘,将其配置为软件RAID 1

配置RAID 1+0图
配置RAID 1+0图

  第一步:将四块硬盘分别分区,全部大小都分为一个分区,并改为id为"fd"

  [root@localhost ~]# fdisk /dev/sdd

  在这里就不演示硬盘分区,fdisk新硬盘分区方法

  第二步:创建RAID1,命名为“md1”

  [root@localhost ~]# fdisk -l /dev/sd* | grep "fd" #查询硬盘信息

  /dev/sdb1 1 2610 20964793+ fd Linux raid autodetect

  /dev/sdc2 1 2610 20964793+ fd Linux raid autodetect

  /dev/sdd3 1 2610 20964793+ fd Linux raid autodetect

  /dev/sde4 1 2610 20964793+ fd Linux raid autodetect

  [root@localhost ~]# mdadm -Cv /dev/md1 -l 1 -n 2 /dev/sdd1 /dev/sdc2

  mdadm: Note: this array has metadata at the start and

  may not be suitable as a boot device. If you plan to

  store '/boot' on this device please ensure that

  your boot-loader understands md/v1.x metadata, or use

  --metadata=0.90

  Continue creating array? mdadm -D /dev/md1

  Continue creating array? (y/n) y

  mdadm: Defaulting to version 1.2 metadata

  mdadm: array /dev/md1 started.

  [root@localhost ~]# mdadm -D /dev/md1

  /dev/md1:

  Version : 1.2

  Creation Time : Sun Apr 29 11:50:33 2018

  Raid Level : raid1

  Array Size : 20948288 (19.98 GiB 21.45 GB)

  Used Dev Size : 20948288 (19.98 GiB 21.45 GB)

  Raid Devices : 2

  Total Devices : 2

  Persistence : Superblock is persistent

  Update Time : Sun Apr 29 11:52:18 2018

  State : clean

  Active Devices : 2

  Working Devices : 2

  Failed Devices : 0

  Spare Devices : 0

  Name : localhost.localdomain:1 (local to host localhost.localdomain)

  UUID : 467bb227:5e8c3ac8:293f4d4b:0e920a62

  Events : 17

  Number Major Minor RaidDevice State

  0 8 17 0 active sync /dev/sdb1

  1 8 34 1 active sync /dev/sdc2

  [root@localhost ~]# mdadm -Cv /dev/md2 -l 1 -n 2 /dev/sdd3 /dev/sde4mdadm: Note: this array has metadata at the start and

  may not be suitable as a boot device. If you plan to

  store '/boot' on this device please ensure that

  your boot-loader understands md/v1.x metadata, or use

  --metadata=0.90

  mdadm: size set to 20948288K

  Continue creating array?

  Continue creating array? (y/n) y

  mdadm: Defaulting to version 1.2 metadata

  mdadm: array /dev/md2 started.

  第三步:两个RAID 1都创建完成,现在把两个RAID 1 分区

  [root@localhost ~]# fdisk /dev/md1

  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  Building a new DOS disklabel with disk identifier 0x9b8896de.

  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): n

  Command action

  e extended

  p primary partition (1-4)

  p

  Partition number (1-4): 1

  First cylinder (1-5237072, default 1):

  Using default value 1

  Last cylinder, +cylinders or +size{K,M,G} (1-5237072, default 5237072):

  Using default value 5237072

  Command (m for help): p

  Disk /dev/md1: 21.5 GB, 21451046912 bytes

  2 heads, 4 sectors/track, 5237072 cylinders

  Units = cylinders of 8 * 512 = 4096 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0x9b8896de

  Device Boot Start End Blocks Id System

  /dev/md1p1 1 5237072 20948286 83 Linux

  Command (m for help): w

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  [root@localhost ~]# fdisk /dev/md2

  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  Building a new DOS disklabel with disk identifier 0x9b8896de.

  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): n

  Command action

  e extended

  p primary partition (1-4)

  p

  Partition number (1-4): 1

  First cylinder (1-5237072, default 1):

  Using default value 1

  Last cylinder, +cylinders or +size{K,M,G} (1-5237072, default 5237072):

  Using default value 5237072

  Command (m for help): p

  Disk /dev/md2: 21.5 GB, 21451046912 bytes

  2 heads, 4 sectors/track, 5237072 cylinders

  Units = cylinders of 8 * 512 = 4096 bytes

  Sector size (logical/physical): 512 bytes / 512 bytes

  I/O size (minimum/optimal): 512 bytes / 512 bytes

  Disk identifier: 0x9b8896de

  Device Boot Start End Blocks Id System

  /dev/md2p1 1 5237072 20948286 83 Linux

  Command (m for help): w

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  第四步:格式化,挂载于/fangjia目录下,并设置为开机自动挂载

  [root@localhost ~]# mkfs.ext4 /dev/md0

  mke2fs 1.41.12 (17-May-2010)

  文件系统标签=

  操作系统:Linux

  块大小=4096 (log=2)

  分块大小=4096 (log=2)

  Stride=128 blocks, Stripe width=256 blocks

  2621440 inodes, 10473984 blocks

  523699 blocks (5.00%) reserved for the super user

  第一个数据块=0

  Maximum filesystem blocks=4294967296

  320 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,

  4096000, 7962624

  正在写入inode表: 完成

  Creating journal (32768 blocks):

  完成

  Writing superblocks and filesystem accounting information: 完成

  This filesystem will be automatically checked every 29 mounts or

  180 days, whichever comes first. Use tune2fs -c or -i to override.

  [root@localhost ~]# mkdir /fangjia

  [root@localhost ~]# mount /dev/md0 /fangjia

  [root@localhost ~]# df -hT

  Filesystem     Type   Size  Used Avail Use% Mounted on
    /dev/sda3      ext4    12G  3.5G  7.8G  31% /
    tmpfs          tmpfs 1004M   72K 1004M   1% /dev/shm
    /dev/sda1      ext4   194M   34M  151M  19% /boot
    /dev/md0       ext4    40G  176M   38G   1% /fangjia

  [root@localhost ~]# vi /etc/fstab


#
# /etc/fstab
# Created by anaconda on Wed Apr 18 03:02:29 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
#
UUID=e7adfeb9-8749-48cd-90cd-61de56c9af74 /                       ext4    defaults        1 1
UUID=3dc81669-b5c6-4dbc-94ae-8ccc08e1c57a /boot                   ext4    defaults        1 2
UUID=0b5d32c6-fd5f-4bdb-bcb8-9ee7fe90b2ce swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/md0                /fangjia                ext4    defaults        0 0

    第五步:手动创建RAID配置文件 /etc/mdadm.conf

  [root@localhost ~]# mdadm -D -s > /etc/mdadm.conf

  [root@localhost ~]# vim /etc/mdadm.conf

  ARRAY /dev/md1 metadata=1.2 name=localhost.localdomain:1 UUID=467bb227:5e8c3ac8:293f4d4b:0e920a62 auto=yes

  ARRAY /dev/md2 metadata=1.2 name=localhost.localdomain:2 UUID=9821cd05:48d4207c:c616492a:fe3ca548 auto=yes

  ARRAY /dev/md0 metadata=1.2 name=localhost.localdomain:0 UUID=07b2453a:b89f01ab:fa025cb0:0cf39cfb auto=yes

更多

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!