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

一个月考取RHCE【第九天】

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

一个月考取RHCE【第九天】

1、SWAP分区

        SWAP分区是一种通过在硬盘中预先划分一定的空间,然后把内存中暂时不常用的数据临时存放到硬盘中,以便腾出物理内存空间让更活跃的程序服务来使用的技术,其设计目的是为了解决真实物理内存不足的问题。

实验:
先添加一块SCSI或者SATA硬盘
[root@linuxprobe ~]# 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 0x4cfc9668.

Command (m for help): n【创建一个分区】
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): e【创建一个拓展分区】
Partition number (1-4, default 1): 直接回车
First sector (2048-41943039, default 2048): 直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +3G【创建3G拓展分区】

Created a new partition 1 of type 'Extended' and of size 3 GiB.

Command (m for help): p【查看分区】
Disk /dev/sdb: 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
Disklabel type: dos
Disk identifier: 0x4cfc9668

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 6293503 6291456   3G  5 Extended

Command (m for help): n
Partition type
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l【创建逻辑分区】

Adding logical partition 5
First sector (4096-6293503, default 4096): 直接回车
Last sector, +sectors or +size{K,M,G,T,P} (4096-6293503, default 6293503): +2G【2G的逻辑分区】

Created a new partition 5 of type 'Linux' and of size 2 GiB.

Command (m for help): p【查看分区】
Disk /dev/sdb: 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
Disklabel type: dos
Disk identifier: 0x4cfc9668

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 6293503 6291456   3G  5 Extended
/dev/sdb5        4096 4198399 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@linuxprobe ~]# partprobe 【手动同步分区信息至内核】
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@linuxprobe ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8,  0 Oct 28 14:31 /dev/sda
brw-rw----. 1 root disk 8,  1 Oct 28 14:31 /dev/sda1
brw-rw----. 1 root disk 8,  2 Oct 28 14:31 /dev/sda2
brw-rw----. 1 root disk 8, 16 Oct 28 14:31 /dev/sdb
brw-rw----. 1 root disk 8, 17 Oct 28 14:31 /dev/sdb1
brw-rw----. 1 root disk 8, 21 Oct 28 14:31 /dev/sdb5

[root@linuxprobe ~]# mkswap /dev/sdb5【对交换分区进行格式化】
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=5c0548b2-1770-4de2-8efe-72653e226e07
[root@linuxprobe ~]# free -m 【查看内存】
              total        used        free      shared  buff/cache   available
Mem:           1966        1298         136          11         530         491
Swap:          2047           1        2046
[root@linuxprobe ~]# swapon /dev/sdb5【激活新的交换分区设备,挂载】
[root@linuxprobe ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1966        1300         123          11         542         489
Swap:          4095           1        4094
[root@linuxprobe ~]# vim /etc/fstab 【永久挂载】
[root@linuxprobe ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Sun Oct 10 14:16:07 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=510c4a0a-d775-44ad-bcab-3f4a612274d1 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
/dev/sdb5    swap    swap    defaults    0    0
[root@linuxprobe ~]# reboot


2、磁盘配额

软限制:当达到软限制时会提示用户,但仍允许用户在限定的额度内继续使用。
        isoft、bsoft
硬限制:当达到硬限制时会提示用户,且强制终止用户的操作。
  ihard、bhard

实验
1、修改配置文件使其支持uquota技术
Ext文件系统为usrquota,xfs文件系统为uquota

[root@linuxprobe ~]# cat /etc/fstab 【修改文件支持uquota技术】

#
# /etc/fstab
# Created by anaconda on Sun Oct 10 14:16:07 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=510c4a0a-d775-44ad-bcab-3f4a612274d1 /boot                   xfs     defaults,uquota        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
/dev/sdb5    swap    swap    defaults    0    0
需重启看下配置是否生效
[root@linuxprobe ~]# mount | grep /boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

用户组@linuxprobe

2、验证结果
[root@linuxprobe ~]# id linuxprobe
uid=1000(linuxprobe) gid=1000(linuxprobe) groups=1000(linuxprobe)
[root@linuxprobe ~]# chmod -R 777 /boot/
[root@linuxprobe ~]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 linuxprobe' /boot/
[root@linuxprobe ~]# xfs_quota -x -c report /boot/
User quota on /boot (/dev/sda1)
                               Blocks                     
User ID          Used       Soft       Hard    Warn/Grace     
---------- -------------------------------------------------- 
root           115048          0          0     00 [--------]
linuxprobe          0       3072       6144     00 [--------]

[root@linuxprobe ~]# su - linuxprobe
[linuxprobe@linuxprobe ~]$ cd /boot/
[linuxprobe@linuxprobe boot]$ touch a b c d e f
[linuxprobe@linuxprobe boot]$ touch g
touch: cannot touch 'g': Disk quota exceeded
[linuxprobe@linuxprobe boot]$ rm -f a b c d e f 
[linuxprobe@linuxprobe boot]$ dd if=/dev/zero of=haha bs=3M count=1
1+0 records in
1+0 records out
3145728 bytes (3.1 MB, 3.0 MiB) copied, 0.0026337 s, 1.2 GB/s
[linuxprobe@linuxprobe boot]$ dd if=/dev/zero of=haha bs=7M count=1【创建一个7M的文件】
dd: error writing 'haha': Disk quota exceeded
1+0 records in
0+0 records out
4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.011413 s, 368 MB/s

修改磁盘配额【需root权限】
[linuxprobe@linuxprobe boot]$ exit
logout
[root@linuxprobe ~]# edquota -u linuxprobe【修改磁盘配额】

Disk quotas for user linuxprobe (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda1                      4096       3072       6144          1        3        6
 

3、VDO

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

4、链接文件

软链接(soft link):也叫符号链接(symbolic link),相当于快捷方式。删除源文件连接文件不能访问。

硬链接(hard link):删除源文件链接文件也可访问。系统会创建出一个与原来一模一样的inode信息块。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361222.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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