Centos7 /var目录扩容

编程入门 行业动态 更新时间:2024-10-27 03:34:48

Centos7 /var<a href=https://www.elefans.com/category/jswz/34/1771435.html style=目录扩容"/>

Centos7 /var目录扩容

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

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

1、查看初始的磁盘目录

[root@localhost ~]# df -HT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        15G  1.1G   14G   8% /
devtmpfs                devtmpfs  8.4G     0  8.4G   0% /dev
tmpfs                   tmpfs     8.4G     0  8.4G   0% /dev/shm
tmpfs                   tmpfs     8.4G   18M  8.4G   1% /run
tmpfs                   tmpfs     8.4G     0  8.4G   0% /sys/fs/cgroup
/dev/sda1               xfs       1.1G  153M  912M  15% /boot
tmpfs                   tmpfs     1.7G     0  1.7G   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、服务器增加一块硬盘,分区并格式化(具体查看)

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

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

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

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

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

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

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

查看

[root@localhost ~]# df -HT
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   xfs        15G  1.6G   13G  11% /
devtmpfs                  devtmpfs  8.4G     0  8.4G   0% /dev
tmpfs                     tmpfs     8.4G     0  8.4G   0% /dev/shm
tmpfs                     tmpfs     8.4G   18M  8.4G   1% /run
tmpfs                     tmpfs     8.4G     0  8.4G   0% /sys/fs/cgroup
/dev/sda1                 xfs       1.1G  153M  912M  15% /boot
tmpfs                     tmpfs     1.7G     0  1.7G   0% /run/user/0
/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、查看初始的磁盘目录

[root@localhost ~]# df -HT
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                   tmpfs     4.2G  9.3M  4.1G   1% /run
tmpfs                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        11G  2.2G  8.1G  21% /
/dev/mapper/centos-var  xfs       2.2G  145M  2.0G   7% /var
/dev/mapper/centos-home xfs       2.2G   34M  2.2G   2% /home
/dev/sda1               xfs       521M  145M  377M  28% /boot
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、服务器增加一个硬盘并分区

[root@localhost ~]# fdisk -l
...
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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
Disk label type: dos
Disk identifier: 0x2e0f7732Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     8388607     4193280   8e  Linux LVM

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

[root@localhost ~]# lvdisplay
....  
--- Logical volume ---LV Path                /dev/centos/varLV Name                varVG Name                centosLV UUID                rRzpmV-wmlt-0IHk-KBR8-rRRy-BBxs-VJ92E5LV Write Access        read/writeLV Creation host, time localhost, 2020-06-12 16:37:42 -0400LV Status              available# open                 1LV Size                2.00 GiBCurrent LE             512Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:3#VG默认信息
[root@localhost ~]# vgdisplay --- Volume group ---VG Name               centosSystem ID             Format                lvm2Metadata Areas        1Metadata Sequence No  5VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                4Open LV               4Max PV                0Cur PV                1Act PV                1VG Size               <15.51 GiBPE Size               4.00 MiBTotal PE              3970Alloc PE / Size       3969 / 15.50 GiBFree  PE / Size       1 / 4.00 MiBVG UUID               fvDOrI-1z8x-7Lkq-s8kR-9UfE-UpEa-BkVVjH

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

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

6、查看磁盘空间

5、查看应用

至此扩容完成

更多推荐

Centos7 /var目录扩容

本文发布于:2024-02-08 21:57:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1675512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目录   var

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!