Manage VM in console

From vpsget wiki
Jump to: navigation, search


Show all OpenVZ containers:

vzlist -a

Show all OVZ templates:

 ls /vz/template/cache/

Stop container:

vzctl stop <vmID>

Srart container:

vzctl start <vmID>

Restart container:

vzctl restart <vmID>

Create container:

vzctl create <vmID>

Force kill CT: vzctl stop <CTID> --fast

Force chkpnt kill container:

vzctl chkpnt <CTID> --kill vzctl --verbose MYCTID CTIDHERE

More details about CT creation:

ovz container creation example:

vzctl create 115 --ostemplate centos-6-x86

Remove container:

vzctl destroy <CTID>

Suspend container

vzctl suspend <CT_ID>

Unsuspend container vzctl resume <CT_ID>

For extended description refer to man vzctl. Also we recommend to read Basic operations in OpenZV environment

get active vz containers count:

vzlist | wc -l

get containers disk usage in %

vzlist -a -H -o hostname,diskspace,diskspace.s,veid  | awk '{ printf( "%2.f%\t%s\t%s\n"), $2*100/$3, $4, $1}' | sort -r

get 10 top CPU openvz containers

ps -e h -o pid --sort -pcpu | head -10 | vzpid -  

show containers' memory usage

vzmemcheck -v -A

show PID containerID owner, user, exe path:

ll /proc/<PID>  #or ls -l /proc/<PID>

show all containers load average:

vzlist -o ctid,laverage

SHow all possibly abusive containers. also show containers with RAM utilization/problems:


Show 10 top memory intensive processes:

ps -auxf | sort -nr -k 4 | head -10

Show 10 top CT's based on number of processes:

/usr/sbin/vzlist -H -o ctid,numproc|sort -r -n -k2|head

Show 10 top CT's based on socket usage:

/usr/sbin/vzstat -t -s sock|awk 'NF==10{print $0}'

Sort containers on TCP send /receive buffer usage:

vzlist -H -o ctid,tcpsndbuf |sort -r -n -k2
vzlist -H -o ctid,tcprcvbuf |sort -r -n -k2

Sort CT's based on inbound/outbound NW traffic:

vznetstat -r |awk '$3 ~ /G/ {print $0}'|sort -r -nk3
vznetstat -r |awk '$5 ~ /G/ {print $0}'|sort -r -nk5

Make backup of the container while CT is online:

vzdump <CTID>


Show all Virtual Machines (logical volumes):


Show state of Virtual Machines:

virsh list --all

You can use virtual machine kvm<ID> or kvm_name as identificator. If VM not turned on you can identify it via name, there no ID assigned to offline VMs.

Soft shutdown VM. This will sent shutdown command to VMs OS.

virsh shutdown kvm<ID>  #for example kvm101

Soft reboot VM

virsh reboot kvm<ID>

Hard power off. This will be equal to unplugging power cord from physical machine.

virsh destroy kvm<ID>

Hard power on

virsh start kvm<ID>

Edit virtual machine config :

virsh edit kvm<ID>
virsh edit <machine_name>  

For extended description refer to man virsh.

Force kvm start. Could be usefull if you disabled selinux and machines were hiobernated before node reboot. so simply clean start:

virsh start <machinename> --force-boot

Increase a VM's disk space [do not use for RAW images!!]

qemu-img resize vmdisk.img +10G