Centos7 /var目录扩容

导读:本篇文章讲解 Centos7 /var目录扩容,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

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,演示生产环境应用(具体查看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

查看到安装路径

Centos7 /var目录扩容

访问

Centos7 /var目录扩容

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

[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应用

Centos7 /var目录扩容

至此扩容完成

二、单独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: 0x2e0f7732

   Device 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/var
  LV Name                var
  VG Name                centos
  LV UUID                rRzpmV-wmlt-0IHk-KBR8-rRRy-BBxs-VJ92E5
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-06-12 16:37:42 -0400
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

#VG默认信息
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <15.51 GiB
  PE Size               4.00 MiB
  Total PE              3970
  Alloc PE / Size       3969 / 15.50 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG 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、查看磁盘空间

Centos7 /var目录扩容

5、查看应用

Centos7 /var目录扩容

至此扩容完成

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/95190.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!