当前位置: 首页>>技术教程>>正文


/var从1and1开始在新的Ubuntu专用服务器中使用3.99GB的91.4%

问题描述

昨天我从1and1购买了专用的服务器软件包。我安装了Rails,Mongo和Nginx。今天,当我登录时,它显示以下消息:

Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-24-generic x86_64)

  • Documentation: https://help.ubuntu.com/

    System information as of Wed May 23 21:45:00 EDT 2012

    System load: 0.82 Processes: 114 Usage of /home: 6.1% of 3.99GB Users logged in: 1 Memory usage: 4%
    IP address for eth0: xx.xx.xxx.xxx Swap usage: 0%

    => /var is using 91.4% of 3.99GB

    Graph this data and manage this system at https://landscape.canonical.com/

21 packages can be updated. 6 updates are security updates.

我不太精通linux或命令行,但是目录的4GB花生不是吗?

如果我这样做du -a /var | sort -n -r | head -n 10

3565292 /var
3299164 /var/lib
3145752 /var/lib/mongodb
3145744 /var/lib/mongodb/journal
1048580 /var/lib/mongodb/journal/prealloc.2
1048580 /var/lib/mongodb/journal/prealloc.1
1048580 /var/lib/mongodb/journal/j._0
237272  /var/cache
147260  /var/cache/apt
114844  /var/lib/apt

如果我这样做df -h

Filesystem             Size  Used Avail Use% Mounted on
/dev/sda1              3.7G  736M  3.0G  20% /
udev                   3.9G  4.0K  3.9G   1% /dev
tmpfs                  1.6G  260K  1.6G   1% /run
none                   5.0M     0  5.0M   0% /run/lock
none                   3.9G     0  3.9G   0% /run/shm
/dev/mapper/vg00-usr   4.0G 1007M  2.9G  26% /usr
/dev/mapper/vg00-var   4.0G  3.7G  146M  97% /var
/dev/mapper/vg00-home  4.0G  251M  3.6G   7% /home

如果我这样做fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204402688 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953524224 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 identifier: 0x6c80de21

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63     7823654     3911796   83  Linux
/dev/sda2         7823655    11743514     1959930   82  Linux swap / Solaris
/dev/sda3        11743515  1953520064   970888275   8e  Linux LVM

Disk /dev/mapper/vg00-usr: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders, total 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 identifier: 0x00000000

Disk /dev/mapper/vg00-usr doesn't contain a valid partition table

Disk /dev/mapper/vg00-var: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders, total 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 identifier: 0x00000000

Disk /dev/mapper/vg00-var doesn't contain a valid partition table

Disk /dev/mapper/vg00-home: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders, total 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 identifier: 0x00000000

Disk /dev/mapper/vg00-home doesn't contain a valid partition table

mount

/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/mapper/vg00-usr on /usr type ext4 (rw,errors=remount-ro)
/dev/mapper/vg00-var on /var type ext4 (rw,errors=remount-ro)
/dev/mapper/vg00-home on /home type ext4 (rw,errors=remount-ro)

vgdisplay

  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               925.91 GiB
  PE Size               4.00 MiB
  Total PE              237033
  Alloc PE / Size       3072 / 12.00 GiB
  Free  PE / Size       233961 / 913.91 GiB
  VG UUID               eI2V0B-oVzj-HiIh-enIh-FnrO-NJKi-KpZb0i

我的问题:有什么办法可以克服这个限制?

最佳思路

事实证明,我的系统支持在线扩展逻辑卷。解决方法如下:

# df -h

分区和逻辑卷将列出:

Filesystem             Size  Used Avail Use% Mounted on
/dev/sda1              3.7G  736M  3.0G  20% /
udev                   3.9G  4.0K  3.9G   1% /dev
tmpfs                  1.6G  260K  1.6G   1% /run
none                   5.0M     0  5.0M   0% /run/lock
none                   3.9G     0  3.9G   0% /run/shm
/dev/mapper/vg00-usr   4.0G 1007M  2.9G  26% /usr
/dev/mapper/vg00-var   4.0G  3.7G  145M  97% /var
/dev/mapper/vg00-home  4.0G  251M  3.6G   7% /home

选择您要扩展的分区并通过lvextend运行它

# lvextend -L +46G /dev/mapper/vg00-var

其中+46G是要添加的GB数,在我的情况下是46 + 4 = 50。

之后,您需要使用以下方法增加文件系统以匹配逻辑卷的文件系统:

# resize2fs /dev/mapper/vg00-var

您将拥有一个更大的分区:

resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/mapper/vg00-var is mounted on /var; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg00-var to 13107200 (4k) blocks.
The filesystem on /dev/mapper/vg00-var is now 13107200 blocks long.

新的df -h输出:

Filesystem             Size  Used Avail Use% Mounted on
/dev/sda1              3.7G  737M  3.0G  20% /
udev                   3.9G  4.0K  3.9G   1% /dev
tmpfs                  1.6G  260K  1.6G   1% /run
none                   5.0M     0  5.0M   0% /run/lock
none                   3.9G     0  3.9G   0% /run/shm
/dev/mapper/vg00-usr   4.0G 1008M  2.9G  26% /usr
/dev/mapper/vg00-var    49G  3.7G   43G   8% /var
/dev/mapper/vg00-home  4.0G  251M  3.6G   7% /home

次佳思路

根据fdisk -l的输出,看来/dev/sda磁盘实际上是1TB驱动器。但是,保存/var目录的卷只有4GB,太小而无法在long-run中使用。

可以扩展逻辑卷,但不能在安装逻辑卷时扩展。这将带来一些困难,尤其是在服务器位于同一位置并且您没有物理访问权限的情况下。托管公司可以为您提供IPKVM设备,这将使您可以远程启动恢复磁盘并调整卷大小。但是,正如您已经说过的那样,您在控制台或Linux上一般不太熟练,我强烈建议您避免使用此方法。而是,我建议以下之一:

  • 请与托管公司联系,并确定是否有技术支持人员可以将安装/var目录的卷的大小调整为更合理的大小,至少可以调整为50GB,因为您确实有1TB的驱动器可用。在此更改期间,服务器将脱机,因为在此过程中必须卸载/var目录。

  • 或者,要求重新安装整个操作系统,并告诉他们将卷大小设置为至少50GB。这可能比让他们在实时系统上执行此调整便宜,因为它的技术性较低。鉴于您对Linux没有太多的技术知识,一个更好的解决方案是告诉他们重新安装操作系统,而无需为/usr /var/home添加任何特殊的安装点,而是将所有内容都安装在根卷上。在单独的卷上创建特殊的挂载点的唯一好处(这就是您当前的设置方式)是,如果一个卷已满,则不会降低整个系统的性能。但是,按照您的情况将卷大小设置为4GB似乎很愚蠢,尤其是考虑到硬盘的大小。

第三种思路

您在说什么限制? /var分区只有4GB,您正在使用其大部分容量。您需要删除一些不需要的文件(例如某些日志)或从主机购买更多空间(例如添加另一个HD驱动器)。但是,除非使用LVM(逻辑卷管理器),否则不能无格式地动态修改/var分区大小。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/11394.html,未经允许,请勿转载。