RAID与磁盘管理之——综合应用

为了实现磁盘的管理和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
完成!
 
 
posted @ 2019-07-15 10:35  假如菜鸟不是鸟  阅读(471)  评论(0编辑  收藏  举报