LINUX 创建RAID5 和 LVM 逻辑卷

LINUX 制作 RAID5卷和LVM逻辑卷

环境搭建

虚拟机装有linux操作系统.

     windows物理机上有SecurCRT或者putty等和linux操作系统远程连接的软件。

 

首先查看linuxip地址,连接SecurCRT输入linux上的ip地址、root用户名和密码来进行远程连接

 

如下图

 

安装mdadm软件包

 

创建RAID卷需要用的命令mdadm,就要先安装好mdadm软件包

 

创建挂载点/mnt/cdrom/

 

使用mount将光盘挂载到/mnt/cdrom/目录下,进入目录/mnt/cdrom/Packages/

 

查看mdadm安装包

 

[root@localhost ~]# mkdir /mnt/cdrom

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom

mount: /dev/sr0 is write-protected,mounting read-only

[root@localhost ~]# cd /mnt/cdrom

[root@localhost cdrom]# cd Packages/

[root@localhost Packages]# ls mdadm*

mdadm-3.2.6-31.el7.x86_64.rpm

 

使用rpm或者yum来安装

[root@localhostPackages]# rpm -Uvhmdadm-3.2.6-31.el7.x86_64.rpm

warning:mdadm-3.2.6-31.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5:NOKEY

Preparing...                         ################################# [100%]

        package mdadm-3.2.6-31.el7.x86_64 isalready installed

RAID5

 

使用命令fdisk –l来查看硬盘情况

 

[root@localhost ~]# fdisk -l

 

Disk /dev/sda: 42.9 GB, 42949672960 bytes,83886080 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0x000ca5cb

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *        2048     1026047      512000  83  Linux

/dev/sda2         1026048    83886079   41430016   8e  Linux LVM

 

Disk /dev/mapper/centos-swap: 1107 MB,1107296256 bytes, 2162688 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

 

 

Disk /dev/mapper/centos-root: 41.3 GB,41313894400 bytes, 80691200 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

添加硬盘

增加3块硬盘,因为构建RAID5卷至少需要3块硬盘



 

为了方面分辨,我给3块硬盘分别分为20GB 21GB22GB

 


方法一   :使用reboot命令重启,LINUX才能识别到新添加的3块硬盘

 

[root@localhost ~]# reboot

 

方法二   :使用命令对linux系统的磁盘进行扫描,就能识别到新添加的3块硬盘

 

[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host1/scan

[root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

 

 

再用fdisk –l查看系统中的所有磁盘信息,就发现有3块新添加的磁盘,没有分区。

 

 

 

…………………..

……………………

………………….

Disk /dev/sdb: 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 / 512bytes

 

 

Disk /dev/sdc: 22.5 GB, 22548578304 bytes,44040192 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

 

 

Disk /dev/sdd: 23.6 GB, 23622320128 bytes,46137344 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

 

创建分区

创建分区,分别将新添加的每块硬盘都规划一个分区

 

首先进入/dev/sdb/

 

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

 

 

使用字母l可以查看更改分区类型

 

Command (m for help): l


 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


 

将分区更改为fdRAID卷),不是RAID5卷,RAID卷有几种类型。这里并没有格式化硬盘。

 

Command (m for help): t

Selected partition 1

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

Changed type of partition ‘Linux‘ to ‘Linuxraid autodetect‘

 

Command (m for help): p   查看

 

Disk /dev/sdb: 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 / 512bytes

Disk label type: dos

Disk identifier: 0xd6c74515

 

  Device Boot      Start        End      Blocks   Id System

/dev/sdb1            2048    41943039   20970496   fd  Linux raid autodetect

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

 

 

分别规划、/dev/sdc/   /dev/sdd/

步骤同/dev/sdb/一样

 

 

 

 

 

创建RAID5

 

-C -----create:指的是创建一个新的阵列

 

-l level= : 设定raid level 这里为RAID5

 

-n , 指定阵列中可用device数目,这里为3,表示3块硬盘

 

Sd[bcd]1, 整个意思为sdb1 , sdc1,sdd1 表示3个分区

 

使用命令创建RAID5

 

 

[root@localhost ~]# mdadm -C /dev/md5 -l5 -n3 /dev/sd[bcd]1

mdadm: largest drive (/dev/sdd1) exceedssize (20953600K) by more than 1%

Continue creating array? y

mdadm: Defaulting to version 1.2 metadata

mdadm:array /dev/md5 started

 

 

创建PV物理卷,将/dev/md5转化成物理卷

 

[root@localhost ~]# pvcreate /dev/md5

  Physicalvolume "/dev/md5" successfully created

 

创建VG卷组,将/dev/md5创建为卷组,名字为mail_stor

 

[root@localhost~]# vgcreate mail_ste/dev/md5

^H  Volume group "mail_ste"successfully created

 

[root@localhost~]# vgdisplay

  --- Volume group ---

  VG Name               mail_ste

  System ID            

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  1

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                0

  Open LV               0

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               39.96 GiB

  PE Size               4.00 MiB

  Total PE              10231

  Alloc PE / Size       0 / 0  

  Free PE / Size       10231 / 39.96 GiB

  VG UUID              6vCcS8-Hsm8-eet4-WKZ6-qw2b-0bIB-FmRWB3

 

 

LVM

 

创建LV逻辑卷,在卷组mail_ste中创建一个名为mail的逻辑卷,容量大小为39GB

注意这里的容量大小不能有小数点,所以只能提取39GB

 

 

[root@localhost ~]# lvcreate -L 39G -n mail  mail_ste

 Logical volume "mail" created

 

格式化mail的逻辑卷,文件系统为ext4

 

[root@localhost ~]# mkfs -t ext4/dev/mail_ste/mail

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=128 blocks, Stripe width=256 blocks

2555904 inodes, 10223616 blocks

511180 blocks (5.00%) reserved for thesuper user

First data block=0

Maximum filesystem blocks=2157969408

312 block groups

32768 blocks per group, 32768 fragments pergroup

8192 inodes per group

Superblock backups stored on blocks:

       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

       4096000, 7962624

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystemaccounting information: done

 

 

最后在根目录下创建目录RAID5

将逻辑卷挂载到/raid5

 

[root@localhost ~]# mkdir /raid5

[root@localhost ~]# mount/dev/mail_ste/mail /raid5

 

 

查看硬盘使用情况,可以看到/raid5

 

[root@localhost ~]#df -hT

Filesystem                Type      Size Used Avail Use% Mounted on

/dev/mapper/centos-root   xfs       39G  986M   38G  3% /

devtmpfs                  devtmpfs  236M    0  236M   0% /dev

tmpfs                     tmpfs     242M    0  242M   0% /dev/shm

tmpfs                     tmpfs     242M 4.5M  238M   2% /run

tmpfs                     tmpfs     242M    0  242M   0% /sys/fs/cgroup

/dev/sda1                 xfs       497M  98M  400M  20% /boot

/dev/sr0                  iso9660   3.9G 3.9G     0 100% /mnt/cdrom

/dev/mapper/mail_ste-mail ext4      39G   49M   37G  1% /raid5

 

 

 

编辑系统挂载目录的配置文件,开启自动挂载

 

 

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

 

在最后一行添加

 

 

 

测试

 

/raid5下创建目录aa,再次查看,创建成功,说明RAID5卷是好的

 

[root@localhost ~]# cd /raid5

[root@localhost raid5]# mkdir aa

[root@localhost raid5]# ll

total 20

drwxr-xr-x 2 root root  4096 Aug 20 12:03 aa

drwx------ 2 root root 16384 Aug 20 11:50 lost+found


LINUX 创建RAID5 和 LVM 逻辑卷,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。