使用vzsplit在OpenVZ VM之间平均分配资源

使用vzsplit在OpenVZ虚拟机之间分配资源

版本1.0
作者:Falko Timme

这个简短的指南显示了如何在vzsplit的帮助下,在多个虚拟机之间平均分割OpenVZ主机资源。 vzsplit生成一个样本容器配置文件,其中包含一系列系统资源控制参数,您可以将其应用于虚拟机。

我不会保证这将为您工作!

使用vzsplit

看一眼

man vzsplit

了解更多关于它的使用情况。

现在假设我们要在OpenVZ主机上运行5个虚拟机。 我们调用vzsplit如下:

vzsplit -n 5 -f max-limits

-n 5指定虚拟机的数量。

server1:~# vzsplit -n 5 -f max-limits
The optimal swap space size is 2022 Mb, twice bigger than the RAM size
WARNING: Recommended minimal size of partition holding /var/lib/vz/private/ is 20Gb!
Config /etc/vz/conf/ve-max-limits.conf-sample was created
server1:~#

如你所见,这样创建了文件/etc/vz/conf/ve-max-limits.conf-sample ,它包含最大值。 五个虚拟机中的每一个的配置设置的值。 看看那个文件:

vi /etc/vz/conf/ve-max-limits.conf-sample
# Configuration file generated by vzsplit for 5 containers
# on HN with total amount of physical mem 1011 Mb
# low memory 883 Mb, swap size 2047 Mb, Max treads 8000
# Resourse commit level 0:
# Free resource distribution. Any parameters may be increased
# Primary parameters
NUMPROC="1600:1600"
AVNUMPROC="452:452"
NUMTCPSOCK="1600:1600"
NUMOTHERSOCK="1600:1600"
VMGUARPAGES="135985:2147483647"

# Secondary parameters
KMEMSIZE="37052743:40758017"
TCPSNDBUF="5797314:12350914"
TCPRCVBUF="5797314:12350914"
OTHERSOCKBUF="2898657:9452257"
DGRAMRCVBUF="2898657:2898657"
OOMGUARPAGES="135985:2147483647"
PRIVVMPAGES="155342:170876"

# Auxiliary parameters
LOCKEDPAGES="1809:1809"
SHMPAGES="15534:15534"
PHYSPAGES="0:2147483647"
NUMFILE="14464:14464"
NUMFLOCK="1000:1100"
NUMPTY="160:160"
NUMSIGINFO="1024:1024"
DCACHESIZE="8088605:8331264"
NUMIPTENT="200:200"
DISKSPACE="117286:129015"
DISKINODES="110065:121072"
CPUUNITS="8587"

如您所见,该文件不包含VM特定的设置,如主机名,IP地址,Nameservers等,这是有道理的,因为我们不想覆盖这些设置。

现在,我们要将这些设置应用到我们的ID为101的虚拟机上。 这是我们的做法:

vzctl set 101 --applyconfig max-limits --save

之后,您可以启动/重新启动VM 101:

vzctl start 101

你可能会看到这样的东西:

server1:~# vzctl start 101
Starting container ...
vzquota : (warning) block_hard_limit [129115] < block_current_usage [139856]
Container is mounted
Adding IP address(es): 192.168.0.101
bash: line 402: printf: write error: Disk quota exceeded
bash: line 416: printf: write error: Disk quota exceeded
bash: line 421: echo: write error: Disk quota exceeded
bash: line 447: printf: write error: Disk quota exceeded
Setting CPU units: 8587
Configure meminfo: 155342
Set hostname: test.example.com
awk: close failed on file /dev/stdout (Disk quota exceeded)
ERROR: Can't change file /etc/hosts
vzquota : (warning) block_hard_limit [129015] < block_current_usage [139856]
Container start in progress...
server1:~#

由于某些原因vzsplit计算了一个错误的磁盘大小。 您可以按照以下方式进行更正:这将设置磁盘大小,软限制为10GB,硬限制为11GB - 根据您的需要调整):

vzctl set 101 --diskspace "10000000:11000000" --save

然后重新启动虚拟机:

vzctl restart 101

您可以查看虚拟机的新设置,如下所示:

vzctl exec 101 cat /proc/user_beancounters
server1:/etc/vz/conf# vzctl exec 101 cat /proc/user_beancounters
Version: 2.5
       uid  resource           held    maxheld    barrier      limit    failcnt
      101:  kmemsize         340278     580635   37052743   40758017          0
            lockedpages           0          0       1809       1809          0
            privvmpages         796       1655     155342     170876          0
            shmpages              0          0      15534      15534          0
            dummy                 0          0          0          0          0
            numproc               5          9       1600       1600          0
            physpages           486       1060          0 2147483647          0
            vmguarpages           0          0     135985 2147483647          0
            oomguarpages        486       1060     135985 2147483647          0
            numtcpsock            1          2       1600       1600          0
            numflock              1          2       1000       1100          0
            numpty                0          1        160        160          0
            numsiginfo            0          2       1024       1024          0
            tcpsndbuf          8928          0    5797314   12350914          0
            tcprcvbuf         16384          0    5797314   12350914          0
            othersockbuf       2232       3624    2898657    9452257          0
            dgramrcvbuf           0          0    2898657    2898657          0
            numothersock          1          3       1600       1600          0
            dcachesize            0          0    8088605    8331264          0
            numfile             129        193      14464      14464          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            10         10        200        200          0
server1:/etc/vz/conf#

failcnt列非常重要,它应该只包含零; 如果不这样做,这意味着vm需要比当前分配给VM的资源更多的资源。

要了解分配给VM的内存,请运行

vzctl exec 101 free
server1:~# vzctl exec 101 free
             total       used       free     shared    buffers     cached
Mem:        621368       3268     618100          0          0          0
-/+ buffers/cache:       3268     618100
Swap:            0          0          0
server1:~#

链接

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏