Install KVM and install rhel7 in KVM

Install KVM and install rhel7 in KVM

KVM brief introduction
KVM is the abbreviation of Kernel-based Virtual Machine, which is an open source system virtualization module. KVM is an open source software based on kernel virtualization technology. It is actually a virtualization module embedded in the system. By optimizing the kernel to use virtualization technology, this kernel module makes Linux a hypervisor, and the virtual machine uses Linux's own scheduling. device for management.
The kernel module of KVM is kvm.ko, which is only used to manage virtual CPU and memory. The virtualization of IO is implemented by the linux kernel and qemu.
libvirt is the management tool of KVM. libvirt includes the background daemon program libvirtd, API library and command-line tool virsh, where libvirtd is a service program running in the background, receiving and processing API requests; the API library allows others to develop advanced tools based on libvirt, such as the graphic virt-manager virsh is a kvm command line tool that is often used.
Next, demonstrate the installation of KVM on the redhat7 host.
Need to check whether the host supports virtualization before installing kvm?
The host must meet three conditions to support virtualization:
1. The CPU must be 64-bit.
2. The CPU has virtualization function
. 3. Virtualization must be enabled in the BIOS
because kvm is installed on the redhat host, so check whether redhat supports it. For virtualization, you can view it through the command to view CPU information.
insert image description here
From the flags field, you can see the two flags of the CPU. lm indicates that the CPU is 64-bit, and vmx indicates that the CPU supports virtualization.
Of course, you can also use commands to directly check that
insert image description here
KVM is a kernel-based virtual machine, so you must also load the kvm module to check the redhat system.
insert image description here
Install KVM
The KVM software is all in the redhat installation image, so the installation image needs to be used as the software source. The image file of redhat is used as the software source of the virtual machine in redhat. Here, I create the software source by building an ftp server.
1. First install the vsftpd package

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
└─sda3   8:3    0   35G  0 part /
sr0     11:0    1  3.5G  0 rom  
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        35G  3.0G   33G   9% /
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.9G   84K  3.9G   1% /dev/shm
tmpfs           3.9G  9.0M  3.9G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1      1014M  169M  846M  17% /boot
tmpfs           781M   16K  781M   1% /run/user/42
tmpfs           781M     0  781M   0% /run/user/0
/dev/sr0        3.6G  3.6G     0 100% /mnt
[root@localhost ~]# rpm -ivh /mnt/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm 
warning: /mnt/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.2-21.el7              ################################# [100%]

After installing the ftp service, create a software warehouse directory /var/ftp/dvd, and permanently mount the image file to this directory.

[root@localhost ~]# mkdir /var/ftp/dvd
[root@localhost ~]# vi /etc/fstab 
[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Feb 24 15:34:07 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e260d75c-d83a-45fe-b084-a5016087f284 /                       xfs     defaults        0 0
UUID=bbce0f47-6db0-4d4a-a37f-025ed12a45ca /boot                   xfs     defaults        0 0
UUID=c299518f-7ce3-430b-872d-7d30e5ec3b98 swap                    swap    defaults        0 0
/dev/sr0	/var/ftp/dvd	iso9660	defaults	0	0
[root@localhost ~]# mount /dev/sr0 /var/ftp/dvd

Restart the vsftpd service, and set the startup to start the vsftpd service, and then create the configuration file dvd.repo of the software warehouse, pointing to the software warehouse stored in the previously created /var/ftp/dvd.
insert image description here
To install kvm, three packages are usually required: qemu-kvm, libvirt and virt-manager. qemu-kvm mainly provides the kvm simulator, libvirt provides related library files, and virt-manager provides the virtual machine manager.

[root@localhost ~]# yum -y install qemu-kvm libvirt virt-manager
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
redhat                                                               | 4.1 kB  00:00:00     
(1/2): redhat/group_gz                                               | 136 kB  00:00:00     
(2/2): redhat/primary_db                                             | 3.9 MB  00:00:01     
Package 10:qemu-kvm-1.5.3-126.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package libvirt.x86_64 0:2.0.0-10.el7 will be installed
--> Processing Dependency: libvirt-daemon-config-nwfilter = 2.0.0-10.el7 for package: libvirt-2.0.0-10.el7.x86_64
--> Processing Dependency: libvirt-daemon-driver-lxc = 2.0.0-10.el7 for package: libvirt-2.0.0-10.el7.x86_64
---> Package virt-manager.noarch 0:1.4.0-2.el7 will be installed
--> Processing Dependency: virt-manager-common = 1.4.0-2.el7 for package: virt-manager-1.4.0-2.el7.noarch
--> Running transaction check
---> Package libvirt-daemon-config-nwfilter.x86_64 0:2.0.0-10.el7 will be installed
---> Package libvirt-daemon-driver-lxc.x86_64 0:2.0.0-10.el7 will be installed
---> Package virt-manager-common.noarch 0:1.4.0-2.el7 will be installed
--> Processing Dependency: libvirt-python >= 0.7.0 for package: virt-manager-common-1.4.0-2.el7.noarch
--> Processing Dependency: python-ipaddr for package: virt-manager-common-1.4.0-2.el7.noarch
--> Running transaction check
---> Package libvirt-python.x86_64 0:2.0.0-2.el7 will be installed
---> Package python-ipaddr.noarch 0:2.1.9-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================
 Package                              Arch         Version               Repository    Size
============================================================================================
Installing:
 libvirt                              x86_64       2.0.0-10.el7          redhat       136 k
 virt-manager                         noarch       1.4.0-2.el7           redhat       629 k
Installing for dependencies:
 libvirt-daemon-config-nwfilter       x86_64       2.0.0-10.el7          redhat       140 k
 libvirt-daemon-driver-lxc            x86_64       2.0.0-10.el7          redhat       801 k
 libvirt-python                       x86_64       2.0.0-2.el7           redhat       321 k
 python-ipaddr                        noarch       2.1.9-5.el7           redhat        36 k
 virt-manager-common                  noarch       1.4.0-2.el7           redhat       1.1 M

Transaction Summary
============================================================================================
Install  2 Packages (+5 Dependent packages)

Total download size: 3.1 M
Installed size: 13 M
Downloading packages:
(1/7): libvirt-2.0.0-10.el7.x86_64.rpm                               | 136 kB  00:00:00     
(2/7): libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64.rpm        | 140 kB  00:00:00     
(3/7): libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64.rpm             | 801 kB  00:00:00     
(4/7): libvirt-python-2.0.0-2.el7.x86_64.rpm                         | 321 kB  00:00:00     
(5/7): python-ipaddr-2.1.9-5.el7.noarch.rpm                          |  36 kB  00:00:00     
(6/7): virt-manager-1.4.0-2.el7.noarch.rpm                           | 629 kB  00:00:00     
(7/7): virt-manager-common-1.4.0-2.el7.noarch.rpm                    | 1.1 MB  00:00:00     
--------------------------------------------------------------------------------------------
Total                                                       5.1 MB/s | 3.1 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64                            1/7 
  Installing : python-ipaddr-2.1.9-5.el7.noarch                                         2/7 
  Installing : libvirt-python-2.0.0-2.el7.x86_64                                        3/7 
  Installing : virt-manager-common-1.4.0-2.el7.noarch                                   4/7 
  Installing : libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64                       5/7 
  Installing : libvirt-2.0.0-10.el7.x86_64                                              6/7 
  Installing : virt-manager-1.4.0-2.el7.noarch                                          7/7 
redhat/productid                                                     | 1.6 kB  00:00:00     
  Verifying  : libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64                       1/7 
  Verifying  : libvirt-python-2.0.0-2.el7.x86_64                                        2/7 
  Verifying  : libvirt-2.0.0-10.el7.x86_64                                              3/7 
  Verifying  : virt-manager-1.4.0-2.el7.noarch                                          4/7 
  Verifying  : python-ipaddr-2.1.9-5.el7.noarch                                         5/7 
  Verifying  : virt-manager-common-1.4.0-2.el7.noarch                                   6/7 
  Verifying  : libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64                            7/7 

Installed:
  libvirt.x86_64 0:2.0.0-10.el7              virt-manager.noarch 0:1.4.0-2.el7             

Dependency Installed:
  libvirt-daemon-config-nwfilter.x86_64 0:2.0.0-10.el7                                      
  libvirt-daemon-driver-lxc.x86_64 0:2.0.0-10.el7                                           
  libvirt-python.x86_64 0:2.0.0-2.el7                                                       
  python-ipaddr.noarch 0:2.1.9-5.el7                                                        
  virt-manager-common.noarch 0:1.4.0-2.el7                                                  

Complete!

After the installation of the three packages required by kvm is complete, enter virt-manager in the terminal to open the graphical interface to manage kvm.

[root@localhost ~]# virt-manager

kvm virtual machine management interface
Create a new virtual machine in kvm
To run an operating system in kvm, you also need to create a new virtual machine.
In Virtual Machine Manager, select the New command.
insert image description here
After entering the new virtual machine wizard, select the way to install the operating system, here select network installation.
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
Enter the configuration page, find the following picture information to adjust.
insert image description here

insert image description here
After the addition is complete, select Start Installation.
insert image description here
insert image description here
insert image description here
Use virt-install to create a new virtual machine
If there is no virt-install command, you need to install it first.

[root@localhost ~]# yum install -y virt-install.noarch
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
redhat                                                   | 4.1 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package virt-install.noarch 0:1.4.0-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch           Version               Repository      Size
================================================================================
Installing:
 virt-install         noarch         1.4.0-2.el7           redhat          88 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 88 k
Installed size: 86 k
Downloading packages:
virt-install-1.4.0-2.el7.noarch.rpm                        |  88 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : virt-install-1.4.0-2.el7.noarch                              1/1 
  Verifying  : virt-install-1.4.0-2.el7.noarch                              1/1 

Installed:
  virt-install.noarch 0:1.4.0-2.el7                                             

Complete!

Then use the virt-install command to complete the new virtual machine.
virt-install --name=vm01 --file=/var/lib/libvirt/images/vm01.dsk --file-size=8 --nonsparse --graphics spice --vcpus=1 --ram=1024 -- location=ftp://192.168.217.139/dvd --network bridge=virbr0 --os-type=linux --os-variant=rhel7.3

[root@localhost ~]# virt-install --name=vm01 --file=/var/lib/libvirt/images/vm01.dsk --file-size=8 --nonsparse --graphics spice --vcpus=1 --ram=1024 --location=ftp://192.168.217.139/dvd --network bridge=virbr0 --os-type=linux --os-variant=rhel7.3
WARNING  Unable to connect to graphical console: virt-viewer not installed. Please install the 'virt-viewer' package.
WARNING  No console to launch for the guest, defaulting to --wait -1

Starting install...
Retrieving file vmlinuz...                                  | 5.1 MB  00:00     
Retrieving file initrd.img...                               |  43 MB  00:00     
Allocating 'vm01.dsk'                                       | 8.0 GB  00:00     
Creating domain...                                          |    0 B  00:03     
Domain installation still in progress. Waiting for installation to complete.

After the creation is complete, you can view the newly created virtual machine in virt-manager. Double-click to open the virtual machine to enter the installation interface.

Install rhel7 in the kvm virtual machine
and install the operating system in the rhel7-vm01 virtual machine.
insert image description here
insert image description here
insert image description here
insert image description here
It is found that after installation, you cannot enter content when you log in, so look back at the virtual machine configuration.
insert image description here
insert image description here
The previous settings did not save the application, and now after resetting, there is no problem.
insert image description here
insert image description here
Log in to rhel7-vm01 remotely through ssh on the host.
insert image description here
Note: When kvm installs a virtual machine, make sure that the current host has enough disk space, and the virtualization function of the host is turned on.

Guess you like

Origin blog.csdn.net/qq_26350199/article/details/114073268