day24 磁盘管理(2)

LVM逻辑卷管理

PV: physical volume 物理卷,逻辑意义上硬盘分区;
VG: volume group LVM卷组;
Lv: logic volume 逻辑卷;
PE: physical extend 实例延伸区块,一个逻辑卷最多能含有65534个PE.
LVM逻辑图说明:


image.png

image.png

详细参数说明:


image.png
  • 实验目标1:实现逻辑卷的扩容
第一步:新建4个10G的物理卷
第二步:让新添加的硬盘支持LVM技术
[root@oldboy ~]# pvcreate /dev/sd[e-h]
  Physical volume "/dev/sde" successfully created.
  Physical volume "/dev/sdf" successfully created.
  Physical volume "/dev/sdg" successfully created.
  Physical volume "/dev/sdh" successfully created.
第三步:加入到卷组doc
[root@oldboy ~]# vgcreate doc /dev/sd[e-h]
  Volume group "doc" successfully created
第四步:切割容量200M
[root@oldboy ~]# lvcreate -n test -l 50 doc
WARNING: xfs signature detected on /dev/doc/test at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/doc/test.
  Logical volume "test" created.
第五步:格式化
[root@oldboy ~]# mkfs.xfs /dev/doc/test 
meta-data=/dev/doc/test          isize=512    agcount=4, agsize=12800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=51200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
第六步:挂载
[root@oldboy ~]# mount /dev/doc/test  /mnt/
[root@oldboy ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   47G  1.6G   46G   4% /
devtmpfs                 979M     0  979M   0% /dev
tmpfs                    991M     0  991M   0% /dev/shm
tmpfs                    991M  9.6M  981M   1% /run
tmpfs                    991M     0  991M   0% /sys/fs/cgroup
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                    199M     0  199M   0% /run/user/0
/dev/mapper/doc-test     197M   11M  187M   6% /mnt
第七步:卸载
[root@oldboy ~]# umount /mnt/
第八步:扩容到500mb
[root@oldboy ~]# lvextend  -L  500mb /dev/doc/test 
  Size of logical volume doc/test changed from 200.00 MiB (50 extents) to 500.00 MiB (125 extents).
  Logical volume doc/test successfully resized.
第九步:检查磁盘完整性
[root@oldboy ~]# e2fsck -f /dev/doc/test 
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/doc/test

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 

[root@oldboy ~]# resize2fs /dev/doc/test 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/doc/test
Couldn't find valid filesystem superblock.
[root@oldboy ~]# mkfs.xfs  -f /dev/doc/test 
meta-data=/dev/doc/test          isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0第十步:挂载
[root@oldboy ~]# mount /dev/doc/test  /mnt/
[root@oldboy ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   47G  1.6G   46G   4% /
devtmpfs                 979M     0  979M   0% /dev
tmpfs                    991M     0  991M   0% /dev/shm
tmpfs                    991M  9.6M  981M   1% /run
tmpfs                    991M     0  991M   0% /sys/fs/cgroup
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                    199M     0  199M   0% /run/user/0
/dev/mapper/doc-test     497M   26M  472M   6% /mnt
  • 实验目录2:逻辑卷的缩容
第一步:检查磁盘完整性
[root@oldboy ~]# e2fsck  /dev/doc/test 
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/doc/test

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 
第二步:设置大小
[root@oldboy ~]# lvreduce  -L  100M /dev/doc/test  
  WARNING: Reducing active logical volume to 100.00 MiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce doc/test? [y/n]: Y
  Size of logical volume doc/test changed from 500.00 MiB (125 extents) to 100.00 MiB (25 extents).
  Logical volume doc/test successfully resized.
第三步:格式化挂载
[root@oldboy ~]# mount /dev/doc/test  /mnt/
[root@oldboy ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   47G  1.6G   46G   4% /
devtmpfs                 979M     0  979M   0% /dev
tmpfs                    991M     0  991M   0% /dev/shm
tmpfs                    991M  9.6M  981M   1% /run
tmpfs                    991M     0  991M   0% /sys/fs/cgroup
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                    199M     0  199M   0% /run/user/0
/dev/mapper/doc-test      97M  5.3M   92M   6% /mnt

SWAP交换分区

  • 调整swap分区的大小
第一步:划分空间被swap调用
[root@oldboy ~]# dd if=/dev/zero of=/tmp/1G count=10 bs=100MB
10+0 records in
10+0 records out
1000000000 bytes (1.0 GB) copied, 16.0573 s, 62.3 MB/s
第二步:给swap分区 做标记
[root@oldboy ~]# mkswap /tmp/1G 
Setting up swapspace version 1, size = 976556 KiB
no label, UUID=71766332-aebf-4fab-94a9-64bc4606a944
第三步:指明哪个区分使用swap
[root@oldboy ~]# swapon  /tmp/1G 
swapon: /tmp/1G: insecure permissions 0644, 0600 suggested
第四步:查找swap分区大小
[root@oldboy ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        778M        166M        9.5M        1.0G        1.0G
Swap:          2.0G          0B        2.0G
[root@oldboy ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        778M        165M        9.5M        1.0G        1.0G
Swap:          2.9G          0B        2.9G
命令解释:
dd if: 从哪里取出存储空间信息;
of: 放到哪里去,一般就是放到swap空间里;
count: 拿的数量;
bs:一次拿的大小。

企业面试题

1. 在系统挂载文件中内容编写错误,会发生什么情况?该如何解决?
环境模拟:例如,在/etc/fstab文件中,误将内容修改为错误,会造成服务器启动缓慢;如果对根分区做了一定的修改,会造成只能读文件内容,不能修改和保存!!
[root@oldboy ~]# cat /etc/fstab  模拟出错信息**
#
# /etc/fstab
# Created by anaconda on Fri Jun 28 14:14:27 2019
#
# 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
**UUID=4bd5-b354-48af-befe-f25680347dbe /boot                   xfs     defaults        0 0**
**#UUID=4bd134d5-b354-48af-befe-f25680347dbe /boot                  xfs     defaults        **0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/mapper/doc-test    /mnt    xfs     defaults 0 0
**[root@oldboy ~]# reboot  重启 **速度会很慢**
解决办法:
# mount -o remount rw /
# reboot
## 让根分区重新挂载,有读写权限
  • 企业面试题2:

卸载挂载点常见的有什么问题?
(1)卸载时当前目录就是挂载目录;
(2)卸载目录时,目录下的文件被程序调用;
卸载目录的方法:umount -lf /mnt
-l lasy 懒惰
-f force 强制

  • 企业面试题3:
    28.出现no space on device错误是什么原因和解决方法?
    (1)Inode 文件过多;
    Inode文件过多的原因:定时任务中产生的大量的小文件;
    环境模拟:
    创建多个空文件:touch oldboy{01..100000000}.txt
    解决办法:
    用find命令在当前文件中查找小于2kb的文件,进行删除。
    (2)Block 过多;
    Block 文件过多是因为定时任务输出内容没有追加到空文件当中。
    环境模拟:
    创建一个或多个大文件,比如10GB的。
    解决办法:
    1>用find命令查找大文件;
    2>用du命令;du -sh /* | sort -nrh
    参数详解:
    Du 命令解释:
    -s 汇总 -h 人类可读
    Sort 命令解释:
    -n 排序 -r 倒序 -h 人类可读
  • 企业面试题4:
    如何彻底将文件删除?
    (1)硬链接数量为0,i_link=0
    (2)进程调用数
    为0,i_count=0
    在删除文件时,只能看到硬链接是否被删除,进程被调用不是能被看到的,所以建议可以清空大文件:>/file
    如果误删除/var/log/secure文件,再新建一个secure文件,新产生的日志也不会追加到新建的secure文件中,因为这两个文件的inode不一样了。
    解决办法:重启rsyslog服务,secure文件即可产生。

你可能感兴趣的:(day24 磁盘管理(2))