Difference between revisions of "Manage VM in console"

From vpsget wiki
Jump to: navigation, search
 
(38 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
== '''OpenVZ''' ==
 +
 +
Show all OpenVZ containers:
 +
<pre>
 +
vzlist -a
 +
</pre>
 +
Show all OVZ templates:
 +
<pre>
 +
ls /vz/template/cache/
 +
</pre>
 +
Stop container:
 +
<pre>
 +
vzctl stop <vmID>
 +
</pre>
 +
Srart container:
 +
<pre>
 +
vzctl start <vmID>
 +
</pre>
 +
Restart container:
 +
<pre>
 +
vzctl restart <vmID>
 +
</pre>
 +
Create container:
 +
<pre>
 +
vzctl create <vmID>
 +
</pre>
 +
 +
Force kill CT:
 +
vzctl stop <CTID> --fast
 +
 +
Force chkpnt kill container:
 +
 +
vzctl chkpnt <CTID> --kill
 +
vzctl --verbose MYCTID CTIDHERE
 +
 +
More details about CT creation: http://openvz.org/Configuring_container_creation<br/>
 +
 +
ovz container creation example:
 +
<pre>
 +
vzctl create 115 --ostemplate centos-6-x86
 +
</pre>
 +
Remove container:
 +
<pre>
 +
vzctl destroy <CTID>
 +
</pre>
 +
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''' http://openvz.org/Basic_operations_in_OpenVZ_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:
 +
dmesg|egrep -v '(SMTP-LOG|INPUT-DROP|LIMIT-PPS-DROP|FORWARD-DROP)' TTL=64 ID=0 PROTO=UDP SPT=68 DPT=67 LEN=556
 +
 +
 +
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>
  
 
== '''KVM''' ==
 
== '''KVM''' ==
 +
Show all Virtual Machines (logical volumes):
 +
<pre>
 +
lvdisplay
 +
</pre>
 +
Show state of Virtual Machines:
 +
<pre>
 +
virsh list --all
 +
</pre>
 +
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.
 +
<pre>
 +
virsh shutdown kvm<ID>  #for example kvm101
 +
</pre>
  
Creating copy of an existing VM:<br/>
+
Soft reboot VM
Find the VM you want to save.
 
 
<pre>
 
<pre>
[root@localhost ~]# lvdisplay
+
virsh reboot kvm<ID>
  --- Logical volume ---
 
  LV Path                /dev/vg1/kvm101_img
 
  LV Name                kvm101_img
 
  VG Name                vg1
 
  LV UUID                ZCfjys-Ut9b-2iKZ-VFen-DG2i-79Hn-dfUnOf
 
  LV Write Access        read/write
 
  LV Creation host, time ,
 
  LV Status              available
 
  # open                1
 
  LV Size                30.00 GiB
 
  Current LE            960
 
  Segments              1
 
  Allocation            inherit
 
  Read ahead sectors    auto
 
  - currently set to    1024
 
  Block device          253:0
 
 
</pre>
 
</pre>
Shutdown it
+
Hard power off. This will be equal to unplugging power cord from physical machine.
 
<pre>
 
<pre>
virsh shutdown kvm101
+
virsh destroy kvm<ID>
 
</pre>
 
</pre>
Now create the backup
+
Hard power on
 
<pre>
 
<pre>
dd if=/dev/vg1/kvm101_img | gzip | dd of=/home/kvm101_backup.gz bs=4096
+
virsh start kvm<ID>
 
</pre>
 
</pre>
This archive can be used either for general backup or for cloning, migrating VMs.<br/>
+
 
 +
Edit virtual machine config :
 +
virsh edit kvm<ID>
 +
#or
 +
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
 +
 
 +
 
 +
"[[Category:Admin area]]"

Latest revision as of 15:20, 29 January 2016

OpenVZ

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: http://openvz.org/Configuring_container_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 http://openvz.org/Basic_operations_in_OpenVZ_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:

dmesg|egrep -v '(SMTP-LOG|INPUT-DROP|LIMIT-PPS-DROP|FORWARD-DROP)' TTL=64 ID=0 PROTO=UDP SPT=68 DPT=67 LEN=556


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>

KVM

Show all Virtual Machines (logical volumes):

lvdisplay

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>
#or
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


""