当前位置:   article > 正文

Centos7 /var目录扩容_centos7 var 空间不足

centos7 var 空间不足

Centos在随着使用时间增加,/var目录提示空间不足,以下有两种解决方案。其他目录类似操作

一、默认磁盘安装的/var目录

1、查看初始的磁盘目录

  1. [root@localhost ~]# df -HT
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root xfs 15G 1.1G 14G 8% /
  4. devtmpfs devtmpfs 8.4G 0 8.4G 0% /dev
  5. tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm
  6. tmpfs tmpfs 8.4G 18M 8.4G 1% /run
  7. tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup
  8. /dev/sda1 xfs 1.1G 153M 912M 15% /boot
  9. tmpfs tmpfs 1.7G 0 1.7G 0% /run/user/0

2、在/var目录编译安装nginx,演示生产环境应用(具体查看https://blog.csdn.net/tladagio/article/details/102551173

[root@localhost nginx-1.14.2]# ./configure --user=nginx --group=nginx --prefix=/var/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module

查看到安装路径

访问

3、服务器增加一块硬盘,分区并格式化(具体查看https://blog.csdn.net/tladagio/article/details/106347445

  1. [root@localhost ~]# fdisk /dev/sdb
  2. #查看结果
  3. Device Boot Start End Blocks Id System
  4. /dev/sdb1 2048 6291455 3144704 8e Linux LVM
  5. #创建lvm
  6. [root@localhost ~]# pvcreate /dev/sdb1
  7. [root@localhost ~]# vgcreate my-vg /dev/sdb1
  8. [root@localhost ~]# lvcreate -n my-lv -L 2G my-vg
  9. [root@localhost ~]# mkfs -t xfs /dev/my-vg/my-lv

4、在足够空间的地方创建备份目录,移动/var目录数据

  1. [root@localhost ~]# mkdir /backup
  2. [root@localhost ~]# cp -a -p /var /backup/
  3. [root@localhost ~]# ll /backup/var/
  4. total 8
  5. drwxr-xr-x. 2 root root 6 Apr 11 2018 adm
  6. drwxr-xr-x. 5 root root 44 May 2 21:01 cache
  7. drwxr-xr-x. 2 root root 6 Nov 4 2018 crash
  8. drwxr-xr-x. 3 root root 34 Jun 12 07:32 db
  9. drwxr-xr-x. 3 root root 18 May 2 21:01 empty
  10. drwxr-xr-x. 2 root root 6 Apr 11 2018 games
  11. drwxr-xr-x. 2 root root 6 Apr 11 2018 gopher
  12. drwxr-xr-x. 3 root root 18 Mar 31 23:06 kerberos
  13. drwxr-xr-x. 25 root root 4096 May 2 21:17 lib
  14. drwxr-xr-x. 3 root root 19 Jun 12 07:56 local
  15. lrwxrwxrwx. 1 root root 11 May 2 20:58 lock -> ../run/lock
  16. drwxr-xr-x. 7 root root 4096 Jun 12 07:34 log
  17. lrwxrwxrwx. 1 root root 10 May 2 20:58 mail -> spool/mail
  18. drwxr-xr-x. 2 root root 6 Apr 11 2018 nis
  19. drwxr-xr-x. 2 root root 6 Apr 11 2018 opt
  20. drwxr-xr-x. 2 root root 6 Apr 11 2018 preserve
  21. lrwxrwxrwx. 1 root root 6 May 2 20:58 run -> ../run
  22. drwxr-xr-x. 8 root root 87 May 2 21:01 spool
  23. drwxrwxrwt. 4 root root 162 Jun 12 08:00 tmp
  24. drwxr-xr-x. 2 root root 6 Apr 11 2018 yp

-a:保留权限,复制软链接本身,递归复制

-p:连同档案的属性一起复制过去,而非使用预设属性

5、挂载新硬盘到/var目录

[root@localhost ~]# mount /dev/my-vg/my-lv  /var

查看

  1. [root@localhost ~]# df -HT
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root xfs 15G 1.6G 13G 11% /
  4. devtmpfs devtmpfs 8.4G 0 8.4G 0% /dev
  5. tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm
  6. tmpfs tmpfs 8.4G 18M 8.4G 1% /run
  7. tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup
  8. /dev/sda1 xfs 1.1G 153M 912M 15% /boot
  9. tmpfs tmpfs 1.7G 0 1.7G 0% /run/user/0
  10. /dev/mapper/my--vg-my--lv xfs 2.2G 34M 2.2G 2% /var

6、恢复数据

[root@localhost ~]# cp -a -p /backup/var/* /var

7、查看nginx应用

至此扩容完成

二、单独lvm的/var目录

1、查看初始的磁盘目录

  1. [root@localhost ~]# df -HT
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
  4. tmpfs tmpfs 4.2G 0 4.2G 0% /dev/shm
  5. tmpfs tmpfs 4.2G 9.3M 4.1G 1% /run
  6. tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup
  7. /dev/mapper/centos-root xfs 11G 2.2G 8.1G 21% /
  8. /dev/mapper/centos-var xfs 2.2G 145M 2.0G 7% /var
  9. /dev/mapper/centos-home xfs 2.2G 34M 2.2G 2% /home
  10. /dev/sda1 xfs 521M 145M 377M 28% /boot
  11. tmpfs tmpfs 821M 0 821M 0% /run/user/0

2、在/var目录编译安装好nginx,演示生产环境某个应用

[root@localhost nginx-1.14.2]# ./configure --user=nginx --group=nginx --prefix=/var/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module

3、服务器增加一个硬盘并分区

  1. [root@localhost ~]# fdisk -l
  2. ...
  3. Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors
  4. Units = sectors of 1 * 512 = 512 bytes
  5. Sector size (logical/physical): 512 bytes / 512 bytes
  6. I/O size (minimum/optimal): 512 bytes / 512 bytes
  7. Disk label type: dos
  8. Disk identifier: 0x2e0f7732
  9. Device Boot Start End Blocks Id System
  10. /dev/sdb1 2048 8388607 4193280 8e Linux LVM

4、查看var所在的卷组(查看到VG Name:centos)

  1. [root@localhost ~]# lvdisplay
  2. ....
  3. --- Logical volume ---
  4. LV Path /dev/centos/var
  5. LV Name var
  6. VG Name centos
  7. LV UUID rRzpmV-wmlt-0IHk-KBR8-rRRy-BBxs-VJ92E5
  8. LV Write Access read/write
  9. LV Creation host, time localhost, 2020-06-12 16:37:42 -0400
  10. LV Status available
  11. # open 1
  12. LV Size 2.00 GiB
  13. Current LE 512
  14. Segments 1
  15. Allocation inherit
  16. Read ahead sectors auto
  17. - currently set to 8192
  18. Block device 253:3
  19. #VG默认信息
  20. [root@localhost ~]# vgdisplay
  21. --- Volume group ---
  22. VG Name centos
  23. System ID
  24. Format lvm2
  25. Metadata Areas 1
  26. Metadata Sequence No 5
  27. VG Access read/write
  28. VG Status resizable
  29. MAX LV 0
  30. Cur LV 4
  31. Open LV 4
  32. Max PV 0
  33. Cur PV 1
  34. Act PV 1
  35. VG Size <15.51 GiB
  36. PE Size 4.00 MiB
  37. Total PE 3970
  38. Alloc PE / Size 3969 / 15.50 GiB
  39. Free PE / Size 1 / 4.00 MiB
  40. VG UUID fvDOrI-1z8x-7Lkq-s8kR-9UfE-UpEa-BkVVjH

5、扩容/var目录所在的vg和lv

  1. #扩容VG
  2. [root@localhost ~]# vgextend centos /dev/sdb1
  3. Volume group "centos" successfully extended
  4. #扩容LV
  5. [root@localhost ~]# lvextend -L +2G /dev/centos/var
  6. Size of logical volume centos/var changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
  7. Logical volume centos/var successfully resized.
  8. #更新
  9. [root@localhost ~]# xfs_growfs /dev/centos/var

6、查看磁盘空间

5、查看应用

至此扩容完成

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/166454
推荐阅读
相关标签
  

闽ICP备14008679号