OpenVZ: Virtualização para servidores Linux
Neste artigo vamos aprender como montar servidores virtuais tão funcionais quanto servidores convencionais, com os quais podemos montar várias máquinas virtuais com serviços distintos e trabalhar de forma organizada e escalonável.
Parte 4: Gerenciando a máquina virtual
Vamos verificar, primeiramente, o arquivo de configuração que o OpenVZ gerou contendo as informações do VPS:
[root@master /etc/vz]# ls
conf dists names vz.conf
[root@master /etc/vz]# cd conf/
[root@master /etc/vz/conf]# ls
0.conf 101.conf ve-light.conf-sample ve-vps.basic.conf-sample
O arquivo 101.conf contém as configurações de nossa VPS:
[root@master /etc/vz]# ls
conf dists names vz.conf
[root@master /etc/vz]# cd conf/
[root@master /etc/vz/conf]# ls
0.conf 101.conf ve-light.conf-sample ve-vps.basic.conf-sample
O arquivo 101.conf contém as configurações de nossa VPS:
# Copyright (C) 2000-2006 SWsoft. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
ONBOOT="yes"
# UBC parameters (in form of barrier:limit)
# Primary parameters
AVNUMPROC="40:40"
NUMPROC="65:65"
NUMTCPSOCK="80:80"
NUMOTHERSOCK="80:80"
VMGUARPAGES="6144:2147483647"
# Secondary parameters
KMEMSIZE="2752512:2936012"
TCPSNDBUF="319488:524288"
TCPRCVBUF="319488:524288"
OTHERSOCKBUF="132096:336896"
DGRAMRCVBUF="132096:132096"
OOMGUARPAGES="6144:2147483647"
# Auxiliary parameters
LOCKEDPAGES="32:32"
SHMPAGES="8192:8192"
PRIVVMPAGES="49152:53575"
NUMFILE="2048:2048"
NUMFLOCK="100:110"
NUMPTY="16:16"
NUMSIGINFO="256:256"
DCACHESIZE="1048576:1097728"
PHYSPAGES="0:2147483647"
NUMIPTENT="128:128"
# Disk quota parameters (in form of softlimit:hardlimit)
DISKSPACE="1048576:1153434"
DISKINODES="200000:220000"
QUOTATIME="0"
# CPU fair sheduler parameter
CPUUNITS="1000"
VE_ROOT="/var/lib/vz/root/$VEID"
VE_PRIVATE="/var/lib/vz/private/$VEID"
OSTEMPLATE="debian-3.1-i386-minimal"
ORIGIN_SAMPLE="vps.basic"
HOSTNAME="vps-new"
IP_ADDRESS="10.1.1.245"
NAMESERVER="10.1.1.43"
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
ONBOOT="yes"
# UBC parameters (in form of barrier:limit)
# Primary parameters
AVNUMPROC="40:40"
NUMPROC="65:65"
NUMTCPSOCK="80:80"
NUMOTHERSOCK="80:80"
VMGUARPAGES="6144:2147483647"
# Secondary parameters
KMEMSIZE="2752512:2936012"
TCPSNDBUF="319488:524288"
TCPRCVBUF="319488:524288"
OTHERSOCKBUF="132096:336896"
DGRAMRCVBUF="132096:132096"
OOMGUARPAGES="6144:2147483647"
# Auxiliary parameters
LOCKEDPAGES="32:32"
SHMPAGES="8192:8192"
PRIVVMPAGES="49152:53575"
NUMFILE="2048:2048"
NUMFLOCK="100:110"
NUMPTY="16:16"
NUMSIGINFO="256:256"
DCACHESIZE="1048576:1097728"
PHYSPAGES="0:2147483647"
NUMIPTENT="128:128"
# Disk quota parameters (in form of softlimit:hardlimit)
DISKSPACE="1048576:1153434"
DISKINODES="200000:220000"
QUOTATIME="0"
# CPU fair sheduler parameter
CPUUNITS="1000"
VE_ROOT="/var/lib/vz/root/$VEID"
VE_PRIVATE="/var/lib/vz/private/$VEID"
OSTEMPLATE="debian-3.1-i386-minimal"
ORIGIN_SAMPLE="vps.basic"
HOSTNAME="vps-new"
IP_ADDRESS="10.1.1.245"
NAMESERVER="10.1.1.43"
Como podemos ver, modificando o arquivo de configuração você configura o espaço em disco que o servidor virtual vai ter, número de arquivos, etc.
Vamos ver alguns binários interessantes que fazem parte do vzctl:
vzcalc
Gera um cálculo de uso de recursos por id de VPS:
# vzcalc -v 101
Resource Current(%) Promised(%) Max(%) Low Mem 0.76 1.33 1.33 Total RAM 1.25 n/a n/a Mem + Swap 0.83 0.57 n/a Alloc. Mem 3.03 0.57 4.33 Num. Proc 0.06 n/a 0.07 -------------------------------------------- Memory 3.03 1.33 4.33
vzmemcheck
Gera um cálculo de utilização de recursos de todas as VPS.
Gerei este resultado em um servidor meu com 5 VPS simultâneos:
# vzmemcheck -v
Output values in %
veid LowMem LowMem RAM MemSwap MemSwap Alloc Alloc Alloc
util commit util util commit util commit limit
101 0.76 1.33 1.25 0.83 0.57 3.03 0.57 4.33
102 0.05 1.33 0.08 0.05 0.57 0.06 0.57 4.33
103 0.05 1.33 0.08 0.05 0.57 0.06 0.57 4.33
104 0.06 1.33 0.09 0.05 0.57 0.07 0.57 4.33
105 0.06 1.33 0.07 0.04 0.57 0.06 0.57 4.33
-------------------------------------------------------------------------
Summary: 0.99 6.65 1.57 1.03 2.86 3.27 2.86 21.64
vzlist
Mostra todas as VPS em execução:
# vzlist
VPSID NPROC STATUS IP_ADDR HOSTNAME
101 63 running 10.1.1.249 vps1.ascenty.com
102 3 running 10.1.1.248 vps2
103 3 running 10.1.1.247 -
104 4 running 10.1.1.246 vps4
105 10 running 10.1.1.245 vps-new
Para reiniciar um VPS, basta pará-lo e iniciá-lo:
# vzctl stop 101
Stopping VPS ...
VPS was stopped
VPS is unmounted
Pronto, nosso VPS foi restartado.
Sensacional, taí uma coisa que eu não fazia idéia de como implementar.
Um abraço