s49 磁盘存储文件系统管理详解

目录
  • 第一部分
    • 1、创建一个2G的文件系统
    • 2、写一个脚本,完成如下功能
    • 3、配置为yum源
  • 第二部分 RAID
    • 1、创建一个可用空间为1G的RAID设备
    • 2、创建由三块硬盘组成的可用空间为2G的RAID5设备
  • 第三部分 LVM
    • 1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;
    • 2、新建用户archlinux
    • 3、扩展testlv至7G
    • 4、收缩testlv至3G
    • 5、对testlv创建快照
    • 6、删除逻辑卷、卷组、物理卷

第一部分

1、创建一个2G的文件系统

块大小为2048byte,预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

#新添加一块10G磁盘
[root@centos8 ~]# scandisk
[root@centos8 ~]# alias scandisk
alias scandisk='echo '\''- - -'\'' > /sys/class/scsi_host/host0/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host1/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host2/scan'
[root@centos8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part
└─sda5    8:5    0    4G  0 part
sdb       8:16   0   20G  0 disk
├─sdb1    8:17   0    1G  0 part /mnt/sdb1
├─sdb2    8:18   0    2G  0 part
├─sdb3    8:19   0    1K  0 part
└─sdb5    8:21   0    3G  0 part
sdc       8:32   0   10G  0 disk
├─sdc1    8:33   0    1G  0 part
└─sdc2    8:34   0    2G  0 part
sdd       8:48   0   10G  0 disk 	#这个是新添加的磁盘
sr0      11:0    1  7.7G  0 rom
nvme0n1 259:0    0    5G  0 disk
[root@centos8 ~]# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x0712eaa0.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): p
Disk /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0712eaa0
Device     Boot Start     End Sectors Size Id Type
/dev/sdd1        2048 4196351 4194304   2G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part
└─sda5    8:5    0    4G  0 part
sdb       8:16   0   20G  0 disk
├─sdb1    8:17   0    1G  0 part /mnt/sdb1
├─sdb2    8:18   0    2G  0 part
├─sdb3    8:19   0    1K  0 part
└─sdb5    8:21   0    3G  0 part
sdc       8:32   0   10G  0 disk
├─sdc1    8:33   0    1G  0 part
└─sdc2    8:34   0    2G  0 part
sdd       8:48   0   10G  0 disk
└─sdd1    8:49   0    2G  0 part 	#新建的分区
sr0      11:0    1  7.7G  0 rom
nvme0n1 259:0    0    5G  0 disk
[root@centos8 ~]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdd1	#-b 2048 块大小为2048byte   -m 1  预留1%  -L TEST  卷标名为TEST
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 1048576 2k blocks and 131072 inodes
Filesystem UUID: 0f8a2804-a927-4cde-9d3c-8066d7148386
Superblock backups stored on blocks:
	16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# tune2fs -l /dev/sdd1
tune2fs 1.45.4 (23-Sep-2019)
Filesystem volume name:   TEST	#卷标名为TEST。
Last mounted on:          <not available>
Filesystem UUID:          0f8a2804-a927-4cde-9d3c-8066d7148386
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl	#centos8 ext4文件系统,默认就有acl功能,不需要单独设置
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              131072
Block count:              1048576
Reserved block count:     10485		#预留块大小
Free blocks:              1011035
Free inodes:              131061
First block:              0
Block size:               2048	#块大小为2048。
Fragment size:            2048
Group descriptor size:    64
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Thu Dec  3 22:58:44 2020
Last mount time:          n/a
Last write time:          Thu Dec  3 22:58:44 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Thu Dec  3 22:58:44 2020
Check interval:           0 (<none>)
Lifetime writes:          1058 kB
Reserved blocks uid:      0 (user root)	#预留给谁使用,root。
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      c99589a0-f6eb-4dd6-a178-b4113c273353
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xc13d6cca
[root@centos8 ~]# mkdir /test	#创建挂载目录
[root@centos8 ~]# blkid /dev/sdd1	#查看UUID和文件系统类型
/dev/sdd1: LABEL="TEST" UUID="0f8a2804-a927-4cde-9d3c-8066d7148386" TYPE="ext4" PARTUUID="0712eaa0-01"
[root@centos8 ~]# vim /etc/fstab
#添加下面行
UUID=0f8a2804-a927-4cde-9d3c-8066d7148386 /test                   ext4   defaults         0  0
:wq
[root@centos8 ~]# mount -a	#自动挂载
[root@centos8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=905164k,nr_inodes=226291,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=23440)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,noquota)
/dev/sda1 on /boot type ext4 (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=184384k,mode=700)
/dev/sdb1 on /mnt/sdb1 type ext4 (rw,noatime,nodiratime)
/dev/sdd1 on /test type ext4 (rw,relatime)	#已经挂载
[root@centos8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part
└─sda5    8:5    0    4G  0 part
sdb       8:16   0   20G  0 disk
├─sdb1    8:17   0    1G  0 part /mnt/sdb1
├─sdb2    8:18   0    2G  0 part
├─sdb3    8:19   0    1K  0 part
└─sdb5    8:21   0    3G  0 part
sdc       8:32   0   10G  0 disk
├─sdc1    8:33   0    1G  0 part
└─sdc2    8:34   0    2G  0 part
sdd       8:48   0   10G  0 disk
└─sdd1    8:49   0    2G  0 part /test	#已经挂载
sr0      11:0    1  7.7G  0 rom
nvme0n1 259:0    0    5G  0 disk
[root@centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          905164       0    905164   0% /dev
tmpfs             921932       0    921932   0% /dev/shm
tmpfs             921932    8940    912992   1% /run
tmpfs             921932       0    921932   0% /sys/fs/cgroup
/dev/sda2      104806400 2152664 102653736   3% /
/dev/sda3       52403200  398448  52004752   1% /data
/dev/sda1         999320  137644    792864  15% /boot
tmpfs             184384       0    184384   0% /run/user/0
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1
/dev/sdd1        2031306    9236   1992908   1% /test
#已经挂载

2、写一个脚本,完成如下功能

(1)列出当前系统识别到的所有磁盘设备

(2)如磁盘数量为1,则显示其空间使用信息

否则,则显示最后一个磁盘上的空间使用信息

[root@centos8 ~]# vim disk_used.sh
#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2020-12-04
#FileName:      disk_used.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
disk=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p'`
disk_num=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p'| wc -l`
disk_end=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p' | sed -n '$p'`
if [ $disk_num -eq 1 ];then
	df | grep "/dev/$disk"
else
	df | grep "/dev/$disk_end"
fi
:wq
[root@centos8 ~]# bash disk_used.sh
/dev/sda2      104806400 4868684  99937716   5% /
/dev/sda3       52403200  398400  52004800   1% /data
/dev/sda1         999320  192580    737928  21% /boot
#添加两块硬盘
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    5G  0 disk
sdc      8:32   0    5G  0 disk
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x2e83806e.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2e83806e
Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4196351 4194304   2G 83 Linux
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (4196352-10485759, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-10485759, default 10485759):
Created a new partition 2 of type 'Linux' and of size 3 GiB.
Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2e83806e
Device     Boot   Start      End Sectors Size Id Type
/dev/sdb1          2048  4196351 4194304   2G 83 Linux
/dev/sdb2       4196352 10485759 6289408   3G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    5G  0 disk
├─sdb1   8:17   0    2G  0 part
└─sdb2   8:18   0    3G  0 part
sdc      8:32   0    5G  0 disk
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: c520fbef-2726-4ab2-b54f-b654bd6c6a1f
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 786176 4k blocks and 196608 inodes
Filesystem UUID: b5efe116-aec1-41e7-80a2-3791b3ee5669
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# mkdir /mnt/sdb{1,2}
[root@centos8 ~]# mount /dev/sdb1 /mnt/sdb1
[root@centos8 ~]# mount /dev/sdb2 /mnt/sdb2
[root@centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          893740       0    893740   0% /dev
tmpfs             921916       0    921916   0% /dev/shm
tmpfs             921916    9528    912388   2% /run
tmpfs             921916       0    921916   0% /sys/fs/cgroup
/dev/sda2      104806400 4868932  99937468   5% /
/dev/sda3       52403200  398400  52004800   1% /data
/dev/sda1         999320  192580    737928  21% /boot
tmpfs             184380    1168    183212   1% /run/user/42
tmpfs             184380       4    184376   1% /run/user/0
/dev/sdb1        1998672    6144   1871288   1% /mnt/sdb1
/dev/sdb2        3029776    9216   2846944   1% /mnt/sdb2
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    5G  0 disk
├─sdb1   8:17   0    2G  0 part /mnt/sdb1
└─sdb2   8:18   0    3G  0 part /mnt/sdb2
sdc      8:32   0    5G  0 disk
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x2885d32c.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +3G
Created a new partition 1 of type 'Linux' and of size 3 GiB.
Command (m for help): p
Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2885d32c
Device     Boot Start     End Sectors Size Id Type
/dev/sdc1        2048 6293503 6291456   3G 83 Linux
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (6293504-10485759, default 6293504):
Last sector, +sectors or +size{K,M,G,T,P} (6293504-10485759, default 10485759):
Created a new partition 2 of type 'Linux' and of size 2 GiB.
Command (m for help): p
Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2885d32c
Device     Boot   Start      End Sectors Size Id Type
/dev/sdc1          2048  6293503 6291456   3G 83 Linux
/dev/sdc2       6293504 10485759 4192256   2G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    5G  0 disk
├─sdb1   8:17   0    2G  0 part /mnt/sdb1
└─sdb2   8:18   0    3G  0 part /mnt/sdb2
sdc      8:32   0    5G  0 disk
├─sdc1   8:33   0    3G  0 part
└─sdc2   8:34   0    2G  0 part
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# mkfs.ext4 /dev/sdc1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 786432 4k blocks and 196608 inodes
Filesystem UUID: e4eac13f-f7aa-4cb1-9c72-d492f16231b9
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# mkfs.ext4 /dev/sdc2
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 524032 4k blocks and 131072 inodes
Filesystem UUID: 91996752-51a6-42c3-9398-fdc9c58aa39f
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# mkdir /mnt/sdc{1,2}
[root@centos8 ~]# mount /dev/sdc1 /mnt/sdc1
[root@centos8 ~]# mount /dev/sdc2 /mnt/sdc2
[root@centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          893740       0    893740   0% /dev
tmpfs             921916       0    921916   0% /dev/shm
tmpfs             921916    9536    912380   2% /run
tmpfs             921916       0    921916   0% /sys/fs/cgroup
/dev/sda2      104806400 4868932  99937468   5% /
/dev/sda3       52403200  398400  52004800   1% /data
/dev/sda1         999320  192580    737928  21% /boot
tmpfs             184380    1168    183212   1% /run/user/42
tmpfs             184380       4    184376   1% /run/user/0
/dev/sdb1        1998672    6144   1871288   1% /mnt/sdb1
/dev/sdb2        3029776    9216   2846944   1% /mnt/sdb2
/dev/sdc1        3030800    9216   2847916   1% /mnt/sdc1
/dev/sdc2        2030416    6144   1903084   1% /mnt/sdc2
[root@centos8 ~]# bash disk_used.sh
/dev/sdc1        3030800    9216   2847916   1% /mnt/sdc1
/dev/sdc2        2030416    6144   1903084   1% /mnt/sdc2

3、配置为yum源

将CentOS6的CentOS-6.10-x86_64-bin-DVD1.iso和CentOS-6.10-x86_64-bin-DVD2.iso两个文件,合并成一个CentOS-6.10-x86_64-Everything.iso文件,并将其配置为yum源

方法1:

先添加一个光驱,把CentOS-6.10-x86_64-bin-DVD1.iso加载到/dev/sr0和把CentOS-6.10-x86_64-bin-DVD2.iso加载到/dev/sr1

[root@centos6 ~]# mkdir /mnt/iso	#创建复制DVD1和DVD2的目录
[root@centos6 ~]# mkdir /mnt/dvd1	#创建挂载DVD1的目录
[root@centos6 ~]# mkdir /mnt/dvd2	#创建挂载DVD2的目录
[root@centos6 ~]# mount /dev/sr0 /mnt/dvd1	#挂载DVD1
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@centos6 ~]# mount /dev/sr1 /mnt/dvd2	#挂载DVD2
mount: block device /dev/sr1 is write-protected, mounting read-only
[root@centos6 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2      100902304  853756  94916260   1% /
tmpfs             501508       0    501508   0% /dev/shm
/dev/sda1         999320   30712    916180   4% /boot
/dev/sda3       51475068   53064  48800564   1% /data
/dev/sr0         3897932 3897932         0 100% /mnt/dvd1
/dev/sr1         2136278 2136278         0 100% /mnt/dvd2
[root@centos6 ~]# ls /mnt/dvd1
CentOS_BuildTag  images                    repodata                       RPM-GPG-KEY-CentOS-Testing-6
EFI              isolinux                  RPM-GPG-KEY-CentOS-6           TRANS.TBL
EULA             Packages                  RPM-GPG-KEY-CentOS-Debug-6
GPL              RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Security-6
[root@centos6 ~]# ls /mnt/dvd2
CentOS_BuildTag  Packages              RPM-GPG-KEY-CentOS-Debug-6     RPM-GPG-KEY-CentOS-Testing-6
EULA             RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Security-6  TRANS.TBL
[root@centos6 ~]# cp  -av  /mnt/dvd1/*  /mnt/iso	#把DVD1复制到/mnt/iso目录
[root@centos6 ~]# cp  -v  /mnt/dvd2/Packages/*.rpm  /mnt/iso/Packages/	#复制DVD2到/mnt/iso
#合并TRANS.TBL
#将DVD2中TRANS.TBL的信息追加到DVD1中TRANS.TBL后面, 并排序保存
[root@centos6 ~]# cat  /mnt/dvd2/Packages/TRANS.TBL  &gt;&gt;  /mnt/iso/Packages/TRANS.TBL
[root@centos6 ~]# mv  /mnt/iso/Packages/{TRANS.TBL,TRANS.TBL.BAK}
[root@centos6 ~]# sort  /mnt/iso/Packages/TRANS.TBL.BAK  &gt;  /mnt/iso/Packages/TRANS.TBL
[root@centos6 ~]# rm  -rf  /mnt/iso/Packages/TRANS.TBL.BAK
#/mnt/iso已经是合并后的文件了
[root@centos6 ~]# du -sh /mnt/iso
5.9G	/mnt/iso
[root@centos6 ~]# mkdir /data/iso	#创建iso文件目录
[root@centos6 ~]# yum -y install mkisofs	#安装创建ISO文件工具
[root@centos6 ~]# mkisofs  -l  -J  -L  -r  -V  "CentOS-6.10-x86_64-Everything"  -o  /data/iso/CentOS-6.10-x86_64-Everything.iso  /mnt/iso	#创建ISO文件
[root@centos6 ~]# ll -h /data/iso
total 5.8G
-rw-r--r-- 1 root root 5.8G Dec  4 01:38 CentOS-6.10-x86_64-Everything.iso

sz 不支持超过4G的文件传输

用Xftp 把文件传到windows里

#关机移除新添加的光驱,把/dev/sr0挂载成CentOS-6.10-x86_64-Everything.iso
[root@centos6 ~]# yum -y install autofs	#安装自动挂载光盘工具
[root@centos6 ~]# service autofs start;chkconfig autofs on	#启动autofs服务,并开机启动
Loading autofs4:                                           [  OK  ]
Starting automount:                                        [  OK  ]
[root@centos6 ~]# ls /misc
[root@centos6 ~]# ls /misc/cd
CentOS_BuildTag  images      RELEASE-NOTES-en-US.html    RPM-GPG-KEY-CentOS-Security-6
EFI              isolinux    repodata                    RPM-GPG-KEY-CentOS-Testing-6
EULA             lost+found  RPM-GPG-KEY-CentOS-6        TRANS.TBL
GPL              Packages    RPM-GPG-KEY-CentOS-Debug-6
[root@centos6 ~]# vim /etc/yum.repos.d/test.repo 	#设置光盘镜像本地源
[base]
name=base
baseurl=file:///misc/cd
checkgpg=0
:wq
[root@centos6 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                | 4.0 kB     00:00 ...
repo id                                             repo name                                        status
base                                                base                                             6,713
repolist: 6,713

方法二:

#先设置光驱加载CentOS-6.10-x86_64-bin-DVD1.iso
[root@centos6 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0 48.8G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
[root@centos6 ~]# dd if=/dev/sr0 bs=1M of=CentOS-6.10-x86_64-Everything.iso
3807+0 records in
3807+0 records out
3991928832 bytes (4.0 GB) copied, 271.833 s, 14.7 MB/s
[root@centos6 ~]# ll CentOS-6.10-x86_64-Everything.iso -h
-rw-r--r-- 1 root root 3.8G Dec  4 18:50 CentOS-6.10-x86_64-Everything.iso
#把光驱断开连接,设置光驱加载CentOS-6.10-x86_64-bin-DVD2.iso,再连接光驱
[root@centos6 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1    2G  0 rom
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0 48.8G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
[root@centos6 ~]# dd if=/dev/sr0 ibs=1k skip=32 of=CentOS-6.10-x86_64-Everything.iso obs=1M seek=3788
#skip=32参考的ISO9660文件头,seek=3788,跳过上个镜像的大小。
2136246+0 records in
2086+1 records out
2187515904 bytes (2.2 GB) copied, 154.047 s, 14.2 MB/s
[root@centos6 ~]# ll -h CentOS-6.10-x86_64-Everything.iso
-rw-r--r-- 1 root root 5.8G Dec  4 18:56 CentOS-6.10-x86_64-Everything.iso

sz 不支持超过4G的文件传输 用Xftp 把文件传到windows里

#把光驱断开连接,设置CentOS-6.10-x86_64-Everything.iso,再连接光驱
[root@centos6 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0 48.8G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
[root@centos6 ~]# yum -y install autofs	#安装自动挂载光盘工具
[root@centos6 ~]# service autofs start;chkconfig autofs on	#启动autofs服务,并开机启动
Loading autofs4:                                           [  OK  ]
Starting automount:                                        [  OK  ]
[root@centos6 ~]# ls /misc
[root@centos6 ~]# ls /misc/cd
CentOS_BuildTag  images      RELEASE-NOTES-en-US.html    RPM-GPG-KEY-CentOS-Security-6
EFI              isolinux    repodata                    RPM-GPG-KEY-CentOS-Testing-6
EULA             lost+found  RPM-GPG-KEY-CentOS-6        TRANS.TBL
GPL              Packages    RPM-GPG-KEY-CentOS-Debug-6
[root@centos6 ~]# vim /etc/yum.repos.d/test.repo 	#设置光盘镜像本地源
[base]
name=base
baseurl=file:///misc/cd
checkgpg=0
:wq
[root@centos6 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                | 4.0 kB     00:00 ...
repo id                                             repo name                                        status
base                                                base                                             6,713
repolist: 6,713

第二部分 RAID

1、创建一个可用空间为1G的RAID设备

文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录

[root@centos8 ~]# scandisk
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    1G  0 disk
sdc      8:32   0    1G  0 disk
sdd      8:48   0    1G  0 disk
sr0     11:0    1  7.7G  0 rom
#添加三块新硬盘/dev/sdb、/dev/sdc和/dev/sdd
[root@centos8 ~]# dnf -y install mdadm
[root@centos8 ~]#  mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sd{b,c,d}
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part  /boot
├─sda2   8:2    0  100G  0 part  /
├─sda3   8:3    0   50G  0 part  /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part  [SWAP]
sdb      8:16   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1
sdc      8:32   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1
sdd      8:48   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# mkfs.ext4 /dev/md0
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 261632 4k blocks and 65408 inodes
Filesystem UUID: 5540936f-bfe4-46ff-8fbb-88e071f5499a
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# tune2fs -l /dev/md0
tune2fs 1.45.4 (23-Sep-2019)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          5540936f-bfe4-46ff-8fbb-88e071f5499a
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65408
Block count:              261632
Reserved block count:     13081
Free blocks:              252781
Free inodes:              65397
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      127
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8176
Inode blocks per group:   511
Flex block group size:    16
Filesystem created:       Fri Dec  4 16:56:44 2020
Last mount time:          n/a
Last write time:          Fri Dec  4 16:56:44 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Dec  4 16:56:44 2020
Check interval:           0 (<none>)
Lifetime writes:          533 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      d8599d77-afd5-4e2f-80c6-f206e7dc2bab
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x066b1a44
[root@centos8 ~]# mkdir /backup
[root@centos8 ~]# blkid /dev/md0
/dev/md0: UUID="5540936f-bfe4-46ff-8fbb-88e071f5499a" TYPE="ext4"
[root@centos8 ~]# vim /etc/fstab
#添加下面内容
UUID=5540936f-bfe4-46ff-8fbb-88e071f5499a /backup                 ext4    defaults        0 0
:wq
[root@centos8 ~]# mount -a
[root@centos8 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        884M     0  884M   0% /dev
tmpfs           901M     0  901M   0% /dev/shm
tmpfs           901M  8.7M  892M   1% /run
tmpfs           901M     0  901M   0% /sys/fs/cgroup
/dev/sda2       100G  2.1G   98G   3% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  135M  775M  15% /boot
tmpfs           181M     0  181M   0% /run/user/0
/dev/md0        990M  2.6M  921M   1% /backup
[root@centos8 ~]# reboot
[root@centos8 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        884M     0  884M   0% /dev
tmpfs           901M     0  901M   0% /dev/shm
tmpfs           901M  8.7M  892M   1% /run
tmpfs           901M     0  901M   0% /sys/fs/cgroup
/dev/sda2       100G  2.1G   98G   3% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  135M  775M  15% /boot
/dev/md0        990M  2.6M  921M   1% /backup
tmpfs           181M     0  181M   0% /run/user/0
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part  /boot
├─sda2   8:2    0  100G  0 part  /
├─sda3   8:3    0   50G  0 part  /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part  [SWAP]
sdb      8:16   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1 /backup
sdc      8:32   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1 /backup
sdd      8:48   0    1G  0 disk
└─md0    9:0    0 1022M  0 raid1 /backup
sr0     11:0    1  7.7G  0 rom

2、创建由三块硬盘组成的可用空间为2G的RAID5设备

要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录

[root@centos8 ~]# scandisk
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0    1G  0 disk
sdc      8:32   0    1G  0 disk
sdd      8:48   0    1G  0 disk
sr0     11:0    1  7.7G  0 rom
#添加三块新硬盘/dev/sdb、/dev/sdc和/dev/sdd
[root@centos8 ~]# dnf -y install mdadm
[root@centos8 ~]# mdadm -C /dev/md1 -a yes -l 5 -n 3 -c 256 /dev/sd{b,c,d}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part  /boot
├─sda2   8:2    0  100G  0 part  /
├─sda3   8:3    0   50G  0 part  /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part  [SWAP]
sdb      8:16   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5
sdc      8:32   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5
sdd      8:48   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5
sr0     11:0    1  7.7G  0 rom
[root@centos8 ~]# mkfs.ext4 /dev/md1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 523264 4k blocks and 130816 inodes
Filesystem UUID: d4447cca-1a84-44c3-b3f6-9a7956091233
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# tune2fs -l /dev/md1
tune2fs 1.45.4 (23-Sep-2019)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          d4447cca-1a84-44c3-b3f6-9a7956091233
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              130816
Block count:              523264
Reserved block count:     26163
Free blocks:              505316
Free inodes:              130805
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      255
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8176
Inode blocks per group:   511
RAID stride:              64
RAID stripe width:        128
Flex block group size:    16
Filesystem created:       Fri Dec  4 17:24:39 2020
Last mount time:          n/a
Last write time:          Fri Dec  4 17:24:40 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Dec  4 17:24:39 2020
Check interval:           0 (<none>)
Lifetime writes:          1045 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      f959b864-fcb7-4eb0-8088-f04be25671fd
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x7e59f1b1
[root@centos8 ~]# mkdir /mydata
[root@centos8 ~]# blkid /dev/md1
/dev/md1: UUID="d4447cca-1a84-44c3-b3f6-9a7956091233" TYPE="ext4"
[root@centos8 ~]# vim /etc/fstab
#添加下面内容
UUID=d4447cca-1a84-44c3-b3f6-9a7956091233 /mydata                 ext4    defaults        0 0
:wq
[root@centos8 ~]# mount -a
[root@centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          905164       0    905164   0% /dev
tmpfs             921932       0    921932   0% /dev/shm
tmpfs             921932    8900    913032   1% /run
tmpfs             921932       0    921932   0% /sys/fs/cgroup
/dev/sda2      104806400 2149500 102656900   3% /
/dev/sda3       52403200  398400  52004800   1% /data
/dev/sda1         999320  137584    792924  15% /boot
tmpfs             184384       0    184384   0% /run/user/0
/dev/md1         2027408    6144   1900228   1% /mydata
[root@centos8 ~]# reboot
[root@centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          905164       0    905164   0% /dev
tmpfs             921932       0    921932   0% /dev/shm
tmpfs             921932    8908    913024   1% /run
tmpfs             921932       0    921932   0% /sys/fs/cgroup
/dev/sda2      104806400 2148524 102657876   3% /
/dev/sda3       52403200  398400  52004800   1% /data
/dev/sda1         999320  137580    792928  15% /boot
/dev/md1         2027408    6144   1900228   1% /mydata
tmpfs             184384       0    184384   0% /run/user/0
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part  /boot
├─sda2   8:2    0  100G  0 part  /
├─sda3   8:3    0   50G  0 part  /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part  [SWAP]
sdb      8:16   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5 /mydata
sdc      8:32   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5 /mydata
sdd      8:48   0    1G  0 disk
└─md1    9:1    0    2G  0 raid5 /mydata
sr0     11:0    1  7.7G  0 rom

第三部分 LVM

1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;

需求PE大小为16MB,而后在卷组中的创建大小为5G的逻辑卷testlv;挂载至/users目录

[root@centos8 ~]# scandisk
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0   15G  0 disk
sdc      8:32   0    5G  0 disk
sr0     11:0    1  7.7G  0 rom
#添加两块硬盘sdb、sdc
[root@centos8 ~]# pvs /dev/sd{b,c}
-bash: pvs: command not found
[root@centos8 ~]# dnf -y install lvm2
[root@centos8 ~]# pvs
[root@centos8 ~]# vgs
[root@centos8 ~]# lvs
[root@centos8 ~]# pvcreate /dev/sd{b,c}		#把两块硬盘加到物理卷
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc" successfully created.
[root@centos8 ~]# pvs
  PV         VG Fmt  Attr PSize  PFree
  /dev/sdb      lvm2 ---  15.00g 15.00g
  /dev/sdc      lvm2 ---   5.00g  5.00g
[root@centos8 ~]# vgcreate -s 16M testvg /dev/sd{b,c}	#把 /dev/sdb和/dev/sdc加入到卷组,块大小为16M
  Volume group "testvg" successfully created
[root@centos8 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@centos8 ~]# pvs
  PV         VG     Fmt  Attr PSize  PFree
  /dev/sdb   testvg lvm2 a--  14.98g 14.98g
  /dev/sdc   testvg lvm2 a--   4.98g  4.98g
[root@centos8 ~]# vgdisplay
  --- Volume group ---
  VG Name               testvg
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               <19.97 GiB	#卷组大小20G
  PE Size               16.00 MiB	#块大小为16M
  Total PE              1278
  Alloc PE / Size       0 / 0
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               ICjCEw-pbWT-0jUt-f4hV-lDOJ-YSSq-o3tq5U
[root@centos8 ~]# lvcreate  -L 5G -n testlv testvg	#创建逻辑卷testlv,大小5G
  Logical volume "testlv" created.
[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g
[root@centos8 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                aPZyRk-7n9N-P7ol-ZwJv-2LHI-aOm2-8tED5j
  LV Write Access        read/write
  LV Creation host, time centos8.neteagles.cn, 2020-12-06 19:54:00 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@centos8 ~]# mkfs.ext4 /dev/testvg/testlv		#创建逻辑卷文件系统
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 81a7eb1b-72ae-4d5c-9d0f-44a3daa14610
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos8 ~]# mkdir /users
[root@centos8 ~]# mount /dev/testvg/testlv /users/	#挂载逻辑卷
[root@centos8 ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  884M     0  884M   0% /dev
tmpfs                     tmpfs     901M     0  901M   0% /dev/shm
tmpfs                     tmpfs     901M  8.7M  892M   1% /run
tmpfs                     tmpfs     901M     0  901M   0% /sys/fs/cgroup
/dev/sda2                 xfs       100G  2.1G   98G   3% /
/dev/sda3                 xfs        50G  390M   50G   1% /data
/dev/sda1                 ext4      976M  135M  775M  15% /boot
tmpfs                     tmpfs     181M     0  181M   0% /run/user/0
/dev/mapper/testvg-testlv ext4      4.9G   20M  4.6G   1% /users	#已被挂载

2、新建用户archlinux

需求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录

[root@centos8 ~]# useradd -d /users/archlinux archlinux
[root@centos8 ~]# getent passwd archlinux
archlinux:x:1001:1001::/users/archlinux:/bin/bash
[root@centos8 ~]# su archlinux
[archlinux@centos8 root]$ cp -r /etc/pam.d ~
[archlinux@centos8 root]$ ll -a /users/archlinux/
total 28
drwx------ 3 archlinux archlinux 4096 Dec  6 19:57 .
drwxr-xr-x 4 root      root      4096 Dec  6 19:56 ..
-rw------- 1 archlinux archlinux   93 Dec  6 19:57 .bash_history
-rw-r--r-- 1 archlinux archlinux   18 Nov  9  2019 .bash_logout
-rw-r--r-- 1 archlinux archlinux  141 Nov  9  2019 .bash_profile
-rw-r--r-- 1 archlinux archlinux  312 Nov  9  2019 .bashrc
drwxr-xr-x 2 archlinux archlinux 4096 Dec  6 19:56 pam.d

3、扩展testlv至7G

需求archlinux用户的文件不能丢失

[archlinux@centos8 root]$ exit
exit
[root@centos8 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  testvg   2   1   0 wz--n- <19.97g <14.97g	#卷组可用空间为15G
[root@centos8 ~]#  lvextend -r -L +2G /dev/testvg/testlv
  Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
  Logical volume testvg/testlv successfully resized.
resize2fs 1.45.4 (23-Sep-2019)
Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/testvg-testlv is now 1835008 (4k) blocks long.
[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-ao---- 7.00g
[root@centos8 ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  884M     0  884M   0% /dev
tmpfs                     tmpfs     901M     0  901M   0% /dev/shm
tmpfs                     tmpfs     901M  8.7M  892M   1% /run
tmpfs                     tmpfs     901M     0  901M   0% /sys/fs/cgroup
/dev/sda2                 xfs       100G  2.1G   98G   3% /
/dev/sda3                 xfs        50G  390M   50G   1% /data
/dev/sda1                 ext4      976M  135M  775M  15% /boot
tmpfs                     tmpfs     181M     0  181M   0% /run/user/0
/dev/mapper/testvg-testlv ext4      6.9G   23M  6.5G   1% /users
[root@centos8 ~]# ll -a /users/archlinux/
total 28
drwx------ 3 archlinux archlinux 4096 Dec  6 19:57 .
drwxr-xr-x 4 root      root      4096 Dec  6 19:56 ..
-rw------- 1 archlinux archlinux   93 Dec  6 19:57 .bash_history
-rw-r--r-- 1 archlinux archlinux   18 Nov  9  2019 .bash_logout
-rw-r--r-- 1 archlinux archlinux  141 Nov  9  2019 .bash_profile
-rw-r--r-- 1 archlinux archlinux  312 Nov  9  2019 .bashrc
drwxr-xr-x 2 archlinux archlinux 4096 Dec  6 19:56 pam.d	#数据还在

4、收缩testlv至3G

要求archlinux用户的文件不能丢失

[root@centos8 ~]# umount /dev/testvg/testlv 	#取消挂载
[root@centos8 ~]# fsck -f /dev/testvg/testlv 	#检查文件系统
fsck from util-linux 2.32.1
e2fsck 1.45.4 (23-Sep-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/testvg-testlv: 40/458752 files (0.0% non-contiguous), 50972/1835008 blocks
[root@centos8 ~]# resize2fs /dev/testvg/testlv 3G	#缩减文件系统
resize2fs 1.45.4 (23-Sep-2019)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 (4k) blocks long.
 [root@centos8 ~]# lvreduce -L 3G /dev/testvg/testlv 	#缩减逻辑卷
  WARNING: Reducing active logical volume to 3.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
  Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
  Logical volume testvg/testlv successfully resized.
[root@centos8 ~]# mount /dev/testvg/testlv /users/	#挂载逻辑卷
[root@centos8 ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  884M     0  884M   0% /dev
tmpfs                     tmpfs     901M     0  901M   0% /dev/shm
tmpfs                     tmpfs     901M  8.7M  892M   1% /run
tmpfs                     tmpfs     901M     0  901M   0% /sys/fs/cgroup
/dev/sda2                 xfs       100G  2.1G   98G   3% /
/dev/sda3                 xfs        50G  390M   50G   1% /data
/dev/sda1                 ext4      976M  135M  775M  15% /boot
tmpfs                     tmpfs     181M     0  181M   0% /run/user/0
/dev/mapper/testvg-testlv ext4      2.9G   16M  2.8G   1% /users	#现在已经缩减至3G
[root@centos8 ~]# ll -a /users/archlinux/
total 28
drwx------ 3 archlinux archlinux 4096 Dec  6 19:57 .
drwxr-xr-x 4 root      root      4096 Dec  6 19:56 ..
-rw------- 1 archlinux archlinux   93 Dec  6 19:57 .bash_history
-rw-r--r-- 1 archlinux archlinux   18 Nov  9  2019 .bash_logout
-rw-r--r-- 1 archlinux archlinux  141 Nov  9  2019 .bash_profile
-rw-r--r-- 1 archlinux archlinux  312 Nov  9  2019 .bashrc
drwxr-xr-x 2 archlinux archlinux 4096 Dec  6 19:56 pam.d
#数据还在

5、对testlv创建快照

并尝试基于快照备份数据,验证快照的功能

[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-ao---- 3.00g 	#逻辑卷还有未使用空间
[root@centos8 ~]# lvcreate -s -L 1G -n testlv-snapshot -p r /dev/testvg/testlv
  Logical volume "testlv-snapshot" created.
[root@centos8 ~]# lvs
  LV              VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv          testvg owi-aos--- 3.00g
  testlv-snapshot testvg sri-a-s--- 1.00g      testlv 0.01
[root@centos8 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                aPZyRk-7n9N-P7ol-ZwJv-2LHI-aOm2-8tED5j
  LV Write Access        read/write
  LV Creation host, time centos8.neteagles.cn, 2020-12-06 19:54:00 +0800
  LV snapshot status     source of
                         testlv-snapshot [active]
  LV Status              available
  # open                 1
  LV Size                3.00 GiB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
  --- Logical volume ---
  LV Path                /dev/testvg/testlv-snapshot
  LV Name                testlv-snapshot
  VG Name                testvg
  LV UUID                PvdE7T-kJCO-ogxX-bjZ3-jRbT-SwVn-z9KqJ9
  LV Write Access        read only
  LV Creation host, time centos8.neteagles.cn, 2020-12-06 20:12:33 +0800
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  COW-table size         1.00 GiB
  COW-table LE           64
  Allocated to snapshot  0.01%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[root@centos8 ~]# mkdir /mnt/testlv-snapshot
[root@centos8 ~]# mount /dev/testvg/testlv-snapshot /mnt/testlv-snapshot/
mount: /mnt/testlv-snapshot: WARNING: device write-protected, mounted read-only.
[root@centos8 ~]# ls /mnt/testlv-snapshot/
archlinux  lost+found
[root@centos8 ~]# ls /users/
archlinux  lost+found
[root@centos8 ~]# ls /users/archlinux/
pam.d
[root@centos8 ~]# rm -rf /users/archlinux/pam.d/	#删除逻辑卷中的牡蛎
[root@centos8 ~]# ls /users/archlinux/	#逻辑卷中已经没有了
[root@centos8 ~]# ls /mnt/testlv-snapshot/archlinux/
pam.d
#快照中还在
[root@centos8 ~]# rm -rf /mnt/testlv-snapshot/archlinux/pam.d/
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/runuser': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/polkit-1': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/systemd-user': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/passwd': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/password-auth': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vmtoolsd': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/system-auth': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vlock': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/runuser-l': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sssd-shadowutils': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/postlogin': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/remote': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo-i': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/fingerprint-auth': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sshd': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/config-util': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su-l': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/smartcard-auth': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/other': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/login': Read-only file system
rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/crond': Read-only file system
#快照中的文件不能删除
[root@centos8 ~]# umount /dev/testvg/testlv	#取消挂载逻辑卷
[root@centos8 ~]# umount /mnt/testlv-snapshot/	#取消挂载快照
[root@centos8 ~]# lvs
  LV              VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv          testvg owi-a-s--- 3.00g
  testlv-snapshot testvg sri-a-s--- 1.00g      testlv 0.01
[root@centos8 ~]# lvconvert --merge /dev/testvg/testlv-snapshot 	#合并快照
  Merging of volume testvg/testlv-snapshot started.
  testvg/testlv: Merged: 100.00%
[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 3.00g  #快照只是一次性的,还原过后就没有了
[root@centos8 ~]# mount /dev/testvg/testlv /users/
	#挂载逻辑卷
[root@centos8 ~]# ll /users/
total 20
drwx------ 3 archlinux archlinux  4096 Dec  6 19:57 archlinux
drwx------ 2 root      root      16384 Dec  6 19:54 lost+found
[root@centos8 ~]# ll /users/archlinux/
total 4
drwxr-xr-x 2 archlinux archlinux 4096 Dec  6 19:56 pam.d
#还原成做快照时的文件了

6、删除逻辑卷、卷组、物理卷

[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-ao---- 3.00g
[root@centos8 ~]# umount /dev/testvg/testlv #取消逻辑卷挂载
[root@centos8 ~]# lvremove /dev/testvg/testlv 	#删除逻辑卷
Do you really want to remove active logical volume testvg/testlv? [y/n]: y
  Logical volume "testlv" successfully removed
[root@centos8 ~]# lvs
[root@centos8 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@centos8 ~]# vgremove testvg	#删除卷组
  Volume group "testvg" successfully removed
[root@centos8 ~]# vgs
[root@centos8 ~]# pvs
  PV         VG Fmt  Attr PSize  PFree
  /dev/sdb      lvm2 ---  15.00g 15.00g
  /dev/sdc      lvm2 ---   5.00g  5.00g
[root@centos8 ~]# pvremove /dev/sd{b,c}	#删除逻辑卷
  Labels on physical volume "/dev/sdb" successfully wiped.
  Labels on physical volume "/dev/sdc" successfully wiped.
[root@centos8 ~]# pvs
[root@centos8 ~]# lvblk
-bash: lvblk: command not found
[root@centos8 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0   15G  0 disk
sdc      8:32   0    5G  0 disk
sr0     11:0    1  7.7G  0 rom  

以上就是s49 磁盘存储文件系统管理详解的详细内容,更多关于s49 磁盘存储文件管理的资料请关注我们其它相关文章!

(0)

相关推荐

  • Linux磁盘设备与LVM管理命令示例详解

    前言 在 Linux 操作系统中, 设备文件 是一种特殊类型的文件.这些文件绝大多数位于 /dev 目录下,用来表示 Linux 主机检测到的某个具体的硬件设备. 比如 /dev/sda 文件通常用来指代系统中的第一块硬盘. Linux 操作系统及其应用与服务则通过这些设备文件与对应的硬件设备进行交互. 对于常见的磁盘(ATA.SATA.SCSI.SAS.SSD 等)和优盘等块存储设备,其设备文件主要以 sd* 的形式命名.如 sda 表示第一块硬盘, sdb2 表示第二块硬盘的第二个分区,以此

  • 基于MySQL在磁盘上存储NULL值

    目录 1为何不能直接存个NULL? 2到底怎么存储? 3一行数据的磁盘存储格式 4如何读磁盘的一行数据? 1 为何不能直接存个NULL? NULL值列表,一行数据里可能有的字段值是NULL,比如nickname字段,允许为NULL,存储时,如果没赋值,这字段值就是NULL.假设这个字段的NULL值在磁盘存储时,就是按“NULL”字符串存储的,是不是很浪费存储空间而且还奇怪? 2 到底怎么存储? 不通过字符串,而是通过二进制bit位存储,一行数据里假设有多个字段的值都是NULL,那么这多个字段的N

  • 如何将mysql存储位置迁移到一块新的磁盘上

    1.准备一块新的磁盘,并格式化为与当前根分区相同的文件系统,创建目录并挂载磁盘 ]#fdisk -l #查看磁盘信息 ]#fdisk /dev/sdb #进行分区 ]# df -T #可以查看到根分区的文件系统类型 ]#mkfs.xfs /dev/sdb1 #将新的磁盘分区格式化 ]#mkdir /data ]#mount /dev/sdb1 /data #挂载磁盘 或者写入/etc/fatab文件中,添加一行:/dev/sdb1 /data xfs defaults 0 0 开机自动挂载 ]#

  • 详解Centos7扩展磁盘空间(LVM管理)

    本文介绍了Centos7扩展磁盘空间(LVM管理),分享给大家,具体如下: 查看磁盘情况 # fdisk -l /dev/sda Disk /dev/sda: 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

  • Linux磁盘配额管理图文案例

    磁盘配额是计算机中指定磁盘的储存限制,就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间.这样可以避免因某个用户的过度使用磁盘空间造成其他用户无法正常工作甚至影响系统运行.在服务器管理中此功能非常重要,但对单机用户来说意义不大. 磁盘配额限制特点 限制方式:软限制,硬限制 限制类型:磁盘容量,文件数量 操作流程 先查看pc机中是否安装了能够实现配额的软件包 关闭增强性安全功能 挂载 输入命令vim /etc/fstab 进入挂载点 保存退出,输入moun

  • Mysql存储引擎MyISAM的常见问题(表损坏、无法访问、磁盘空间不足)

    本文为大家分享了解决Mysql存储引擎MyISAM常见问题的方法,供大家参考,具体内容如下 一.处理MyISAM存储引擎的表损坏 在使用MySQL,可能会遇到过MyISAM存储引擎的表损坏的情况.如以下情况: .frm被锁定不能修改 找不到.myi文件(索引文件) 意外结束记录 文件被毁坏 从表处理器得到错误nnn 解决办法1: 使用MySQL自带的myisamchk工具进行修复 打开bin目录,可以看到该工具 命令如下 myisamchk -r tablename r代表recover 或 m

  • s49 磁盘存储文件系统管理详解

    目录 第一部分 1.创建一个2G的文件系统 2.写一个脚本,完成如下功能 3.配置为yum源 第二部分 RAID 1.创建一个可用空间为1G的RAID设备 2.创建由三块硬盘组成的可用空间为2G的RAID5设备 第三部分 LVM 1.创建一个至少有两个PV组成的大小为20G的名为testvg的VG: 2.新建用户archlinux 3.扩展testlv至7G 4.收缩testlv至3G 5.对testlv创建快照 6.删除逻辑卷.卷组.物理卷 第一部分 1.创建一个2G的文件系统 块大小为204

  • mongodb 集群重构和释放磁盘空间实例详解

    MongoDB集群重构,释放磁盘空间 由于mongodb删除了一部分数据后,不会回收相应的磁盘空间,所以这里通过重建数据目录的方式释放磁盘空间. 一 实验环境 配置了一个副本集,该副本集由以下三个节点组成: 10.192.203.201:27017 PRIMARY 10.192.203.202:27017 SECONDARY 10.192.203.202:10001  ARBITER 二 实验步骤 2.1 模拟环境 use dba; for(var i=0;i<1000000;i++)db.c.

  • 一天一个shell命令 linux好管家-磁盘-du命令详解

    du命令 磁盘管理 du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 语法 du [选项][文件] 选项 -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文件大小时,以byte为单位. -c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和. -k或--kilobytes 以KB(1024bytes)为单位输出. -m或--megabytes 以MB为单位

  • 一天一个shell命令 linux好管家--磁盘--df命令详解

    df命令 磁盘管理 df命令用于显示磁盘分区上的可使用的磁盘空间.默认显示单位为KB.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 语法 df(选项)(参数) 选项 -a或--all:包含全部的文件系统: --block-size=<区块大小>:以指定的区块大小来显示区块数目: -h或--human-readable:以可读性较高的方式来显示信息: -H或--si:与-h参数相同,但在计算时是以1000 Bytes为换算单位而非1024 Bytes: -i或--inod

  • PHP操作MongoDB GridFS 存储文件的详解

    复制代码 代码如下: <?php //初始化gridfs $conn = new Mongo(); //连接MongoDB $db = $conn->photos; //选择数据库 $grid = $db->getGridFS(); //取得gridfs对象 //gridfs有三种方式存储文件 //第一种直接存储文件 $id = $grid->storeFile("./logo.png"); //第二种存储文件二进制流 $data = get_file_cont

  • Linux磁盘格式化命令详解

    命令:mke2fs mke2fs [选项] 文件系统 磁盘盘符= 注释: 1.磁盘虽然分好区了,但是还不能用,还需要在这每一个分区上格式化,所谓格式化,其实就是安装文件系统,Windows下的文件系统有Fat32.NTFS,CentOS使用的文件系统为ext,之前centOS5版本使用ext3作为默认的文件系统,而CentOS6使用ext4作为默认的文件系统: 2.当用man查询这四个命令的帮助文档时,你会发现我们看到了同一个帮助文档,这说明四个命令是一样的: 3.指定文件系统格式为ext4,该

  • Windows WMIC命令使用详解(附实例)

    执行"wmic"命令启动WMIC命令行环境.这个命令可以在XP或 .NET Server的标准命令行解释器(cmd.exe).Telnet会话或"运行"对话框中执行.这些启动方法可以在本地使用,也可以通过.NET Server终端服务会话使用. 第一次执行WMIC命令时,Windows首先要安装WMIC,然后显示出WMIC的命令行提示符.在WMIC命令行提示符上,命令以交互的方式执行. wimic的运行方式可以有两种法: 1.搞入wimic进入后输入命令运行,键入w

  • Glide4 高效加载图片的配置详解

    本文介绍了Glide4 高效加载图片的配置详解,分享给大家,具体如下: 在build.gradle中添加glide依赖 // glide 依赖 compile 'com.github.bumptech.glide:glide:4.6.1' // glide 相关注解,生成GlideApp代码 annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1' // Glide网络库配置成okhttp3 compile ('com.gith

  • JDK13的新特性之AppCDS详解

    简介 AppCDS的全称是Application Class-Data Sharing.主要是用来在不同的JVM中共享Class-Data信息,从而提升应用程序的启动速度. 通常来说,如果要执行class字节码,JVM需要执行下面的一些步骤:给定一个类的名字,JVM需要从磁盘上面找到这个文件,加载,并验证字节码,最后将它加载进来. 如果JVM启动的时候需要加载成百上千个class,那么需要的就不是一个小数目了. 对于打包好的jar包来说,只要jar的内容不变,那么jar包中的类的数据始终是相同的

随机推荐