Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
linux:kvm [2015/12/03 14:43]
vondra [Debian 8]
linux:kvm [2015/12/14 11:16]
vondra [Instalace KVM]
Line 1: Line 1:
 ====== Instalace KVM ====== ====== Instalace KVM ======
 TODO: udelat tutorial :) TODO: udelat tutorial :)
 +<code bash>​aptitude -y install qemu-kvm libvirt-bin virtinst bridge-utils </​code>​
 ====== Vytvoreni guesta ====== ====== Vytvoreni guesta ======
 ===== Debian 8 ===== ===== Debian 8 =====
-  - Instalace guestu:<code bash>​virt-install -n vps1 --ram=2048 --vcpus=2 --location='​http://​ftp.cz.debian.org/​debian/​dists/​jessie/​main/​installer-amd64/' ​ +  - Install gues:<code bash>​virt-install -n vps1 --ram=2048 --vcpus=2 --location='​http://​ftp.cz.debian.org/​debian/​dists/​jessie/​main/​installer-amd64/'​ --disk path=/​dev/​shared_vg/​vps1 ​ --network bridge=br0 --os-type linux --console pty,​target_type=serial --graphics none --os-variant generic --extra-args '​console=ttyS0,​115200n8 serial'</​code>​ 
---disk path=/​dev/​shared_vg/​vps1 ​ --network bridge=br0 --os-type linux  +  - put following line into grubu in line starting with linux <​code>​console=tty0 console=ttyS0,​115200</​code>​ 
---console pty,​target_type=serial --graphics none --os-variant generic ​ +  - put "​console=tty0 console=ttyS0,​115200"​ into /​etc/​default/​grub ​in GRUB_CMDLINE_LINUX_DEFAULT ​<​code>​GRUB_CMDLINE_LINUX_DEFAULT="​console=tty0 console=ttyS0,​115200"<​/code> 
---extra-args '​console=ttyS0,​115200n8 serial'</​code>​ +  - update grub (this one i always forget and wondering why it doesn'​t work :))<code bash>​update-grub</​code>​ 
-  - grubu pridat do radky linux <​code>​console=tty0 console=ttyS0,​115200</​code>​ + 
-  - do /​etc/​default/​grub ​pridat do GRUB_CMDLINE_LINUX_DEFAULT "​console=tty0 console=ttyS0,​115200"<​code>​GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200"</​code>​+====== Vzdaleny pristup ====== 
 +===== Pres certifikaty ===== 
 +https://​libvirt.org/​remote.html 
 +  * note: nepovedlo se mi rozbehat 
 +===== Pres libvirt + ssh ===== 
 +<code python>​ 
 +import libvirt 
 +conn = libvirt.open("qemu+ssh://​root@10.0.0.120"​) 
 + 
 +# vypis bezicich vps (interni ID) 
 +conn.listDomainsID() 
 + 
 +# nalezeni vps podle ID (pouze bezici) 
 +vps conn.lookupByID(1) 
 + 
 +# nalezeni vps podle jmena (bere i masiny, ktere jsou nebezici, ale nadefinovane) 
 +vps1 conn.lookupByName("​vps1"​) 
 + 
 +# spusteni 
 +vps1.start() 
 + 
 +# pause 
 +vps1.suspend() 
 + 
 +# unpause 
 +vps1.resume() 
 + 
 +# shut down 
 +vps1.shutdown() 
 + 
 +# force shutdown 
 +vps1.destroy() 
 + 
 +# close connection 
 +conn.close() 
 +</​code>​ 
 +====== HOT migration ====== 
 +  * NOTE: we cannot use kvm migrationsince we use mirrored clustered LVM (mirrored volume could not be activated on more than one node in time) 
 +  * use following script instead:<​code bash> 
 +#​!/​bin/​bash 
 + 
 +if [ $# != 2 ]; then 
 +        echo "​Usage:​ move_vps.sh domain destination"​ 
 +        exit 1 
 +fi 
 + 
 +MACHINE=$1 
 +DESTINATION=$2 
 + 
 +XML_NAME=/​tmp/​$MACHINE 
 +virsh dumpxml $MACHINE > $XML_NAME 
 +scp ${XML_NAME} root@${DESTINATION}:​${XML_NAME} 
 +rm $XML_NAME 
 + 
 +IMG_NAME=/​tmp/​${MACHINE}.img 
 +virsh save $MACHINE $IMG_NAME 
 +scp $IMG_NAME root@${DESTINATION}:​${IMG_NAME} 
 +rm $IMG_NAME 
 + 
 +lvchange -an /​dev/​shared_vg/​$MACHINE 
 +ssh root@$DESTINATION "​lvchange -ay /​dev/​shared_vg/​$MACHINE"​ 
 +ssh root@$DESTINATION "virsh define ${XML_NAME}"​ 
 +ssh root@$DESTINATION "virsh restore $IMG_NAME"​ 
 +ssh root@$DESTINATION "rm $IMG_NAME"</​code>​ 
 + 
 
linux/kvm.txt · Last modified: 2019/01/11 13:14 by admin