为了实现磁盘的管理和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. 吴裕雄--天生自然ORACLE数据库学习笔记:过程、函数、触发器和包

    create procedure pro_insertDept is begin ,'市场拓展部','JILIN'); --插入数据记录 commit; --提交数据 dbms_output.put_ ...

  2. 吴裕雄--天生自然PYTHON爬虫:使用Selenium爬取大型电商网站数据

    用python爬取动态网页时,普通的requests,urllib2无法实现.例如有些网站点击下一页时,会加载新的内容,但是网页的URL却没有改变(没有传入页码相关的参数),requests.urll ...

  3. Java基础 -3.3

    位运算 指的是可以直接进行二进制数据的计算处理,主要是:与(&).或(|).非(!).异或(^).反码(~).移位处理(>>.<<) 与运算 public class ...

  4. tensorflow简介、目录

    目前工作为nlp相关的分类及数据治理,之前也使用tensorflow写过一些简单分类的代码,感受到深度学习确实用处较大,想更加系统和全面的学习下tensorflow的相关知识,于是我默默的打开了b站: ...

  5. Java1.7已经舍弃substr了

    网上一堆在写substring和substr区别的文章,都是过时的. 起码在官方6.0的api文档中已经找不到了,只有substring()

  6. CentOS初始化脚本(未完)

    #!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...

  7. JS - false 的 六种类型

    document.write("--------------");document.write(!false);document.write("------------- ...

  8. wikipedia

    1. 维基百科 2. 更多维基项目 3. 有关维基百科的电影列表 4. 维基软件 5. 维基百科相关列表 6. 其他知识分享列表 7. 补充:维基百科使用中好用的关键字 1. 维基百科 https:/ ...

  9. Linux centosVMware Nginx负载均衡、ssl原理、生成ssl密钥对、Nginx配置ssl

    一.Nginx负载均衡 vim /usr/local/nginx/conf/vhost/load.conf // 写入如下内容 upstream qq_com { ip_hash; 同一个用户始终保持 ...

  10. C++ class without pointer members

      写在前面 Object Oriented class 的分类:带指针的class和不带指针的class, class 的声明         这里有一个inline的概念,写在类里面的默认为inl ...