21 Nov 2018

OpenVZ useful commands

Here is the list of some useful OpenVZ commands which should be run from the main node :

1. To fetch the consumption of disk for each container in the node along its it’s hostname and cid

vzlist -H -o veid,hostname,diskspace | awk '{ printf("%d\t%s\t%.2f GB\n", $1, $2, $3/(1024*1024))}'

 

2. To find the load average of each container on the node. Pretty useful command to find the culprit.

vzlist -o ctid,laverage,hostname

 

3. Using PLOOP containers? Use this command to free up some space.

vzctl compact [ctid]

 

4. Change the number of CPU allocated to a container by the following command

vzctl set [cid] --cpus 4 --save

 

5. Command to modify the disk space allocated to a container

vzctl set [cid] --diskspace 480G:500G --save

 

6. Command to change password of a container (including root user)

vzctl set [ctid] --userpasswd [username]:[password]

 

7. Command to change/set hostname of a container.

vzctl set [ctid] --hostname server.hostname.com --save

 

8. Command to adjust/allocate the RAM for the container.

64MB Guaranteed, 128MB Burstable
vzctl set [ctid] --vmguarpages 64M --save
vzctl set [ctid] --oomguarpages 64M --save
vzctl set [ctid] --privvmpages 64M:128M --save

1024MB Guaranteed, 2048MB Burstable
vzctl set [ctid] --vmguarpages 1024M --save
vzctl set [ctid] --oomguarpages 1024M --save
vzctl set [ctid] --privvmpages 1024M:2048M --save

 

9. Starting, Stopping, Restarting, and Querying Status of Container

Start a Container
vzctl start [cid]

Stop a Container
vzctl stop [cid]

Restart a Container
vzctl restart [cid]

Status of a Container
vzctl status [cid]

 

10. Listing Containers

vzlist -a

 

11. Deleting Container

vzctl stop [cid]
vzctl destroy [cid]

 

12. Disabling Container

vzctl set [cid] --disabled yes --save

 

13. Suspending Container

vzctl chkpnt [cid]

 

14. Running Commands in Container

vzctl exec [cid] /etc/init.d/sshd status
openssh-daemon is stopped
vzctl exec [cid] /etc/init.d/sshd start
Starting sshd: [ OK ]
vzctl exec [cid] /etc/init.d/sshd status
openssh-daemon (pid 9899) is running…

 

Extras

VZCTL Log File Location: /var/log/vzctl.log