Linux Learning Log: details of the use of virtualization management tools, linux details
Virtualization management tools
Reason for Virtualization: the power consumption of computer computing is too high, virtualization can greatly reduce the power consumption of Enterprises
(Parallel operations in the kernel during virtualization)
Key File: cat/proc/cpuinfo | grep-E "svm | vmx"
Find one of the two. Otherwise, redhat virtualization cannot be used.
1. Virtual Machine installation (with images)
Step 1: Open the VM manager and enter the superuser password:
[Kiosk @ foundation3 Desktop] $ virt-manager
Step 2: download the required Image File
Step 3: Click Create a New virtualization Device
Step 4: Select Local install media (ISO image or CDROM)
Step 5: select all the directory addresses of the virtualization Program
Step 6: select the memory and CPU count
Step 7: select the disk size
Step 8: Enter the Virtual Machine name and network card type
Step 9: select the DISK type
Step 10: select the NIC type
Step 11: Go to virtualization settings and select the first item
Step 12: select the time zone, input method, and language support
Step 13: select the software environment
Step 14: Set the hard disk
Step 15: Set the superuser password
1. Virtual Machine installation ()
[VM vm_create.sh]
[Root @ foundation3 sbin] # vim/sbin/vm_create.sh // create a fully automated creation script
#! /Bin/bash // not Annotation
Virt-install \ // start the Virtual Machine Installer
-- Location http: // 172.25.254.23/rhel7.3 \ // Data Source Address
-- Extra-args "ks = http: // 172.25.254.103/ks. cfg" // reset the IP address of the VM
-- Ram 1024 \ // memory size
-- Vcpus 1 \ // Number of cpu Cores
-- File-size 8 \ // hard disk size
-- File/var/lib/libvirt/images/$1. qcows, bus = virtio \ // hard disk location, bus set type
-- Network source = br0, model = virtio \ // sets the NIC type and working mode of the VM.
-- Name $1 & // specify the name of the virtual machine to be installed
[Root @ foundation3 sbin] # chmod + x/sbin/vm_create.sh // grant permissions
[Set in Virtual Machine]
[Create a kickstart file]
Use the system-config-kickstart Tool
Template:/root/anaconda-ks.cfg (automatically generated)
Then, run the ksvalidator command to verify the correctness.
Install system-config-kickstart
[Root @ foundation3 bin] # yum install system-config-kickstart
Install system-config-kickstart.noarch
[Root @ foundation3 bin] # yum install system-config-kickstart.noarch-y
Open the Installation File system-config-kickstart.
[Root @ foundation3 bin] # system-config-kickstart
Add the allocated/boot waap and other space allocations to Add.
Generate the ks. cfg file and save it to the Apache shared directory.
(The anaconda-ls.cfg is a file automatically generated when the system is installed)
[Root @ westos2 ~] # Vim/var/www/html/kd. cfg
% Packages
@ Base
Fftp
% End
% Post
Rm-fr/etc/yum. repos. d /*
Cat>/etc/yum. repos. d/yum. repo <
[Rhel7.3]
Name = rhel7.3
Baseurl = http: // 172.25.254.23/rhel7.3
Gpgcheck = 0
EOF
% End
[Done] Run/bin/reset. sh to reset
3. VM management commands
! A virtual machine consists of two parts: virtual machine hardware information files & Virtual Machine Hard Disk Files
/Etc/libvirt/qemu/westos2.xml // virtual machine hardware information file
/Var/lib/libvirt/images/westos2.qcow2 // Virtual Machine Hard Disk File
File Type:
. Xml # front-end hardware information data file
. Qemu # Hard Disk File
Common commands:
Virt-manager // open the Virtual Machine manager
Virt-viewer westos2 // display virtual machines
Virsh start westos2 // open the Virtual Machine
Virsh list // display the running Virtual Machine
Virsh list -- all // display all VMS
Virsh shutdown westos2 // shut down the VM normally
Virsh destroy westos2 // force shut down the Virtual Machine
Virsh define westos2.xml // restore the Virtual Machine (permanent)
Virsh undefine westos2.xml // Delete the virtual machine hardware information file
Virsh create westos2.xml // use the virtual machine hardware information file to open the Virtual Machine (one-time)
Migration:
Because the virtual machine consists of the virtual machine hardware information file and Virtual Machine hard disk file, you must copy the. xml file and. qemu2 file to the USB flash drive during migration (move to/mnt/as an example)
[Root @ foundation3 mnt] # cp/etc/libvirt/qemu/westos2.xml/mnt/
[Root @ foundation3 mnt] # mv/var/lib/libvirt/images/westos2.qcow2/mnt/
4. Virtual Machine Snapshot
! The snapshot of a VM is only a file that stores the changed information.
! When the VM is read, the content in the master disk is still read.
Format]
Qemu-img create-f qcow2-B master disk. qcow2 snapshot. qcow2
In the figure, node2.qcow2 takes a snapshot of westos2.qcow2 as the master disk.
[PURPOSE]
Using snapshots in virt-manager allows you to quickly create snapshot VMS.
[Example: Use westos2.qcow2 as the master disk to create a snapshot node3.qcow2 and create a snapshot VM]
[Root @ foundation3 libvirt] # cd/var/lib/libvirt/images/
[Root @ foundation3 images] # qemu-img create-f qcow2-B westos. qcow2 node3.qcow2//-F is type-B is backup
Formatting 'node3. qcow2 ', fmt = qcow2 size = 8589934592 backing_file = 'westos. qcow2' encryption = off cluster_size = 65536 lazy_refcounts = off
Import snapshots to virtual machines
The subsequent settings are the same as those in the figure above.
VM installation completed by snapshot
!!! Make sure to create a snapshot using a normally running VM as the master disk. Otherwise, an error will be reported.
5. VM snapshot reset script
[Root @ foundation3 images] # cd/bin/
[Root @ foundation3 bin] # vim/bin/reset. sh
#! /Bin/bash
Virsh destroy $1
Rm-fr/var/lib/libvirt/images/$1. qcow2
Qemu-img create-f qcow2-B \
/Var/lib/libvirt/images/westos2.qcow2 \
/Var/lib/libvirt/images/$1. qcow2
Virsh start $1
Virt-viewer $1 & // & suspended for the background