Monday, 3 December 2012

OpenVz commands

Some of commonly used openvz commands

VZ Information To list all the running/stopped VPS in the node
 vzlist -a

To list all the running VPS in the node

To display the templates present in the server

Creating a VPS To create a VPS with VEID 101 and ostemplate fedora-core-4 with vps.basic configuration
 vzctl create 101 --ostemplate fedora-core-4 -.config vps.basic

Deleting a VPS To destroy a VPS with VEID 101
 vzctl destroy 101

Configuring VPS (The changes are saved in /etc/vz/conf/<VEID>.conf) To automatically boot when a node is up
 vzctl set 101 --onboot yes --save

To set hostname
 vzctl set 101 --hostname --save

To add an IP address
 vzctl set 101 --ipadd --save

To delete an IP address
 vzctl set 101 --ipdel --save

To set the name servers
 vzctl set 101 --nameserver --save

To set the root password of VPS 101
 vzctl set 101 --userpasswd root:password

To set shortname for VPS
 vzctl set 101 --name test101 --save

Start/Stop/Restart VPS To start a VPS
 vzctl start 101

To start a disabled VPS
 vzctl start 101 --force

To stop a VPS
 vzctl stop 101

To restart a VPS
 vzctl restart 101

To know the status of a VPS
 vzctl status 101

To get the details of the VPS like VEID, ClassID, number of processes inside each VPS and the IP addresses of VPS
 cat /proc/vz/veinfo

To enter into a VPS 101
 vzctl enter 101

To execute a command in VPS 101
 vzctl exec 101 command --- replace command with the command you need to execute
 vzctl exec 101 df -h

Managing Disk Quotas To assign disk quotas – First limit is soft limit, second limit is hard limit
 vzctl set 101 --diskspace 10485760 --save  ==>> for setting 10GB
 vzctl set 101 --diskspace 1048576 --save   ==>> for setting 1GB

To assign disk inodes
 vzctl set 101 --diskinodes 90000:91000 --save

To check the disk quota of a VPS
 vzquota stat 101 -t

Managing CPU quota To display the available CPU power

To set the number of CPUs available to a VPS
 vzctl set 101 --cpus 2 --save

To set the minimum and maximum CPU limits
 vzctl set 101 --cpuunits nnnn --cpulimit nn --save

(cpuunits is a an absolute number (fraction of power of the node) and cpulimit is taken as percentage)

Managing memory quota To display memory usage
 vzmemcheck -v

To set kmem
 vzctl set 101 --kmemsize 2211840:2359296 --save

To set privvmpages
 vzctl set 101 --privvmpages 2G:2G --save

Other Commands To copy/clone a VPS
 vzmlocal -C <source_VEID>:<desitnation_VEID>

To disable a VPS
 vzctl set 101 --disabled yes

To enable a VPS
 vzctl set 101 --disabled no

To suspend a VPS
 vzctl suspend 101

To resume a VPS
 vzctl resume 101

To run yum update on a VPS
 vzyum 101 -y update

To install a package using yum on VPS
 vzyum 101 -y install package

To install a package using rpm on VPS
 vzrpm 101 -ivh package

Refer :