Very Useful Commands For OpenVZ

Very Useful Commands For OpenVZ

Today we will learn about OpenVZ commands. Here is a list of some useful OpenVZ commands that should be run from the master node:
– To fetch the disk cost with the hostname and ctid of each container on the node.

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

– To find the load average of each container on a node. A pretty useful command to find criminals.

 vzlist -o ctid,laverage,hostname

-Using the PLOOP container? Use this command to clear some space.

vzctl compact [ctid]

-Change the number of CPUs allocated to a container by the following command

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

-This Commands to change the disk space allocated to a container.

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

-Commands to change the password of a container (including the root user)

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

-Commands to change/set the hostname of a container.

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

-Order to adjust/allocate RAM for containers.

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

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

You can also set vm_overcommit manually 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

-Starting, stopping, restarting, and querying the status of the 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]

Listing Containers

vzlist -a

Deleting Container

vzctl stop [ctid]
vzctl destroy [ctid]

Disabling Container

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

Suspending Container

vzctl chkpnt [ctid]

Executing commands in the 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…
-Setting up SWAP space for containers
4GB SWAP Space

vzctl set [ctid] --swappages 4G:4G --save

Buy a dedicated server from Oudel Inc.

Scroll to Top