栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux学习--磁盘配额、VDO虚拟数据优化

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux学习--磁盘配额、VDO虚拟数据优化

Linux学习–磁盘配额、VDO虚拟数据优化 磁盘容量配额

软限制:当达到软限制时会提示用户,当仍允许用户在限定的额度内继续使用

硬限制:当达到硬限制时会提示用户,且强制终止用户的操作

RHEL8中自带了quota磁盘容量配额服务程序包,但是需要手动配置并重启系统后生效。

以启动目录/boot为例

一、启动磁盘配额
 [root@localhost ~]# vim /etc/fstab
 3 # /etc/fstab
  4 # Created by anaconda on Wed Mar 17 00:16:10 2021
  5 #
  6 # Accessible filesystems, by reference, are maintained under '/dev/disk/'.
  7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
  8 #
  9 # After editing this file, run 'systemctl daemon-reload' to update systemd
 10 # units generated from this file.
 11 #
 12 /dev/mapper/rhel-root   /                       xfs     defaults        0 0
 13 UUID=72e9e1b7-3326-413e-956f-d2ee7e41ad4a /boot                   xfs     defaults,uquota        0 0
 14 /dev/mapper/rhel-swap   swap                    swap    defaults        0 0
[root@localhost ~]# mount | grep boot
/dev/nvme0n1p1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

二、创建账户并对/boot设置写入权限
[root@localhost ~]# useradd zhangsan
[root@localhost ~]# chmod -R o+w /boot
三、配置磁盘配额

xfs_quota命令用于管理设备的磁盘容量配额,语法格式为“xfs_quota [参数] 配额 文件系统”

-c:以参数的形式设置要执行的命令

-x:专家模式,让运维人员能够对quota进行更多复杂的配置

isoft和ihard是通过限制系统最大使用的inode个数来限制文件数量

bsoft和bhard则是代表文件所占用的block大小,也就是文件占用的最大容量的总统计

soft是软限制,超过该限制后也只是将操作记录写到日志中,不对用户行为进行限制。而hard是硬限制,一旦超过系统就会马上禁止,用户再也不能创建或新占任何的硬盘容量。

[root@localhost ~]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 zhangsan' /boot
[root@localhost ~]# xfs_quota -x -c report /boot
User quota on /boot (/dev/nvme0n1p1)
                               Blocks                     
User ID          Used       Soft       Hard    Warn/Grace     
---------- -------------------------------------------------- 
root           132452          0          0     00 [--------]
zhangsan            0       3072       6144     00 [--------]


四、测试

切换到zhangsan这个账户,然后分别创建一个5MB和8MB的文件测试

[root@localhost ~]# su - zhangsan
[zhangsan@localhost ~]$ cd /boot
[zhangsan@localhost boot]$ dd if=/dev/zero of=/boot/zhangsan bs=5M count=1
1+0 records in
1+0 records out
5242880 bytes (5.2 MB, 5.0 MiB) copied, 0.00846127 s, 620 MB/s
[zhangsan@localhost boot]$ dd if=/dev/zero of=/boot/zhangsan bs=8M count=1
dd: error writing '/boot/zhangsan': Disk quota exceeded
1+0 records in
0+0 records out
4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.0102364 s, 410 MB/s

发现可以创建5M大小的文件,但是创建8M大小的文件时提示

Disk quota exceeded,现在将磁盘配额的限制值改大一些

五、修改磁盘配额的值

edquota命令用于管理系统的磁盘配额,英文全称为“edit quota”,语法格式为“edquota [参数] 用户名”

参数作用
-u对某个用户进行设置
-g对某个用户进行设置
-p复制原有的规则到新的用户/组
-t限制宽限期限

将磁盘配额的值修改为8M,然后创建8M的文件测试

[zhangsan@localhost ~]$ edquota -u zhangsan 
Disk quotas for user zhangsan (uid 1001):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/nvme0n1p1                 8192       3072       8192          1        3        6
[zhangsan@localhost ~]$ dd if=/dev/zero of=/boot/zhangsan bs=8M count=1
1+0 records in
1+0 records out
8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.00722449 s, 1.2 GB/s

增大磁盘配额的值以后创建文件成功

VDO虚拟数据优化

VDO(Virtual Data Optimize,虚拟数据优化)是一种通过压缩或删除存储设备上的数据来优化存储空间的技术。

红帽建议部署虚拟机或容器时,建议采用逻辑存储与物理存储为10∶1的比例进行配置,即1TB物理存储对应10TB逻辑存储;而部署对象存储时 (例如使用Ceph)则采用逻辑存储与物理存储为3∶1的比例进行配置,即使用1TB物理存储对应3TB逻辑存储。

一、先添加一块硬盘
[root@localhost ~]# fdisk -l
Disk /dev/nvme0n2: 20 GiB, 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 bytes / 512 bytes

二、安装VDO相关文件

RHEL8默认启用了VDO

[root@localhost ~]# dnf install kmod-kvdo vdo
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:35:25 ago on Tue 19 Oct 2021 11:03:26 PM CST.
Package kmod-kvdo-6.2.0.293-50.el8.x86_64 is already installed.
Package vdo-6.2.0.293-10.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
二、创建一个VDO卷

使用vdo命令来添加,其中name参数代表新的设备卷的名称;device参数代表由哪块磁盘进行制作;vdoLogicalSize参数代表制作后的设备大小。依据红帽公司推荐的原则,20GB硬盘将翻成200GB的逻辑存储:

[root@localhost ~]# vdo create --name=sotrage --device=/dev/nvme0n2  --vdoLogicalSize=200G
Creating VDO sotrage
Starting VDO sotrage
Starting compression on VDO sotrage
VDO instance 0 volume is ready at /dev/mapper/sotrage
三、查看新建卷的详细信息

新创建的卷存放在/dev/mapper目录下

[root@localhost ~]# vdo status --name=sotrage
VDO status:
  Date: '2021-10-20 00:41:43+08:00'
  Node: localhost.localdomain
Kernel module:
  Loaded: true
  Name: kvdo
  Version information:
    kvdo version: 6.2.0.293
Configuration:
  File: /etc/vdoconf.yml
  Last modified: '2021-10-20 00:40:59'
VDOs:
  sotrage:
    Acknowledgement threads: 1
    Activate: enabled
    Bio rotation interval: 64
    Bio submission threads: 4
    Block map cache size: 128M
    Block map period: 16380
    Block size: 4096
    CPU-work threads: 2
    Compression: enabled
    Configured write policy: auto
    Deduplication: enabled
    Device mapper status: 0 419430400 vdo /dev/nvme0n2 normal - online online 1051408 5242880
    ......
四、对新建卷进行格式化并挂载使用
[root@localhost ~]# mkfs.xfs /dev/mapper/sotrage 
meta-data=/dev/mapper/sotrage    isize=512    agcount=4, agsize=13107200 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=52428800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=25600, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# udevadm settle
[root@localhost ~]# mkdir /sotrage
[root@localhost ~]# mount /dev/mapper/sotrage /sotrage/
五、查看设备使用的情况

使用命令vdostats查看 ,human-readable参数的作用是将存储容量自动进位,以人们更易读的方式输出(比如,显示20G而不是20971520K)

[root@localhost ~]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/sotrage      20.0G      4.0G     16.0G  20%           99%
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               889M     0  889M   0% /dev
tmpfs                  904M     0  904M   0% /dev/shm
tmpfs                  904M  9.7M  894M   2% /run
tmpfs                  904M     0  904M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  3.9G   14G  23% /
/dev/nvme0n1p1        1014M  169M  846M  17% /boot
tmpfs                  181M   16K  181M   1% /run/user/42
tmpfs                  181M  2.3M  179M   2% /run/user/1000
/dev/sr0               6.7G  6.7G     0 100% /media/cdrom
tmpfs                  181M  4.0K  181M   1% /run/user/0
/dev/mapper/sotrage    200G  1.5G  199G   1% /sotrage

六、存放文件测试
[root@localhost ~]# ls -lh /media/cdrom/images/install.img 
-r--r--r--. 1 roo roo 448M Apr  4  2019 /media/cdrom/images/install.img
[root@localhost ~]# cp /media/cdrom/images/install.img /sotrage/
[root@localhost ~]# ls -lh /sotrage/install.img 
-r--r--r--. 1 root root 448M Oct 20 00:45 /sotrage/install.img
[root@localhost ~]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/sotrage      20.0G      4.4G     15.6G  22%           18%
[root@localhost ~]# cp /media/cdrom/images/install.img /sotrage/
cp: overwrite '/sotrage/install.img'? ^C 
[root@localhost ~]# cp /media/cdrom/images/install.img /sotrage/ss.img
[root@localhost ~]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/sotrage      20.0G      4.5G     15.5G  22%           55%

可以看到第二次拷贝过去同样的文件,只占用了100M的空间

七、永久挂载使用
[root@localhost ~]# blkid /dev/mapper/sotrage 
/dev/mapper/sotrage: UUID="e1b143ff-e663-4ca8-8e82-959430835086" TYPE="xfs"
[root@localhost ~]# vi /etc/fstab 
# /etc/fstab
# Created by anaconda on Wed Mar 17 00:16:10 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=72e9e1b7-3326-413e-956f-d2ee7e41ad4a /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
UUID="e1b143ff-e663-4ca8-8e82-959430835086"  /storage  xfs   defaults,_netdev             0 0
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/335814.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号