swap分区,lvm的管理及计划任务

文章目录

  • swap分区,lvm的管理及计划任务
    • 一.swap分区的管理
      • 1.swap分区的创建
        • 1.1 用分区创建交换分区
        • 1.2 文件的创建
      • 2.格式化swap分区
        • 2.1 格式化swap,首先要卸载分区
        • 2.2 永久挂载
      • 2.3 格式化分区
      • 3. 检测swap分区
      • 4. 开启新建的swap分区
      • 5. 关闭新建的swap分区
      • 6. 查看swap分区由哪些设备组成 ` swapon -s `
      • 7. 生产磁盘故障案例
        • 7.1 Inode被占满,导致磁盘有可用的剩余空间也无法继续使用
        • 7.2 Block空间即将被占满, 但删除大文件也没有释放空间
    • 二. lvm管理
      • 1. lvm的应用场景及其弊端
      • 2. 物理卷(pv)卷组(vg)逻辑卷(lv)
      • 3. 部署lvm
        • 3.1 **创建lvm步骤:**
      • 3.2 部署lvm
      • 4. 卷组管理
      • 5. 逻辑卷管理
        • 5.1 辑卷扩展,逻辑卷的扩展取决于卷组中的容量,逻辑卷扩展的容量不能超过卷组的容量
        • 5.2 对`ext4`文件系统的逻辑卷裁剪容量
      • 6. 作业
    • 三. 计划任务
      • 1. 计划任务的概述

一.swap分区的管理

交换分区SWAP就是LINUX下的虚拟内存分区,它的作用是在物理内存使用完之后,将磁盘空间(SWAP分区)虚拟成内存来使用。

交换分区一般指定虚拟内存的大小为实际内存的1.5~2倍。(真实内存2g/8g,虚拟内存4g/16g)如果虚拟内存不够用的情况,须增加一个虚拟磁盘,由于不能给原有的磁盘重新分区,所以可以选择新建。

1.swap分区的创建

1.1 用分区创建交换分区
Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 82Changed type of partition 'Linux' to 'Linux swap / Solaris'.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: 0xfb278e8dDevice     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2254847 1228800  600M 83 Linux
/dev/sdb3       2254848 3074047  819200  400M 82 Linux swap / SolarCommand (m for help): w
  • free /free -m 显示系统使用和空闲的内存情况/以兆显示

  • [root@SYL3 ~]# free总内存      使用内存       剩余内存    共享内存         缓冲/缓存
    剩余可用              total        used        free      shared  buff/cache   available
    Mem:        1833232      266888     1128788        8936      437556     1401304
    Swap:       2097148           0     2097148
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         260        1102           8         427        1368
    Swap:          2047           0        2047
    [root@SYL3 ~]# 
1.2 文件的创建
[root@SYL3 ~]# dd if=/dev/zero of=/opt/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.63056 s, 162 MB/s
[root@SYL3 ~]# du -sh /opt/swapfile
1.0G    /opt/swapfile

2.格式化swap分区

2.1 格式化swap,首先要卸载分区
[root@SYL3 ~]# mkswap /dev/sdb3   //将sdb3格式化成swap
mkswap: /dev/sdb3: warning: wiping old xfs signature.
Setting up swapspace version 1, size = 400 MiB (419426304 bytes)
no label, UUID=e275b98c-eb93-4b5d-826f-c97c24414f5c
[root@SYL3 ~]# blkid /dev/sdb3   //查找sdb3的UUID
/dev/sdb3: UUID="e275b98c-eb93-4b5d-826f-c97c24414f5c" TYPE="swap" PARTUUID="fb278e8d-03"
[root@SYL3 ~]# vim /etc/fstab  //永久挂载swap空间
[root@SYL3 ~]# cat /etc/fstab |grep swap
/dev/mapper/rhel-swap   none                    swap    defaults        0 0
UUID 挂载点 挂载文件类型 挂载参数  不检查 不备份
UUID="e275b98c-eb93-4b5d-826f-c97c24414f5c" swap swap  defaults   0 0
[root@SYL3 ~]# mount -a  //加载
[root@SYL3 ~]# free -m   //显示swap分区情况以m显示total        used        free      shared  buff/cache   available
Mem:           1790         268        1127           8         394        1361
Swap:          2047           0        2047
[root@SYL3 ~]# swapon UUID="e275b98c-eb93-4b5d-826f-c97c24414f5c"  //立即开启swap分区
[root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1790         268        1127           8         394        1361
Swap:          2447           0        2447
[root@SYL3 ~]#
[root@SYL3 ~]# swapoff /dev/sdb3  立即关闭swap分区
[root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1790         268        1126           8         395        1361
Swap:          2047           0        2047
[root@SYL3 ~]#
2.2 永久挂载
[root@SYL3 ~]# vim /etc/fstab  //永久挂载swap空间
[root@SYL3 ~]# cat /etc/fstab |grep swap
/dev/mapper/rhel-swap   none                    swap    defaults        0 0
UUID 挂载点 挂载文件类型 挂载参数  不检查 不备份
UUID="e275b98c-eb93-4b5d-826f-c97c24414f5c" swap swap  defaults   0 0

2.3 格式化分区

[root@SYL3 ~]# dd if=/dev/zero of=/opt/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.63056 s, 162 MB/s
[root@SYL3 ~]# du -sh /opt/swapfile
1.0G    /opt/swapfile
[root@SYL3 ~]# mkswap -f /opt/swapfile   //文件的形式前面加-f
mkswap: /opt/swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=2cd66081-fc68-4dda-887e-5133f41cf0cb
[root@SYL3 ~]# chmod 600 /opt/swapfile
[root@SYL3 ~]# vi /etc/fstab
[root@SYL3 ~]# tail -1 /etc/fstab
/opt/swapfile swap swap defaults   0 0
[root@SYL3 ~]# mount -a
[root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1790         267          95           8        1426        1360
Swap:          2047           0        2047
[root@SYL3 ~]# swapon /opt/swapfile
[root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1790         269          94           8        1426        1359
Swap:          3071           0        3071
[root@SYL3 ~]# swapoff /opt/swapfile
[root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
Mem:           1790         269          93           8        1427        1359
Swap:          2047           0        2047
[root@SYL3 ~]# 

3. 检测swap分区

1.检查sdb3的swap分区

  • [root@SYL3 ~]# free -m   //显示swap分区情况以m显示total        used        free      shared  buff/cache   available
    Mem:           1790         268        1127           8         394        1361
    Swap:          2047           0        2047
    

4. 开启新建的swap分区

1.开启sdb3swap分区

  • [root@SYL3 ~]# swapon UUID="e275b98c-eb93-4b5d-826f-c97c24414f5c"  //立即开启swap分区
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         268        1127           8         394        1361
    Swap:          2447           0        2447
    

2.开启

  • [root@SYL3 ~]# swapon /opt/swapfile
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         269          94           8        1426        1359
    Swap:          3071           0        3071
    

3.开启所有的 swapon -a

  • [root@SYL3 ~]# swapon -a
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         269          92           8        1428        1358
    Swap:          3471           0        3471
    

5. 关闭新建的swap分区

1.立即关闭sdb3

  • [root@SYL3 ~]# swapoff /dev/sdb3  立即关闭swap分区
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         268        1126           8         395        1361
    Swap:          2047           0        2047
    [root@SYL3 ~]#
    

2.关闭用文件创建的swap

  • [root@SYL3 ~]# swapoff /opt/swapfile
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         269          93           8        1427        1359
    Swap:          2047           0        2047
    [root@SYL3 ~]#
    

3.关闭所有的 swapoff -a

  • [root@SYL3 ~]# swapoff -a
    [root@SYL3 ~]# free -mtotal        used        free      shared  buff/cache   available
    Mem:           1790         267          95           8        1427        1361
    Swap:             0           0           0

6. 查看swap分区由哪些设备组成 swapon -s

  • [root@SYL3 ~]# swapon -a
    [root@SYL3 ~]# swapon -s
    Filename                                Type            Size    Used       Priority
    /dev/dm-1                               partition       2097148 0 -2
    /dev/sdb3                               partition       409596  0 -3
    /opt/swapfile                           file            1048572 0 -4
    [root@SYL3 ~]#
    

7. 生产磁盘故障案例

生成一个分区

[root@SYL3 ~]# dd if=/dev/zero of=mushuang bs=1k count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00189487 s, 553 MB/s
[root@SYL3 ~]# du -sh *
4.0K    1.1.txt
4.0K    anaconda-ks.cfg
1.0M    mushuang
[root@SYL3 ~]# mkfs.ext4 -i 1024 mushuang
mke2fs 1.45.6 (20-Mar-2020)Filesystem too small for a journal
Discarding device blocks: done
Creating filesystem with 1024 1k blocks and 1024 inodesAllocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done[root@SYL3 ~]# mount -t ext4 -o loop mushuang /data
[root@SYL3 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               877M     0  877M   0% /dev
tmpfs                  896M  8.8M  887M   1% /run
tmpfs                  896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  3.0G   15G  18% /
tmpfs                  180M     0  180M   0% /run/user/0
/dev/sda1             1014M  212M  803M  21% /boot
/dev/sdb1              477M  2.3M  445M   1% /media
/dev/loop0             891K   21K  799K   3% /data
7.1 Inode被占满,导致磁盘有可用的剩余空间也无法继续使用
  • [root@SYL3 ~]# touch /data/{1..5000}
    [root@SYL3 data]# ls ????
    1000  1002  1004  1006  1008  1010  1012
    1001  1003  1005  1007  1009  1011  1013
    [root@SYL3 data]#
    [root@SYL3 ~]# df -h //磁盘内存没用完
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M  8.8M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  3.0G   15G  18% /
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sda1             1014M  212M  803M  21% /boot
    /dev/sdb1              477M  2.3M  445M   1% /media
    /dev/loop0             891K   39K  781K   5% /data
    [root@SYL3 ~]#
    [root@SYL3 ~]# df -i  //可以看出indoes用完
    Filesystem             Inodes IUsed   IFree IUse% Mounted on
    devtmpfs               224354   438  223916    1% /dev
    tmpfs                  229154   647  228507    1% /run
    tmpfs                  229154    17  229137    1% /sys/fs/cgroup
    /dev/mapper/rhel-root 8910848 41377 8869471    1% /
    tmpfs                  229154     5  229149    1% /run/user/0
    /dev/sda1              524288   310  523978    1% /boot
    /dev/sdb1              128016    11  128005    1% /media
    /dev/loop0               1024  1024       0  100% /data
    [root@SYL3 ~]# 
7.2 Block空间即将被占满, 但删除大文件也没有释放空间

假设现在线上正在运行Nginx服务, Nginx产生的日志已经达到了20个G, 磁盘眼看就看沾满了, 请问不重启Nginx的方式如何处理

//是会删除文件, 但Nginx持续占用着文件, 所以空间并不会被释放
rm -f access.log//正确做法如下, 清空该文件即可释放文件内容
> access.log
  • [root@SYL3 ~]# httpd
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe88:169d%ens160. Set the 'ServerName' directive globally to suppress this message
    [root@SYL3 ~]# ss -antl
    State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process
    LISTEN 0      128          0.0.0.0:22         0.0.0.0:*
    LISTEN 0      128                *:80               *:*
    LISTEN 0      128             [::]:22            [::]:*
    [root@SYL3 ~]# cd /usr/local/httpd/
    [root@SYL3 httpd]# cd logs/
    [root@SYL3 logs]# ll
    total 12
    -rw-r--r--. 1 root root  589 Apr 11 13:08 access_log
    -rw-r--r--. 1 root root 1860 Apr 11 15:56 error_log
    -rw-r--r--. 1 root root    7 Apr 11 15:56 httpd.pid
    [root@SYL3 logs]# 
  • [root@SYL3 logs]# dd if=/dev/zero of=access_log bs=1M count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB, 1.0 GiB) copied, 37.9985 s, 28.3 MB/s
    [root@SYL3 logs]# du -sh *
    1.0G    access_log
    4.0K    error_log
    4.0K    httpd.pid
    [root@SYL3 logs]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M  8.8M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  4.0G   14G  24% /
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sda1             1014M  212M  803M  21% /boot
    /dev/sdb1              477M  2.3M  445M   1% /media
    /dev/loop0             891K   39K  781K   5% /data
    [root@SYL3 logs]# rm -f access_log
    [root@SYL3 logs]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M  8.8M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  4.0G   14G  24% /
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sda1             1014M  212M  803M  21% /boot
    /dev/sdb1              477M  2.3M  445M   1% /media
    /dev/loop0             891K   39K  781K   5% /data
    [root@SYL3 logs]# service httpd stop
    Redirecting to /bin/systemctl stop httpd.service
    Failed to stop httpd.service: Unit httpd.service not loaded.
    [root@SYL3 logs]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M  8.8M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  4.0G   14G  24% /
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sda1             1014M  212M  803M  21% /boot
    /dev/sdb1              477M  2.3M  445M   1% /media
    /dev/loop0             891K   39K  781K   5% /data
  • 不停止删除

  • [root@SYL3 logs]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M  8.8M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  6.0G   12G  36% /
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sda1             1014M  212M  803M  21% /boot
    /dev/sdb1              477M  2.3M  445M   1% /media
    /dev/loop0             891K   39K  781K   5% /data
    [root@SYL3 logs]# 

二. lvm管理

1. lvm的应用场景及其弊端

应用场景:
随着公司的发展,数据增长较快,最初规划的磁盘容量不够用了

弊端:
数据不是直接存放在硬盘上,而是在硬盘的上面又虚拟出来一层逻辑卷存放数据,故而增加了磁盘数据恢复的难度

2. 物理卷(pv)卷组(vg)逻辑卷(lv)

物理卷(PV):把常规的块设备(硬盘,分区等可以读写数据的设备)通过pvcreate命令对其进行初始化,就成了物理卷

卷组(VG):把多个物理卷的容量组成一个逻辑整体,可以从里面灵活分配容量

逻辑卷(LV):从卷组中划分部分空间成为一个可以读写数据的逻辑单元。需要对其格式化然后挂载使用

3. 部署lvm

3.1 创建lvm步骤:
  1. 添加物理磁盘,创建物理卷
  2. 创建卷组,将物理卷加入卷组
  3. 在卷组中划分逻辑卷
  4. 格式化逻辑卷
  5. 挂载使用

3.2 部署lvm

[root@SYL3 ~]# pvsPV         VG   Fmt  Attr PSize   PFree/dev/sda2  rhel lvm2 a--  <19.00g    0
[root@SYL3 ~]# pvcreate /dev/sdb  //初始化sdbPhysical volume "/dev/sdb" successfully created.
[root@SYL3 ~]# pvs //检查pv创建情况PV         VG   Fmt  Attr PSize   PFree/dev/sda2  rhel lvm2 a--  <19.00g    0 /dev/sdb        lvm2 ---    5.00g 5.00g
[root@SYL3 ~]# vgcreate mushuang /dev/sdb //创建卷组Volume group "mushuang" successfully created
[root@SYL3 ~]# vgs //检查卷组VG       #PV #LV #SN Attr   VSize   VFree mushuang   1   0   0 wz--n-  <5.00g <5.00grhel       1   2   0 wz--n- <19.00g     0
[root@SYL3 ~]# lvcreate -L 500M -n lv1 mushuang //创建逻辑卷,-L 指定大小, -n指定名称 在哪个卷组上
Logical volume "lv1" created.
[root@SYL3 ~]# lvs  //检查逻辑卷LV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv1  mushuang -wi-a----- 500.00m                                                    root rhel     -wi-ao---- <17.00g                                                    swap rhel     -wi-ao----   2.00g
[root@SYL3 ~]# mkfs.xfs /dev/mushuang/lv1  格式化文件系统
meta-data=/dev/mushuang/lv1      isize=512    agcount=4, agsize=32000 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
data     =                       bsize=4096   blocks=128000, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@SYL3 ~]# blkid /dev/mushuang/lv1 //查看UUID
/dev/mushuang/lv1: UUID="3a2c7c2f-9632-47c9-9331-43c43b3e5867" BLOCK_SIZE="512" TYPE="xfs"
[root@SYL3 ~]# vi /etc/fstab  //永久挂载
[root@SYL3 ~]# cat /etc/fstab | grep UUID
UUID=35fc3533-8bca-4e7e-8b24-362dd3ac7b90 /boot                   xfs     defaults        0 0
UUID="3a2c7c2f-9632-47c9-9331-43c43b3e5867" /data xfs defaults        0 0
[root@SYL3 ~]# mount -a
[root@SYL3 ~]# df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                  877M     0  877M   0% /dev
tmpfs                     896M     0  896M   0% /dev/shm
tmpfs                     896M  8.8M  887M   1% /run
tmpfs                     896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root      17G  1.7G   16G  10% /
/dev/sda1                1014M  212M  803M  21% /boot
tmpfs                     180M     0  180M   0% /run/user/0
/dev/mapper/mushuang-lv1  495M   29M  466M   6% /data
[root@SYL3 ~]#

4. 卷组管理

  • 扩展卷组,将新磁盘加入卷组

  • [root@SYL3 ~]# pvcreate /dev/sdcPhysical volume "/dev/sdc" successfully created.
    [root@SYL3 ~]# pvsPV         VG       Fmt  Attr PSize   PFree /dev/sda2  rhel     lvm2 a--  <19.00g     0 /dev/sdb   mushuang lvm2 a--   <5.00g <4.51g/dev/sdc            lvm2 ---   10.00g 10.00g
    [root@SYL3 ~]# vgextend mushuang /dev/sdcVolume group "mushuang" successfully extended
    [root@SYL3 ~]# vgsVG       #PV #LV #SN Attr   VSize   VFree mushuang   2   1   0 wz--n-  14.99g 14.50grhel       1   2   0 wz--n- <19.00g     0
    [root@SYL3 ~]# 
  • 缩减卷组,将指定磁盘从卷组中删除

  • [root@SYL3 ~]# vgreduce mushuang /dev/sdcRemoved "/dev/sdc" from volume group "mushuang"
    [root@SYL3 ~]# vgsVG       #PV #LV #SN Attr   VSize   VFree mushuang   1   1   0 wz--n-  <5.00g <4.51grhel       1   2   0 wz--n- <19.00g     0
    [root@SYL3 ~]# 
  • 数据迁移卷组,同一卷组的磁盘才可以进行在线迁移,里面的文件不变

  • [root@SYL3 ~]# cd /data/
    [root@SYL3 data]# dd if=/dev/zero of=/data/test bs=200M count=2
    2+0 records in
    2+0 records out
    419430400 bytes (419 MB, 400 MiB) copied, 7.13043 s, 58.8 MB/s
    [root@SYL3 data]# echo 'hello' > abc
    [root@SYL3 data]# ls
    abc  test
    [root@SYL3 data]# cat abc
    hello
    [root@SYL3 ~]# pvsPV         VG       Fmt  Attr PSize   PFree  /dev/sda2  rhel     lvm2 a--  <19.00g      0 /dev/sdb   mushuang lvm2 a--   <5.00g  <4.51g/dev/sdc   mushuang lvm2 a--  <10.00g <10.00g
    [root@SYL3 ~]# pvmove /dev/sdb/dev/sdb: Moved: 11.20%/dev/sdb: Moved: 100.00%
    [root@SYL3 ~]# pvsPV         VG       Fmt  Attr PSize   PFree /dev/sda2  rhel     lvm2 a--  <19.00g     0 /dev/sdb   mushuang lvm2 a--   <5.00g <5.00g/dev/sdc   mushuang lvm2 a--  <10.00g <9.51g
    [root@SYL3 data]# cat abc
    hello
    [root@SYL3 data]# du -sh *
    4.0K    abc
    400M    test
    [root@SYL3 data]#
    

5. 逻辑卷管理

5.1 辑卷扩展,逻辑卷的扩展取决于卷组中的容量,逻辑卷扩展的容量不能超过卷组的容量
  • 扩展到800M给Lv

  • 增加800M分配给逻辑卷

  • [root@SYL3 ~]# lvextend -L 500M /dev/mushuang/lv1New size (125 extents) matches existing size (125 extents).
    [root@SYL3 ~]# lvsLV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv1  mushuang -wi-ao---- 500.00m                                                    root rhel     -wi-ao---- <17.00g                                                    swap rhel     -wi-ao----   2.00g
    [root@SYL3 ~]# lvextend -L +500M /dev/mushuang/lv1Size of logical volume mushuang/lv1 changed from 500.00 MiB (125 extents) to 1000.00 MiB (250 extents).Logical volume mushuang/lv1 successfully resized.
    [root@SYL3 ~]# lvsLV   VG       Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv1  mushuang -wi-ao---- 1000.00m                                                    root rhel     -wi-ao----  <17.00g                                                    swap rhel     -wi-ao----    2.00g
    [root@SYL3 ~]# 
  • 分配磁盘池中多少百分比给逻辑卷

  • [root@SYL3 ~]# lvextend -l +50%FREE /dev/mushuang/lv1Size of logical volume mushuang/lv1 changed from 1000.00 MiB (250 extents) to 7.98 GiB (2044 extents).Logical volume mushuang/lv1 successfully resized.
    [root@SYL3 ~]# vgsVG       #PV #LV #SN Attr   VSize   VFree mushuang   2   1   0 wz--n-  14.99g <7.01grhel       1   2   0 wz--n- <19.00g     0
    [root@SYL3 ~]# 
  • 扩展fs文件系统

  • xfs扩容— xfs_growfs /dev/mushuang/lv1

  • [root@SYL3 ~]# df -T
    Filesystem               Type     1K-blocks    Used Available Use% Mounted on
    devtmpfs                 devtmpfs    897416       0    897416   0% /dev
    tmpfs                    tmpfs       916616       0    916616   0% /dev/shm
    tmpfs                    tmpfs       916616    8920    907696   1% /run
    tmpfs                    tmpfs       916616       0    916616   0% /sys/fs/cgroup
    /dev/mapper/rhel-root    xfs       17811456 1763548  16047908  10% /
    /dev/sda1                xfs        1038336  216572    821764  21% /boot
    tmpfs                    tmpfs       183320       0    183320   0% /run/user/0
    /dev/mapper/mushuang-lv1 xfs        8366752  497240   7869512   6% /data
    [root@SYL3 ~]# xfs_growfs /dev/mushuang/lv1
    meta-data=/dev/mapper/mushuang-lv1 isize=512    agcount=4, agsize=32000 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
    data     =                       bsize=4096   blocks=128000, imaxpct=25=                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
    log      =internal log           bsize=4096   blocks=1368, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 128000 to 2093056
    [root@SYL3 ~]# df -h
    Filesystem                Size  Used Avail Use% Mounted on
    devtmpfs                  877M     0  877M   0% /dev
    tmpfs                     896M     0  896M   0% /dev/shm
    tmpfs                     896M  8.8M  887M   1% /run
    tmpfs                     896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root      17G  1.7G   16G  10% /
    /dev/sda1                1014M  212M  803M  21% /boot
    tmpfs                     180M     0  180M   0% /run/user/0
    /dev/mapper/mushuang-lv1  8.0G  486M  7.6G   6% /data
    [root@SYL3 ~]# 
  • ext扩容

  • [root@SYL3 ~]# lvextend -L +500M /dev/mushuang/lv2Size of logical volume mushuang/lv2 changed from 2.00 GiB (512 extents) to <2.49 GiB (637 extents).Logical volume mushuang/lv2 successfully resized.
    [root@SYL3 ~]# resize2fs /dev/mushuang/lv2
    resize2fs 1.45.6 (20-Mar-2020)
    Filesystem at /dev/mushuang/lv2 is mounted on /extfile; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/mushuang/lv2 is now 652288 (4k) blocks long.
    
5.2 对ext4文件系统的逻辑卷裁剪容量
  • 创建一个2g的逻辑卷
[root@SYL3 ~]# lvcreate -L 2G -n lv2 mushuang
WARNING: xfs signature detected on /dev/mushuang/lv2 at offset 0. Wipe it? [y/n]: yWiping xfs signature on /dev/mushuang/lv2.Logical volume "lv2" created.
[root@SYL3 ~]# mkfs.ext4 /dev/mushuang/lv2
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 07db6586-55a1-4070-93d7-2e96c975c52d
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done [root@SYL3 ~]# blkid /dev/mushuang/lv2
/dev/mushuang/lv2: UUID="07db6586-55a1-4070-93d7-2e96c975c52d" BLOCK_SIZE="4096" TYPE="ext4"
[root@SYL3 ~]# vi /etc/fstab
[root@SYL3 ~]# cat /etc/fstab | grep extfile
UUID="07db6586-55a1-4070-93d7-2e96c975c52d" /extfile ext4 defaults        0 0
[root@SYL3 ~]# mount -a
[root@SYL3 ~]# df -hT
Filesystem               Type      Size  Used Avail Use% Mounted on
devtmpfs                 devtmpfs  877M     0  877M   0% /dev
tmpfs                    tmpfs     896M     0  896M   0% /dev/shm
tmpfs                    tmpfs     896M  8.8M  887M   1% /run
tmpfs                    tmpfs     896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root    xfs        17G  1.7G   16G  10% /
/dev/sda1                xfs      1014M  212M  803M  21% /boot
tmpfs                    tmpfs     180M     0  180M   0% /run/user/0
/dev/mapper/mushuang-lv1 xfs       8.0G  486M  7.6G   6% /data
/dev/mapper/mushuang-lv2 ext4      2.0G  6.0M  1.8G   1% /extfile
[root@SYL3 ~]# lvextend -L +500M /dev/mushuang/lv2Size of logical volume mushuang/lv2 changed from 2.00 GiB (512 extents) to <2.49 GiB (637 extents).Logical volume mushuang/lv2 successfully resized.
[root@SYL3 ~]# resize2fs /dev/mushuang/lv2
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mushuang/lv2 is mounted on /extfile; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mushuang/lv2 is now 652288 (4k) blocks long.[root@SYL3 ~]# df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                  877M     0  877M   0% /dev
tmpfs                     896M     0  896M   0% /dev/shm
tmpfs                     896M  8.8M  887M   1% /run
tmpfs                     896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root      17G  1.7G   16G  10% /
/dev/sda1                1014M  212M  803M  21% /boot
tmpfs                     180M     0  180M   0% /run/user/0
/dev/mapper/mushuang-lv1  8.0G  486M  7.6G   6% /data
/dev/mapper/mushuang-lv2  2.4G  6.0M  2.3G   1% /extfile
[root@SYL3 ~]#
  • 如果已经挂载,必须先卸载,不卸载,其他用户写入文件,超过你空间的容量,会导致内容丢失

  • [root@SYL3 ~]# mkdir /extfile
    [root@SYL3 ~]# cp /etc/hosts /extfile/
    [root@SYL3 ~]# cat /extfile/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    [root@SYL3 ~]# lvsLV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv1  mushuang -wi-ao----   7.98g                                                    lv2  mushuang -wi-a-----  <2.49g                                                    root rhel     -wi-ao---- <17.00g                                                    swap rhel     -wi-ao----   2.00g     [root@SYL3 ~]# umount /extfile/
  • 裁剪容量,必须是先检测文件系统,在预缩减

  • [root@SYL3 ~]# e2fsck -f /dev/mushuang/lv2   //检测
    e2fsck 1.45.6 (20-Mar-2020)
    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/mushuang/lv2: 12/163840 files (0.0% non-contiguous), 28213/652288 blocks
    [root@SYL3 ~]# resize2fs /dev/mushuang/lv2 500M  //预缩减
    resize2fs 1.45.6 (20-Mar-2020)
    Resizing the filesystem on /dev/mushuang/lv2 to 128000 (4k) blocks.
    The filesystem on /dev/mushuang/lv2 is now 128000 (4k) blocks long.
  • 调整完毕后采取裁剪逻辑卷容量

  • [root@SYL3 ~]# lvreduce -L 500M /dev/mushuang/lv2WARNING: Reducing active logical volume to 500.00 MiB.THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce mushuang/lv2? [y/n]: ySize of logical volume mushuang/lv2 changed from <2.49 GiB (637 extents) to 500.00 MiB (125 extents).Logical volume mushuang/lv2 successfully resized.
  • 强烈建议裁剪后,再次检测文件系统

  • [root@SYL3 ~]# e2fsck -f /dev/mushuang/lv2
    e2fsck 1.45.6 (20-Mar-2020)
    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/mushuang/lv2: 12/32768 files (0.0% non-contiguous), 19218/128000 blocks
  • 挂载测试,如果能够挂载,一般说明裁剪成功,文件系统没有损坏

  • [root@SYL3 ~]# mount -a
    [root@SYL3 ~]# cat /extfile/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    [root@SYL3 ~]# lvsLV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertlv1  mushuang -wi-ao----   7.98g                                                    lv2  mushuang -wi-ao---- 500.00m                                                    root rhel     -wi-ao---- <17.00g                                                    swap rhel     -wi-ao----   2.00g
    

6. 作业

1.如何查看/etc/目录大小

[root@SYL3 ~]# du -sh /etc/
24M     /etc/
[root@SYL3 ~]#

2.如何查看磁盘使用分区情况

[root@SYL3 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               877M     0  877M   0% /dev
tmpfs                  896M     0  896M   0% /dev/shm
tmpfs                  896M  8.8M  887M   1% /run
tmpfs                  896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  3.0G   15G  18% /
/dev/sdb1              477M  2.3M  445M   1% /media
/dev/sda1             1014M  212M  803M  21% /boot
tmpfs                  180M     0  180M   0% /run/user/0
[root@SYL3 ~]#

3.如何查看inode使用情况

[root@SYL3 ~]# df -i
Filesystem             Inodes IUsed   IFree IUse% Mounted on
devtmpfs               224354   434  223920    1% /dev
tmpfs                  229154     1  229153    1% /dev/shm
tmpfs                  229154   652  228502    1% /run
tmpfs                  229154    17  229137    1% /sys/fs/cgroup
/dev/mapper/rhel-root 8910848 41376 8869472    1% /
/dev/sdb1              128016    11  128005    1% /media
/dev/sda1              524288   310  523978    1% /boot
tmpfs                  229154     5  229149    1% /run/user/0
[root@SYL3 ~]#

4.如何查看磁盘block使用情况

[root@SYL3 ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                 897416       0    897416   0% /dev
tmpfs                    916616       0    916616   0% /dev/shm
tmpfs                    916616    8948    907668   1% /run
tmpfs                    916616       0    916616   0% /sys/fs/cgroup
/dev/mapper/rhel-root  17811456 3124240  14687216  18% /
/dev/sdb1                487634    2318    455620   1% /media
/dev/sda1               1038336  216436    821900  21% /boot
tmpfs                    183320       0    183320   0% /run/user/0
[root@SYL3 ~]#

5.如何查看分区使用格式

[root@SYL3 ~]# df -T
Filesystem            Type     1K-blocks    Used Available Use% Mounted on
devtmpfs              devtmpfs    897416       0    897416   0% /dev
tmpfs                 tmpfs       916616       0    916616   0% /dev/shm
tmpfs                 tmpfs       916616    8948    907668   1% /run
tmpfs                 tmpfs       916616       0    916616   0% /sys/fs/cgroup
/dev/mapper/rhel-root xfs       17811456 3124240  14687216  18% /
/dev/sdb1             ext4        487634    2318    455620   1% /media
/dev/sda1             xfs        1038336  216436    821900  21% /boot
tmpfs                 tmpfs       183320       0    183320   0% /run/user/0
[root@SYL3 ~]#

6.如何查看一个设备的UUID

[root@SYL3 ~]# blkid
/dev/sda1: UUID="35fc3533-8bca-4e7e-8b24-362dd3ac7b90" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="9df1171a-01"
/dev/sda2: UUID="fI0vcs-e72I-1Yyw-rPtd-EAAN-sz2g-SBwals" TYPE="LVM2_member" PARTUUID="9df1171a-02"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-10-13-03-57-25-00" LABEL="RHEL-8-5-0-BaseOS-x86_64" TYPE="iso9660" PTUUID="4d694e6c" PTTYPE="dos"
/dev/mapper/rhel-root: UUID="14f507b0-8f31-4d89-8c21-7a9b7dae0e8f" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/rhel-swap: UUID="3f377df3-4664-4f19-883b-2c7fd6fd215c" TYPE="swap"

7.请解释/etc/fstab中每段含义

[root@SYL3 ~]# tail -1 /etc/fstab
/dev/mapper/rhel-swap   none                    swap    defaults        0 0
UUID/设备名                    挂载点 挂载文件类型  挂载参数 不检查 不备份
[root@SYL3 ~]#

8.一个ext4的文件分区,当使用touch test.file命令创建一个新文件是报错,报错的信息提示磁盘已满,但是采用df –h 命令查看磁盘大小时,只是用了60%的磁盘空间,为什么会出现这个情况,说说你的理由.
df -h 显示磁盘内存空间足够 ,用df -i 查看,显示磁盘的indoes使用满了

9.磁盘分区方案
在虚拟机中添加一块20GB的SCISI磁盘
在新硬盘中建立一个5GB的分区,一个10G的分区
一个格式化为ext4的文件系统, 一个格式化为xfs的文件系统
新建两个目录站点进行挂载, 要求开机自动挂载该分区

[root@SYL3 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@SYL3 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 3faf1c5b-7cfb-4f6d-b486-ed3a75af74dc
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done [root@SYL3 ~]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=655360 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
data     =                       bsize=4096   blocks=2621440, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@SYL3 ~]# [root@SYL3 ~]# mkdir /mu
[root@SYL3 ~]# mkdir /shuang
[root@SYL3 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="3faf1c5b-7cfb-4f6d-b486-ed3a75af74dc" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="8f5c46bd-01"
[root@SYL3 ~]# blkid /dev/sdb2
/dev/sdb2: UUID="b8c468df-a10c-4f43-aefe-9c78fcb3e9b7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="8f5c46bd-02"[root@SYL3 ~]# vi /etc/fstab
[root@SYL3 ~]# cat /etc/fstab | grep UUID
UUID=35fc3533-8bca-4e7e-8b24-362dd3ac7b90 /boot                   xfs     defaults        0 0
UUID="3faf1c5b-7cfb-4f6d-b486-ed3a75af74dc" /mu ext4 defaults        0 0
UUID="b8c468df-a10c-4f43-aefe-9c78fcb3e9b7" /shuang xfs defaults        0 0
[root@SYL3 ~]# mount -a
[root@SYL3 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               877M     0  877M   0% /dev
tmpfs                  896M     0  896M   0% /dev/shm
tmpfs                  896M  8.8M  887M   1% /run
tmpfs                  896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  1.7G   16G  10% /
/dev/sda1             1014M  212M  803M  21% /boot
tmpfs                  180M     0  180M   0% /run/user/0
/dev/sdb1              4.9G   20M  4.6G   1% /mu
/dev/sdb2               10G  104M  9.9G   2% /shuang
[root@SYL3 ~]#

10.LVM磁盘管理方案
在虚拟机环境中,新添加两块SCISI硬盘设备,完成硬盘检测及分区

[root@SYL3 ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   20G  0 disk
|-sda1          8:1    0    1G  0 part /boot
`-sda2          8:2    0   19G  0 part |-rhel-root 253:0    0   17G  0 lvm  /`-rhel-swap 253:1    0    2G  0 lvm  [SWAP]
sdb             8:16   0    5G  0 disk
sdc             8:32   0   10G  0 disk
sr0            11:0    1 10.2G  0 rom
[root@SYL3 ~]# mkdir /box
[root@SYL3 ~]# mkdir /xfs
[root@SYL3 ~]#

建立逻辑卷mbvg, 格式化为ext4文件系统, 分配1G逻辑分区供/box目录使用

[root@SYL3 ~]# vgcreate mbvg /dev/sdbVolume group "mbvg" successfully created
[root@SYL3 ~]# lvcreate  -L 1G -n box mbvgLogical volume "box" created.
[root@SYL3 ~]# mkfs.ext4 /dev/mbvg/box
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 0fff59a7-0fb6-492a-bee8-e82fc6faf94f
Superblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done[root@SYL3 ~]#
[root@SYL3 ~]# blkid /dev/mbvg/box
/dev/mbvg/box: UUID="0fff59a7-0fb6-492a-bee8-e82fc6faf94f" BLOCK_SIZE="4096" TYPE="ext4"
[root@SYL3 ~]# vi /etc/fstab
[root@SYL3 ~]# cat /etc/fstab | grep ext4
[root@SYL3 ~]# cat /etc/fstab | grep ext4
UUID="0fff59a7-0fb6-492a-bee8-e82fc6faf94f" /box ext4 defaults        0 0

第二块逻辑分区, 格式化为xfs文件系统, 分配1G逻辑分区供/xfs目录使用

[root@SYL3 ~]# lvcreate  -L 1G -n xfs mbvgLogical volume "xfs" created.
[root@SYL3 ~]# mkfs.xfs /dev/mbvg/xfs
meta-data=/dev/mbvg/xfs          isize=512    agcount=4, agsize=65536 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=1, sparse=1, rmapbt=0=                       reflink=1
data     =                       bsize=4096   blocks=262144, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@SYL3 ~]#
[root@SYL3 ~]# blkid /dev/mbvg/xfs
/dev/mbvg/xfs: UUID="4b1ad9bc-b95f-4d2e-b6d8-c20d42b9ba40" BLOCK_SIZE="512" TYPE="xfs"
[root@SYL3 ~]# vi /etc/fstab
[root@SYL3 ~]# cat /etc/fstab | grep xfs
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=35fc3533-8bca-4e7e-8b24-362dd3ac7b90 /boot                   xfs     defaults        0 0
UUID="4b1ad9bc-b95f-4d2e-b6d8-c20d42b9ba40" /xfs  xfs defaults        0 0
[root@SYL3 ~]# mount -a
[root@SYL3 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               877M     0  877M   0% /dev
tmpfs                  896M     0  896M   0% /dev/shm
tmpfs                  896M  8.8M  887M   1% /run
tmpfs                  896M     0  896M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  1.7G   16G  10% /
/dev/sda1             1014M  212M  803M  21% /boot
tmpfs                  180M     0  180M   0% /run/user/0
/dev/mapper/mbvg-box   976M  2.6M  907M   1% /box
/dev/mapper/mbvg-xfs  1014M   40M  975M   4% /xfs

最后使用扩容方案将/box站点扩展到2.8G磁盘使用空间, 将/xfs目录扩展到2G

[root@SYL3 ~]# lvextend -L 2.8G /dev/mbvg/box Rounding size to boundary between physical extents: 2.80 GiB.Size of logical volume mbvg/box changed from 1.00 GiB (256 extents) to 2.80 GiB (717 extents).Logical volume mbvg/box successfully resized.[root@SYL3 ~]# lvextend -L 2G /dev/mbvg/xfs Size of logical volume mbvg/xfs changed from 1.00 GiB (256 extents) to 2.00 GiB (512 extents).Logical volume mbvg/xfs successfully resized.
[root@SYL3 ~]# lvsLV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convertbox  mbvg -wi-ao----   1.00g                                                    xfs  mbvg -wi-ao----   2.00g                                                    root rhel -wi-ao---- <17.00g                                                    swap rhel -wi-ao----   2.00g
[root@SYL3 ~]#

三. 计划任务

1. 计划任务的概述

  • 什么是计划任务,计划在某一个时间段完成的任务
    在Linux系统的计划任务服务crond可以满足周期性执行任务的需求。
    crond进程每分钟会处理一次计划任务, 计划任务主要是做一些周期性的任务目前最主要的用途是定时备份数据

  • 一次性调度执行

  • [root@SYL3 ~]# systemctl status crond
    ● crond.service - Command SchedulerLoaded: loaded (/usr/lib/systemd/system/crond.service; >Active: active (running) since Mon 2022-04-11 21:00:11 >Main PID: 1128 (crond)Tasks: 2 (limit: 11216)Memory: 1.7MCGroup: /system.slice/crond.service├─1128 /usr/sbin/crond -n└─2946 /usr/sbin/anacron -s
    [root@SYL3 ~]# systemctl status atd
    ● atd.service - Job spooling toolsLoaded: loaded (/usr/lib/systemd/system/atd.service; en>Active: inactive (dead)
    [root@SYL3 ~]# systemctl start atd
    [root@SYL3 ~]# at 21:15
    warning: commands will be executed using /bin/sh
    at> touch 123456
    at> <EOT>
    job 1 at Mon Apr 11 21:15:00 2022
    [root@SYL3 ~]# ls
    1.1.txt  123456  anaconda-ks.cfg
    [root@SYL3 ~]# ll
    total 8
    -rw-r--r--. 1 root root 3025 Mar 22 16:37 1.1.txt
    -rw-r--r--. 1 root root    0 Apr 11 21:15 123456
    -rw-------. 1 root root 1093 Mar 22 16:26 anaconda-ks.cfg
    [root@SYL3 ~]#
    

期性的任务目前最主要的用途是定时备份数据

  • 一次性调度执行

  • [root@SYL3 ~]# systemctl status crond
    ● crond.service - Command SchedulerLoaded: loaded (/usr/lib/systemd/system/crond.service; >Active: active (running) since Mon 2022-04-11 21:00:11 >Main PID: 1128 (crond)Tasks: 2 (limit: 11216)Memory: 1.7MCGroup: /system.slice/crond.service├─1128 /usr/sbin/crond -n└─2946 /usr/sbin/anacron -s
    [root@SYL3 ~]# systemctl status atd
    ● atd.service - Job spooling toolsLoaded: loaded (/usr/lib/systemd/system/atd.service; en>Active: inactive (dead)
    [root@SYL3 ~]# systemctl start atd
    [root@SYL3 ~]# at 21:15
    warning: commands will be executed using /bin/sh
    at> touch 123456
    at> <EOT>
    job 1 at Mon Apr 11 21:15:00 2022
    [root@SYL3 ~]# ls
    1.1.txt  123456  anaconda-ks.cfg
    [root@SYL3 ~]# ll
    total 8
    -rw-r--r--. 1 root root 3025 Mar 22 16:37 1.1.txt
    -rw-r--r--. 1 root root    0 Apr 11 21:15 123456
    -rw-------. 1 root root 1093 Mar 22 16:26 anaconda-ks.cfg
    [root@SYL3 ~]#
    

swap分区,lvm的管理及计划任务相关推荐

  1. linux swap 分区调控(swap分区 lvm管理)

    注:linux swap分区 采用lvm管理,调控可以采用下面的方法 一.查看 swap    lv [root@testdb ~]# vgdisplay -v Finding all volume ...

  2. linux 标准分区 lvm,Linux lvm 分区知识笔记

    盘面上可以细分出扇区(Sector)与柱面(Cylinder)两种单位,其中扇区每个为512bytes那么大. 通常所说的"硬盘分区"就是指修改磁盘分区表,它定义了"第n ...

  3. swap分区管理方法

    swap分区管理方法 一.内存的认识 二.SWAP分区作用(内存暂存的地址-硬盘) 三.swap分区大小建议 四.swap管理 4.1创建swap分区 4.2swap临时调整优先级 4.2swap永久 ...

  4. 通过lvm方式扩展swap分区

    1.先将swap数据同步写入到硬盘 sync;sync;sync 添加硬盘逻辑卷(这个可以参考我前面的文章) https://blog.csdn.net/zetion_3/article/detail ...

  5. linux 1t 分区,Linux磁盘管理——swap分区

    对swap分区的误解 一种流行的.以讹传讹的说法是,安装Linux系统时,交换分区swap的大小应该是内存的两倍.也就是说,如果内存是2G,那么就应该分出4G的硬盘空间作为交换空间.其实这是严重的浪费 ...

  6. linux内存管理笔记(四十一)----swap分区

    前面我们学习了操作系统通过"虚拟内存"技术,不但在功能上突破了物理内存的限制,使程序可以操作大于实际物理内存的空间:更重要的是,隔离了每个进程的安全保护,使每个进程都不受其他程序的 ...

  7. CentOS 6.5 LVM磁盘管理学习笔记

    在系统运维和服务器管理过程中,经常遇到服务器磁盘容量不足,需要在线扩容的情况.普通磁盘分区的管理方式在逻辑分区划好之后就无法改变其大小.而LVM可以实现Linux服务器下面磁盘空间的在线扩容和动态管理 ...

  8. Linux--管理LVM逻辑卷 --原理+命令双结合(LVM的概述与建立,LVM的管理命令,LVM的应用步骤,磁盘配额的详解)

    Linux--管理LVM逻辑卷 --原理+命令双结合(LVM的概述与建立,LVM的管理命令,LVM的应用步骤,磁盘配额的详解) 前言 一:LVM概述 1.1:PV(Physical Volume,物理 ...

  9. 添加磁盘MBR,GPT,Swap分区和Linux文件系统

    MBR-GPT的区别:MBR的分区数是15,存储数据大小32位,最大分区容量是2TB:GPT又名:UEFI,分区数128,存储数据64位,最大容量到P 管理MBR磁盘和分区:MBR=512byte,b ...

  10. linux的SWAP分区

    linux的SWAP分区 from net 汇总网络信息,并进行测试验证,感谢网络. Linux SWAP 深度解读 https://blog.csdn.net/wh8_2011/article/de ...

最新文章

  1. python观察日志(part22)--设置工作目录及文件读取
  2. 工作207:修改表头按钮样式
  3. 红橙Darren视频笔记 IOC注解框架 了解xUtils3与ButterKnife的原理
  4. JAVA——网络编程
  5. 清华技术经理自学Python全栈的从业笔记,欢迎收藏
  6. 微信小程序 - 实现简单登录和个人信息页面
  7. mysql答题系统android_Android答题APP的设计与实现
  8. 正则表达式限制只能输入中文英文数字
  9. 因果推断-PSM的原理及python实现
  10. 基于MATLAB的数字信号处理(5) FIR数字滤波器设计及软件实现
  11. MIN-MAX归一化
  12. javaweb项目实现连续3次输错密码后禁止登录
  13. 大数据学习总结(2021版)---Mysql基础
  14. C1认证学习十一(常用网络命令以及端口)
  15. 10+编程语言实现云笔记
  16. int *a和(int *)a的区别
  17. Snapchat发布不到2个月的故事搜索功能,又双叒被Instagram抄袭了
  18. 【S0021】【素材】创意几何海报、h5背景
  19. 计算机游戏与动画技术课程,计算机游戏动画教学大纲.pdf
  20. google 天气rss

热门文章

  1. 将手机流氓软件彻底赶出去
  2. 【Faster R-CNN论文精度系列】原文精析
  3. RTX自动配置客户端服务器地址
  4. 修改IE地址栏Tomcat小猫咪图标
  5. 最优传输论文(十四):Generative Adversarial Nets论文原理
  6. ❥呕心沥血系列❥-- Linux基础
  7. 解决linux:docker-compose: Permission denied
  8. ECMAScript 6 入门教程
  9. linux入侵检测工具之aide
  10. 煤矸石无线测温系统项目背景