centos7 kvm installation and use

Introduction to kvm###

The full name of KVM is Kernel-Based Virtual Machine. In other words, KVM is implemented based on the Linux kernel.
KVM has a kernel module called kvm.ko, which is only used to manage virtual CPU and memory.

Then who will realize the virtualization of IO, such as storage and network equipment?
This is done by the Linux kernel and Qemu.

To put it bluntly, as a hypervisor, KVM itself only focuses on virtual machine scheduling and memory management. The task of IO peripherals is handed over to the Linux kernel and Qemu

kvm installation###

Check whether the cpu supports virtualization

[ root@localhost ~]# grep -E '(vmx|svm)'/proc/cpuinfo **

Install qemu-kvm (user mode management tool), libvirt (command line management tool), virt-install (install kvm tool), bridge-utils (bridge device management tool)

[ root@localhost ~]# yum install -y qemu-kvm libvirt virt-install bridge-utils

Make sure to load the kvm module

[ root@localhost ~]# lsmod |grep kvm
kvm_intel             1748410 
kvm                   5785181 kvm_intel
irqbypass              135031 kvm
# If it is not loaded, run the command
[ root@localhost ~]# modprobe kvm
[ root@localhost ~]# modprobe kvm-intel

Start libvirtd service

[ root@localhost ~]# systemctl enable libvirtd
[ root@localhost ~]# systemctl start  libvirtd
[ root@localhost ~]# systemctl status  libvirtd

Configure kvm bridge mode

[ root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# cp ifcfg-ens32 ifcfg-br0
[ root@localhost network-scripts]# vim ifcfg-br0
NAME=br0
DEVICE=br0
ONBOOT=yes
NETBOOT=yes
IPV6INIT=no
BOOTPROTO=static
NM_CONTROLLED=no
TYPE=Bridge
IPADDR=192.168.0.127
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=8.8.8.8[root@localhost network-scripts]# vim ifcfg-ens32 
NAME=ens32
DEVICE=ens32
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
BRIDGE=br0

View bridge

[ root@localhost ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.000c29d1267b    no        ens32
virbr0        8000.52540063d8f4    yes        virbr0-nic

Delete virbr0

[ root@localhost ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.000c29d1267b    no        ens32
virbr0        8000.52540063d8f4    yes        virbr0-nic
[ root@localhost ~]# virsh net-list
 Name                 State      Autostart     Persistent
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - default              active     yes           yes

[ root@localhost ~]# virsh net-destroy default
Network default destroyed

[ root@localhost ~]# virsh net-undefine default
Network default has been undefined

[ root@localhost ~]# systemctl restart libvirtd.service
[ root@localhost ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
br0        8000.000c29d1267b    no        ens32

Use virt-manager to manage kvm

Because you want to install the virtual machine graphically with virt-manager, you also need to install the desktop

[ root@localhost ~]# yum grouplist
[ root@localhost ~]# yum groupinstall "GNOME Desktop"-y

Configure Chinese Desktop

grep -E "^[ \t]*export[ \t]+LANG[ \t]*="/etc/profile&& y="yes"|| y="no"if[["$y"="yes"]]; then
sed -r -i -e '/^[ \t]*export[ \t]+LANG[ \t]*=/c\export LANG="zh_CN.UTF-8"'/etc/profile
else
echo 'export LANG="zh_CN.UTF-8"'>>/etc/profile
fi
source /etc/profile

Install virt-manager

[ root@localhost ~]# yum -y install virt-manager

xshell link

[ root@localhost ~]# virt-manager

Store the ISO system image in a directory on the server in advance, such as /data/iso

[ root@localhost ~]# mkdir -p /data/{iso,kvmstorage}[root@localhost ~]# cd /data/iso/[root@localhost iso]# ll
Total amount 4217748-rw-r--r--1 root root 95000985611 2215:24 CentOS-7-x86_64-Minimal-1804.iso
- rw-r--r--1 root root 33689620483 month 232012 cn_windows_server_2008_r2.iso

New virtual machine

Commonly used kvm commands

The management of KVM virtual machine is mainly through the virsh command to manage the virtual machine

Command help
[ root@localhost ~]# virsh --help
View virtual machine status
[ root@localhost ~]# virsh list --all
 Id name status
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4  win2k8r2                       running

Shutdown
[ root@localhost ~]# virsh shutdown win2k8r2

Force power off
[ root@localhost ~]# virsh destroy win2k8r2

Create a virtual machine from a configuration file
[ root@localhost ~]# virsh create /etc/libvirt/qemu/win2k8r2.xml

Set the virtual machine to start automatically
[ root@localhost ~]# virsh autostart win2k8r2
[ root@localhost ~]# ll /etc/libvirt/qemu/autostart/
Total amount 0
lrwxrwxrwx 1 root root 301, 2413:06 win2k8r2.xml ->/etc/libvirt/qemu/win2k8r2.xml

Virtual machine configuration files everywhere
[ root@localhost ~]# virsh dumpxml win2k8r2 >/etc/libvirt/qemu/win2k8r2_bak.xml

Delete the virtual machine (this command only deletes the configuration file, not the disk file)
[ root@localhost ~]# virsh undefine win2k8r2

Restore the definition of the original KVM virtual machine by exporting the backup configuration file, and redefine the virtual machine.
[ root@localhost ~]# mv /etc/libvirt/qemu/win2k8r2_bak.xml /etc/libvirt/qemu/win2k8r2.xml
[ root@localhost ~]# virsh define /etc/libvirt/qemu/win2k8r2.xml

Edit configuration file
[ root@localhost ~]# virsh edit win2k8r2

Hang
[ root@localhost ~]# virsh suspend win2k8r2

restore
[ root@localhost ~]# virsh resume win2k8r2

Other commands###

Create storage volume

[ root@localhost ~]# qemu-img create -f qcow2 /data/kvmstorage/centos7.qcow2 20G
Formatting '/data/kvmstorage/centos7.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off 
[ root@localhost ~]# ll //data/kvmstorage
Total amount 7437168-rw-r--r--1 root root 1971 January 2413:21 centos7.qcow2
- rw-------1 qemu qemu 42956488704 January 2413:21 win2k8r2.qcow2

Generate virtual machine

[ root@localhost ~]# virt-install --virt-type kvm --name centos --ram 1024 \
 - - disk /data/kvmstorage/centos7.qcow2,format=qcow2 \
 - - network bridge=br0 \
 - - graphics vnc,listen=0.0.0.0--noautoconsole \
 - - os-type=linux --os-variant=rhel7 \
 - - location=/data/iso/CentOS-7-x86_64-Minimal-1804.iso

[ root@localhost ~]# virsh list --all
 Id name status
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5  win2k8r2                       running
 7  centos                         running

Recommended Posts

centos7 kvm installation and use
KVM installation and preliminary use under CentOS 7.2
CentOS7 postgresql installation and use
Centos7 elk7.1.1 installation and use
Centos mysql installation and configuration
CentOS 7 installation and configuration PPTP
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
GitLab installation and basic use
2019-07-09 CentOS7 installation
centos7_1708 installation
Use Nginx and u under CentOS
CentOS6 minimal installation KVM detailed tutorial
Centos7 hadoop cluster installation and configuration
CentOS7 installation and maintenance of Gitlab
CentOS7.3 install iptables and detailed use
CentOS 7.X system installation and optimization
Java-JDK installation and configuration under CentOS
Install and use docker under CentOS 6.8
CentOS 7 Tomcat service installation and configuration
CentOS7 install and use SQL Server
CentOS NTP server installation and configuration
CentOs7 installation and deployment Zabbix3.4 original
Erlang 20.2 installation and deployment under CentOS 7
Centos7 mysql database installation and configuration
Centos5 installation guide
CentOS 7 system installation and configuration graphic tutorial
Tomcat installation and configuration under CentOS 7 (Tomcat startup)
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Linux kernel compilation and CentOS system installation
Python - centos6 installation
Installation and configuration of redis under centos7
Centos7.6 operating system installation and optimization record
Centos7 installation and deployment of gitlab server
Ubuntu18.04 Server version installation and use (graphic)
Docker installation (CentOS7 installation)
Installation and use of Win10 subsystem Ubuntu
Centos python3 compile installation and compile gcc upgrade
Zabbix installation and deployment and localization under CentOS
Centos7 hive stand-alone mode installation and configuration
CentOS7 installation zabbix 4.0 tutorial (graphics and text)
Jenkins installation and deployment tutorial under CentOS 7
Centos6.3 install KVM
CentOS7 docker installation
Centos7 installation and deployment of Airflow detailed
Installation and configuration of JDK in CentOS 7 system
CentOS 7 installation and configuration graphic tutorials under VMware10
Centos7 installation of PHP and Nginx tutorial detailed
Installation and configuration of rsync server under CentOS 6.5
Installation and configuration of CentOS 7 in VMware Workstation
How to install and use Curl on CentOS 8
CentOS 7 install KVM and create a virtual machine
MySQL 8.0 installation and deployment under CentOS, super detailed!
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Installation and use of SSH in Ubuntu environment
Install centos7 and connect
CentOS online installation RabbitMQ3.7
Vmware-install and start Centos 8
Vmware-install and start Centos 7
OpenMPI-Ubuntu installation and configuration