Article Directory
- Preface
- 1. KVM installation conditions
- Two, KVM virtualization installation
- Three, KVM virtualization related information
- Four, manually install the virtual machine
- Five, virtual machine management commands
- Six, the virtual machine is transmitted in the linux system
- Seven, virtual machine snapshot
- Eight, the virtual machine is connected to the real machine network
Preface
The application of virtualization technology is very extensive. The current virtualization technology mainly focuses on the virtualization of servers, or the hosting of multiple independent operating systems on a single host.
Virtualization technology can make multiple computers look like one computer, which is called server aggregation or grid computing.
Application scenario: It is necessary to install multiple systems in one server, deploy different services, set different system times, and communicate between multiple systems.
This article first introduces the concept of KVM, focusing on virtualization technology on the Linux operating system.
1. KVM installation conditions
Case 1. If the computer's cpu is inter, the cpu must support vmx function;
case 2. If the computer's cpu is amd, the cpu must support svm function;
The cpu full virtualization function must be turned on before setting up the virtual machine!!
Two, KVM virtualization installation
step:
- View hidden groups
dnf group list --hidden
- Install virtualization tools
dnf group install “Virtualization Client” “Virtualization Hypervisor”
“Virtualization Tools” -y
- Virtualization Client ##Virtualization Client
- Virtualization Tools ##Virtualization Tools
- Virtualization Hypervisor ##Virtualization Core Suite
- View libvirtd service status
systemctl status libvirtd.service
- start up
virt-manager
Three, KVM virtualization related information
Related information Related file location
Service name libvirtd
virtualization core qemu/kvm
virtualization storage directory (virtual machine hard disk) /var/lib/libvirt/images/xxxx.qcow2
Virtualization hardware information /etc/libvirt/qemu/xxxx.xml
Four, manually install the virtual machine
Five, virtual machine management commands
- virt-viewer westos ##Display westos virtual machine
- virt-manager ##Open the virtual machine controller
- virsh list ##List running virtual machines
- virsh list --all ##List all virtual machines
- virsh start westos ##Start the virtual machine
- virsh shutdown westos ##Shut down the virtual machine normally
- virsh destroy westos ##Power off westos virtual machine
Six, the virtual machine is transmitted in the linux system
Steps :
- Connect to other hosts
ssh root@ip
- Copy .xml and .qcow2 files
scp /etc/libvirt/qemu/long.xml [email protected]:/etc/libvirt/qemu
scp /var/lib/libvirt/images/node1.qcow2 [email protected]:
/var/lib/libvirt/images
-
ctrl+d to exit the connection
-
Restore virtual machine
virsh create long.xml Opens the virtual machine directly through the hardware information file, and disappears after the virtual machine is closed virsh define long.xml
adds the virtual machine to the virtual machine list virsh undefine long deletes the virtual machine hardware information
Seven, virtual machine snapshot
1. Create a virtual machine snapshot
step:
- Delete virtual machine hardware information
virsh undefine virtual machine name
- Create a snapshot
qemu-img create -f qcow2 -b virtual machine name.qcow2 snapshot name.qcow2
- Create a new glass by importing an existing disk in the system
- Misoperation in the snapshot, you can delete and recreate a new snapshot
Enter cd /var/lib/libvirt/images/ to
delete the damaged snapshot and
recreate the snapshot
2. Use a script file to create a virtual machine
Steps :
- Create the script file create-vm.sh and edit
#!/bin/bash virt-install
–cdrom /isos/rhel-8.2-x86_64-dvd.iso
–memory 2048
–vcpus 1
–disk /var/lib/libvirt/images/$.qcow2,size=8,bus=virtio
–name $
- Run the script file and enter the virtual machine name
Example: sh create-vm.sh test
- Open virtual Machine to see the created virtual machine
3. Use script files to generate snapshots
#!/bin/bash qemu-img create
-f qcow2
-b /var/lib/libvirt/images/long.qcow2 \ /var/lib/libvirt/images/$*.qcow2 \virt-install
–memory 2048
–vcpus 1
–name KaTeX parse error: Undefined control sequence: \ at position 3: * \̲ ̲--disk /var/lib…*.qcow2
–import
4. Use a script file to reset the virtual machine
Eight, the virtual machine is connected to the real machine network
step:
- cd /etc/sysconfig/network-scripts/
transfer the files inside to /mnt/ - Edit file
vim ifcfg-enp0s25 : DEVICE=enp0s25 ONBOOT=yes BOOTPROTO=none
BRIDGE=br0vim ifcfg-br0 : DEVICE=br0 ONBOOT=yes BOOTPROTO=none
IPADDR=172.25.254.26 NETMASK=255.255.255.0 TYPE=Bridge
- Restart the system
- Turn on the virtual machine and configure the NIC
- Run nm-connection-editor in the virtual machine to
delete the original Bridge, add a new Bridge, and configure its IPV4: edit the address and subnet mask