Introduction to the creation management and migration of KVM virtual machines

  • 2020-05-17 07:04:53
  • OfStack

Virtual machine migration technology provides a convenient method for server virtualization. Although commercial virtual software is quite powerful, open source virtual machines such as Linux kernel virtual machines KVM and XEN are developing rapidly and the migration technology is becoming more and more perfect.

1. Install the guest virtual machine

1. Directly install and manage the virtual machine through virt-manager (omitted)

2. Install the guest virtual machine from the command line

qemu-img create -f qcow2 /images/centos6.3-x86_64.img 10G
chown qemu:qemu /images/centos6.3-x86_64.img
virt-install --name centos6.3 --ram=1024 --arch=x86_64 --vcpus=1 --check-cpu --os-type=linux --os-variant='rhel6' -c /tmp/CentOS-6.3-x86_64-minimal.iso --disk path=/images/centos6.3-x86_64.img,device=disk,bus=virtio,size=10,format=qcow2 --bridge=br100 --noautoconsole --vnc --vncport=5902 --vnclisten=0.0.0.0

2. Virtual machine management with virsh

2, switch the machine

virsh start centos6.3 # boot
virsh create etc/libvirt qemu/centos6. 3. # xml directly through the host configuration document to start the host
virsh shutdown centos6.3 # shutdown
virsh destroy centos6.3 # force power off
virsh list --all # view virtual machine status

3. Add and remove virtual machines

virsh define/etc/libvirt/qemu/node5 xml # according to add virtual machine host configuration document
virsh list --all #node5 has been added
virsh undefine node5 # removes the virtual machine
ls /etc/libvirt/qemu
virsh list --all #node5 has been removed

4. Install the new virtual machine using the existing virtual machine configuration document

qemu-img create-f qcow2 /virhost/kvm_node/ node6.img 20G# produce disk image files for the new virtual machine
virsh list
virsh dumpxml node4 > / etc/libvirt/qemu/node6 xml node6 # derived virtual machine hardware configuration information for/etc/libvirt/qemu/node6 xml

vim /etc/libvirt/qemu/node6.xml
id='20' > Modify the id number for node6
node6 # virtual machine node6 name
4 b7e91eb - 6521 - c2c6 - cc64 - c1ba72707fc7 # uuid must be modified, otherwise you will and node4 conflict
Specify the hard disk file for the new virtual machine

virsh define/etc/libvirt/qemu/node6 xml # using virtual description document set up a virtual machine,
The configuration file for node6 can be modified using virsh edit node6
virsh start node6# starts the virtual machine

5 turn on vnc for the virtual machine
virsh edit node4 # edit node4 profile; Modification via vim node4.xml is not recommended.

#port='-1' : port automatic allocation, listening loop network (virt-manager management requires listen='127.0.0.1'), no password
Instead of

Fixed vnc admin port 5904, not automatically assigned, vnc password xiaobai, monitor all networks

Remote vnc access address: 192.168.32.49:5904

3. Management of storage pools and volumes

1. Create the KVM host storage pool

1). Create a storage pool based on folders (directories)

virsh pool-define-as vmware_pool --type dir --target /virhost/vmware# defines the storage pool vmware_pool or
virsh pool-create-as --name vmware_pool --type dir --target /virhost/vmware
Create storage pool vmware_pool, type file directory,/virhost/vmware, same as pool-define-as result 1

2). Create a file system-based storage pool

virsh pool-define-as --name vmware_pool --type fs --source-dev /dev/vg_target/LogVol02 --source-format ext4 --target /virhost/vmware
or
virsh pool-create-as --name vmware_pool --type fs --source-dev /dev/vg_target/LogVol02 --source-format ext4 --target /virhost/vmware

3). View the storage pool information

virsh pool-info vmware_pool # view storage domain (pool)

4). Start the storage pool

virsh pool-start vmware_pool # start the storage pool
virsh pool-list

5) destroy the storage domain and cancel the storage pool

virsh pool-destroy vmware_pool # destroy the storage pool
virsh pool-list --all
virsh pool-undefine vmware_pool # undefines a storage pool
virsh pool-list --all

2. After creating the storage pool, you can create a volume that is used as the hard disk of the virtual machine

virsh vol-create-as --pool vmware_pool name name node6.img qcow2# create volume node6.img, in the storage pool vmware_pool, capacity 10G, Initial allocation 1G, file format type qcow2
virsh vol - info/virhost/vmware/node6 img # name: volume information node6. img type: file capacity: 10.00 GB distribution: 136.00 KB

3. Install the virtual host on the volume

virt-install --connect qemu:///system \-n node7 \-r 512 \-f /virhost/vmware/node7.img \--vnc \--os-type=linux \--os-variant=rhel6 \--vcpus=1 \--network bridge=br0 \-c /mnt/rhel-server-6.0-x86_64-dvd.iso

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: