Liunx-9 Unit-Virtualization Deployment


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!!
Insert picture description here

Two, KVM virtualization installation

step:

  1. View hidden groups

dnf group list --hidden

  1. 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
  1. View libvirtd service status

systemctl status libvirtd.service

  1. 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

Insert picture description here
Insert picture description hereInsert picture description here

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 :

  1. Connect to other hosts

ssh root@ip

  1. 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

  1. ctrl+d to exit the connection

  2. 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:

  1. Delete virtual machine hardware information

virsh undefine virtual machine name

  1. Create a snapshot

qemu-img create -f qcow2 -b virtual machine name.qcow2 snapshot name.qcow2

  1. Create a new glass by importing an existing disk in the system
  2. 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 :

  1. 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 $

  1. Run the script file and enter the virtual machine name

Example: sh create-vm.sh test

  1. 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:

  1. cd /etc/sysconfig/network-scripts/
    transfer the files inside to /mnt/
  2. Edit file

vim ifcfg-enp0s25 : DEVICE=enp0s25 ONBOOT=yes BOOTPROTO=none
BRIDGE=br0

vim ifcfg-br0 : DEVICE=br0 ONBOOT=yes BOOTPROTO=none
IPADDR=172.25.254.26 NETMASK=255.255.255.0 TYPE=Bridge

  1. Restart the system
  2. Turn on the virtual machine and configure the NIC
  3. 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

Guess you like

Origin blog.csdn.net/m0_46988935/article/details/109352791