为了实现磁盘的管理和RAID的综合,现将四块硬盘组合成一个RAID10,并在此基础之上创建物理卷、卷组、逻辑卷,实现在线扩容,最后挂载使用。

其中也部分包含了swap分区的创建和使用。

1、根据linux系统下,一切皆文件的特性。硬盘在linux中识别为文件,分区也是识别为文件,因此在liunx系统之中用一块磁盘的四个主分区(主分区最多四个)模拟成四块SCSI硬盘。

首先进行四个主分区的创建:

[root@localhost ~]# 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 0xdbd4718a.
Command (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):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2500M
Partition 1 of type Linux and of size 2.5 GiB is set
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (5122048-20971519, default 5122048):
Using default value 5122048
Last sector, +sectors or +size{K,M,G} (5122048-20971519, default 20971519): +2500M
Partition 2 of type Linux and of size 2.5 GiB is set
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (10242048-20971519, default 10242048): 
Using default value 10242048
Last sector, +sectors or +size{K,M,G} (10242048-20971519, default 20971519): +2500M
Partition 3 of type Linux and of size 2.5 GiB is set
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p
Selected partition 4
First sector (15362048-20971519, default 15362048):
Using default value 15362048
Last sector, +sectors or +size{K,M,G} (15362048-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Linux and of size 2.7 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2、磁盘同步完成之后开始创建RAID10
[root@localhost ~]# ls /dev/sdb*
/dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdb3  /dev/sdb4
[root@localhost ~]# rpm -q mdadm
mdadm-3.4-14.el7.x86_64
所有的RAID需要mdadm软件包来统一管理。
[root@localhost dev]# mdadm -C /dev/md/md_10 -l 10 -n 4 /dev/sdb{1..4}
mdadm: largest drive (/dev/sdb4) exceeds size (2557952K) by more than 1%
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md/md_10 started.
RAID10创建成功,进到/dev/md/进行查看:
[root@localhost dev]# cd md
[root@localhost md]# ls
md_10
3、创建物理卷、卷组——该卷组中只包含了一个物理卷。
[root@localhost dev]# pvcreate /dev/md/md_10
  Physical volume "/dev/md/md_10" successfully created.
[root@localhost dev]# vgcreate /dev/vg_10 /dev/md/md_10
  Volume group "vg_10" successfully created
如果需要增加物理卷:
pvcreste 新的物理卷名
pvscan ——查看新的可用物理卷
vgextend   卷组名   可用物理卷名
 
4、创建逻辑卷
[root@localhost dev]# lvcreate -L 1000M -n lv_10 /dev/vg_10
  Logical volume "lv_10" created.
进行查看:进到/dev/vg_10
[root@localhost dev]# cd vg_10/
[root@localhost vg_10]# ls
lv_10
 
5、格式化后挂载使用
[root@localhost dev]# mkfs -t xfs /dev/vg_10/lv_10
meta-data=/dev/vg_10/lv_10       isize=512    agcount=8, agsize=31872 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=254976, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=624, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /md_mount
[root@localhost ~]# mount /dev/vg_10/lv_10 /md_mount/
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/sda2                8.7G  4.7G  4.1G  54% /
devtmpfs                 474M     0  474M   0% /dev
tmpfs                    489M   84K  489M   1% /dev/shm
tmpfs                    489M  7.1M  482M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                297M  152M  146M  51% /boot
tmpfs                     98M     0   98M   0% /run/user/0
tmpfs                     98M   16K   98M   1% /run/user/42
/dev/mapper/vg_10-lv_10  994M   33M  962M   4% /md_mount
 
然后会发现/dev/mapper/vg_10-lv_10和设置的路径不太一样,怎么回事?
[root@localhost ~]# ls /dev/mapper/vg_10-lv_10 -l
lrwxrwxrwx 1 root root 7 Jul 14 18:48 /dev/mapper/vg_10-lv_10 -> ../dm-0
仔细查看之后发现是链接文件,指向了目的地。
 
6、在线扩容
[root@localhost ~]# lvextend -L 2000M /dev/vg_10/lv_10
  Size of logical volume vg_10/lv_10 changed from 1000.00 MiB (250 extents) to 1.95 GiB (500 extents).
  Logical volume vg_10/lv_10 successfully resized.
扩容之后文件系统也需要扩展:
[root@localhost ~]# xfs_growfs /dev/vg_10/lv_10
meta-data=/dev/mapper/vg_10-lv_10 isize=512    agcount=8, agsize=31872 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=254976, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=624, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 254976 to 512000
 
查看扩容之后的大小:
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/sda2                8.7G  4.7G  4.1G  54% /
devtmpfs                 474M     0  474M   0% /dev
tmpfs                    489M   84K  489M   1% /dev/shm
tmpfs                    489M  7.1M  482M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                297M  152M  146M  51% /boot
tmpfs                     98M     0   98M   0% /run/user/0
tmpfs                     98M   16K   98M   1% /run/user/42
/dev/mapper/vg_10-lv_10  2.0G   33M  2.0G   2% /md_mount 
 
扩容成功,从RAID到逻辑卷的创建完成!

7、swap交换分区
[root@localhost ~]# mkdir /swap
[root@localhost ~]# dd if=/dev/zero of=/swap/swap bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 8.01682 s, 67.0 MB/s
[root@localhost ~]# mkswap /swap/swap
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=49054206-a32f-443e-b87b-22619a2aead4
 
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           976M        239M         71M        7.1M        665M        553M
Swap:          1.0G          0B        1.0G
[root@localhost ~]# swapon /swap/swap
swapon: /swap/swap: insecure permissions 0644, 0600 suggested.
[root@localhost ~]# chmod 600 /swap/swap
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           976M        239M         68M        7.1M        668M        553M
Swap:          1.5G          0B        1.5G
 
 
交换分区添加成功。
实现开机自启:
echo  “/swap/swap      swap    swap    defaults 0 0” >> /etc/fstab
完成!
 
 

RAID与磁盘管理之——综合应用的更多相关文章

  1. 使用RAID进行磁盘管理

    转自http://www.linuxprobe.com/chapter-06/ 磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有 ...

  2. 每天进步一点点——Linux磁盘管理LVM与RAID

    转载请注明出处:http://blog.csdn.net/cywosp/article/details/38965799 1. 传统磁盘管理问题 当分区大小不够用时无法扩展其大小,仅仅能通过加入硬盘. ...

  3. linux磁盘管理系列-软RAID的实现

    1 什么是RAID RAID全称是独立磁盘冗余阵列(Redundant Array of Independent Disks),基本思想是把多个磁盘组合起来,组合一个磁盘阵列组,使得性能大幅提高. R ...

  4. linux磁盘管理系列二:软RAID的实现

    磁盘管理系列 linux磁盘管理系列一:磁盘配额管理   http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_040_quota.html l ...

  5. Linux RAID 磁盘管理

    Linux RAID 磁盘管理 RAID工作模式介绍:https://www.cnblogs.com/xiangsikai/p/8441440.html 本章主要讲解 Linux下 RAID5 与 R ...

  6. liunx 磁盘管理命令记录

    Linux磁盘管理好坏管理直接关系到整个系统的性能问题. Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分 ...

  7. LVM磁盘管理

    http://www.cnblogs.com/gaojun/archive/2012/08/22/2650229.html Linux LVM硬盘管理及LVM扩容 LVM磁盘管理 一.LVM简介... ...

  8. linux磁盘管理系列-LVM的使用

    LVM是什么 LVM是Linux操作系统的逻辑卷管理器. 现在有两个Linux版本的LVM,分别是 LVM1,LVM2.LVM1是一种已经被认为稳定了几年的成熟产品,LVM2 是最新最好的LVM版本. ...

  9. Linux第七节随笔-下磁盘管理

    baidubaike 磁盘管理物理磁盘---> RAID--->文件系统--->用户使用LVM概念简述Raid详细解说                0                ...

随机推荐

  1. stack的使用-Hdu 1062

    Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. 关于window.location.href页面跳转的坑

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  3. build hadoop, spark, hbase cluster

    1,something: 1,arc land 506  git branch 507  git status 508  git reset multicloud/qcloud/cluster_man ...

  4. 13 JavaScript Array对象&Boolean对象&Math对象&RegExp对象

    万物皆对象,数组是对象,数组可以存储元素,函数,数组等对象 创建数组的三个方式: 常规方式:var myCars = new Array(); 简介方式:var myCars = new Arrray ...

  5. BZOJ 4167: 永远的竹笋采摘

    首先同BZOJ5052 \(O(n \log n \log v)\) 求出所有点对 现在变成选出 \(k\) 条不相交的线段使得权值最小 可用前缀min优化dp \(O(nk)\) 解决 还是太慢,考 ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:联合使用所有表格类

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 02-06Android学习进度报告六

    今天学习了关于Android开发中常用的两个知识,即对话框和悬浮框. 首先我学习了对话框的基本使用流程 Step 1:创建AlertDialog.Builder对象: Step 2:调用setIcon ...

  8. Duilib 窗口之间的消息传递

    转载:https://www.cnblogs.com/Alberl/p/3404240.html 1.定义消息ID #define WM_USER_POS_CHANGED WM_USER + 2 2. ...

  9. Lesson 13 The search for oil

    What do oilmen want to achieve as soon as they strike oil? The deepest holes of all are made for oil ...

  10. Rabbitmq概念用法

    MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可以读取或者订阅队列 ...