Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed description of centos7 deployment KVM Virtualization platform

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

KVM has been integrated directly into the Linux kernel since Linux version 2.6.20, and it relies on the CPU virtualization instruction set for high-performance virtualization support. It is highly integrated with the Linux kernel, so it has a good performance in performance, security, compatibility and stability.

Each virtualized operating system running in a KVM environment will behave as a single, independent system process. Therefore, it can be easily integrated with the security module in Linux system (SELinux), and can flexibly realize the management and allocation of hardware resources. The architecture diagram of KVM virtualization is as follows:

Needless to say, start building a KVM virtualization platform:

1. Install:

[root@localhost media] # yum-y groupinstall "GNOME Desktop" # install GNOME Desktop Environment [root@localhost media] # yum-y install qemu-kvm # KVM Module [root@localhost media] # yum-y install qemu-kvm-tools # KVM debugging tool Do not install [root@localhost media] # yum-y install virt-install # command line tool for building virtual machines [root@localhost media] # yum-y install qemu-img # qemu components Create a disk, Start virtual machines, etc. [root@localhost media] # yum-y install bridge-utils # Network support tools [root@localhost media] # yum-y install libvirt # Virtual Machine Management tools [root@localhost media] # yum-y install virt-manager # graphical interface management virtual machines [root@localhost media] # yum-y install libguestfs-tools # to manage virtual machines Disk format [root@localhost ~] # ls-sf / lib/systemd/system/graphical.target / etc/systemd/system/default.target# changes the default running target of the system to graphical.target If you do not execute the command, an error may be reported when you restart.

2. After installation, restart the system and execute the following command to check the system:

[root@localhost ~] # cat / proc/cpuinfo | grep vmx # check whether the CPU of Intel supports virtualization, if it is the CPU of AMD Need "cat / proc/cpuinfo | grep smv" [root@localhost ~] # lsmod | grep kvm # check whether the KVM module is installed with kvm_intel 170181 0 kvm 554609 1 kvm_intelirqbypass 13503 1 kvm [root@localhost ~] # systemctl start libvirtd # start the libvirtd service [root@localhost ~] # systemctl enable libvirtd

3. Set up KVM network:

There are two ways to run a KVM network in libvirt: NAT and Bridge, and the default is NAT.

The descriptions of the two modes are as follows:

(1) NAT mode: it is also the user mode. Packets are transmitted through the interface of the host by NAT mode, which can access the external network, but cannot access the virtual machine network from the outside, so it is generally not used.

(2) Bridge: bridge mode, which allows a virtual machine to own a network like an independent host. External machines can directly access the interior of the virtual machine, but it needs network card support, and generally wired network cards support it.

Let me take Bridge (bridging mode) as an example:

[root@localhost ~] # vim / etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=EthernetBOOTPROTO=none # change this item to noneDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=ens33DEVICE=ens33ONBOOT=yesBRIDGE=br0 # to add the line. If there is a configuration item for UUID, it is recommended to delete it. # copy the file of the network card ens33 and rename it br0 [root@localhost ~] # vim / etc/sysconfig/network-scripts/ifcfg-br0 TYPE=Bridge # change type to BridgeBOOTPROTO=static # here change to static or dhcpDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=br0 # rename DEVICE=br0 # rename ONBOOT=yesIPADDR=192.168. 1.1 # the ip will be the IP address of the host GATEWAY= 192.168.1.254 [root @ localhost ~] # systemctl restart network # restart the network service [root@localhost ~] # ifconfig # confirm the IP address information br0: flags=4163 mtu 1500 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::db0f:ab79:54a1:241b Prefixlen 64 scopeid 0x20 ether 00:0c:29:1a:e0:46 txqueuelen 1000 (Ethernet) RX packets 50 bytes 4155 (4.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 58 bytes 7046 (6.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens33: flags=4163 mtu 1500 ether 00:0c:29:1a:e0:46 txqueuelen 1000 (Ethernet) RX packets 1062 bytes 95264 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 688 bytes 81579 (79.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4. Manage KVM:

[root@localhost /] # virt-manager # Open the graphics management software, and the following interface appears after executing the command

Create a storage pool:

Create an iso mirrored storage pool with the same operation, and complete it as follows:

Create a storage volume:

When you are finished, click as follows to create a virtual machine:

[root@localhost ~] # cp / dev/cdrom / kvm/iso/centos7.iso # first copy the CD and image it to the specified directory

Provide hardware resources according to requirements:

Create custom storage:

Define the virtual machine name and click finish:

After clicking "finish", the window of the virtual machine will pop up automatically, and install the system. Here, as usual, the system is omitted:

Now that the KVM virtualization platform has been deployed, here are some common management commands:

[root@localhost ~] # virsh-h # View Command help [root@localhost ~] # ls / etc/libvirt/qemu # View the configuration file storage directory of KVM (test01.xml is the configuration file of the virtual machine system instance) networks test01.xml [root@localhost ~] # virsh list-- all # View the virtual machine status Id name Status-2 test01 running [root@localhost ~] # virsh shutdown test01 # shut down the virtual machine [root@localhost ~] # virsh start test01 # enable virtual machine [root@localhost ~] # virsh destroy test01 # Force shutdown [root@localhost ~] # virsh create / etc/libvirt/qemu/test01.xml # start virtual machine [root@localhost ~] # virsh suspend test01 # suspend virtual machine [root@localhost ~] # virsh resume test01 # resume running from suspended state Virtual machine [root@localhost ~] # virsh autostart test01 # Settings virtual machine accompanying host automatic startup # deletion and addition of virtual machine: [root@localhost ~] # virsh dumpxml test01 > / etc/libvirt/qemu/test02.xml # Export virtual machine configuration # Delete virtual machine: [root@localhost ~] # virsh shutdown test01 [root@localhost ~] # virsh undefine test01 [root@localhost ~] # virsh list- -all # check whether the virtual machine has been deleted Id name status-# redefine the virtual machine through the backed-up configuration file: [root@localhost ~] # cd / etc/ Libvirt/qemu/ [root@localhost qemu] # mv test02.xml test01.xml [root@localhost qemu] # virsh define test01.xml # modify virtual machine configuration (memory size, etc.) information: [root@localhost qemu] # vim / etc/libvirt/qemu/test01.xml [root@localhost qemu] # virt-df-h test01 # View virtual machine disk information on the host machine

Clone the virtual machine:

[root@localhost qemu] # virt-clone-o test01-n test02-f / kvm/store/test02.qcow2# Clone test01 to test02 [root@localhost qemu] # virsh list-- all # View the status of existing virtual machine Id names-- -- test01 shutdown-test02 shutdown

The virtual machine creates a snapshot:

For the KVM virtual machine to use the snapshot feature, the disk format must be qcow2

[root@localhost qemu] # virsh snapshot-create test01 # create a snapshot of virtual machine test01 [root@localhost qemu] # virsh snapshot-list test01 # View snapshot information name generation time status-- -1560191837 2019-06-11 02:37:17 + 0800 shutoff [root@localhost qemu] # virsh snapshot-revert test01 156019183 "restore virtual machine state to 1560191837 [root@localhost qemu] # virsh snapshot-delete test01 156019183" delete snapshot

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report