OpenVZ useful commands

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 ctid

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 [ctid] --cpus 4 --save

 

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

vzctl set [ctid] --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.

vzctl set [ctid] --ram 1G --swap 2G --vm_overcommit 2 --save

[ctid] with 1 GB of RAM, 2 GB of swap, and (1+2)*2, i.e. 6 GB of virtual memory. That means this container can allocate up to 6 GB of memory, but can’t use more than 3 GB.

You can set vm_overcommit manually as well by using the following commands

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 [ctid]

Stop a Container
vzctl stop [ctid]

Restart a Container
vzctl restart [ctid]

Status of a Container
vzctl status [ctid]

 

10. Listing Containers

vzlist -a

 

11. Deleting Container

vzctl stop [ctid]
vzctl destroy [ctid]

 

12. Disabling Container

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

 

13. Suspending Container

vzctl chkpnt [ctid]

 

14. Running Commands in Container

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

 

15. Setting SWAP Space for the container

4GB SWAP Space
vzctl set [ctid] --swappages 4G:4G --save

 

Extras

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

Similar Posts