kvm虚拟化

Posted ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kvm虚拟化相关的知识,希望对你有一定的参考价值。

kvm虚拟化

虚拟化简介

虚拟化是指计算机元件在虚拟的基础上而不是真实的基础上运行。虚拟化技术可以扩大硬件的容量,简化软件的重新配置过程。CPU的虚拟化技术可以单CPU模拟多CPU并行,允许一个平台同时运行多个操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率。
虚拟化是一个为了简化管理,优化资源的解决方案。如同空旷、通透的写字楼,整个楼层几乎看不到墙壁,用户可以用同样的成本构建出更加自主适用的办公空间,进而节省成本,发挥空间最大利用率。这种把有限的固定的资源根据不同需求进行重新规划以达到最大利用率的思路,在IT领域就叫做虚拟化技术。
虚拟化技术可以扩大硬件的容量,简化软件的重新配置过程。CPU的虚拟化技术可以单CPU模拟多CPU并行,允许一个平台同时运行多个操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率。
虚拟化技术与多任务以及超线程技术是完全不同的。多任务是指在一个操作系统中多个程序同时并行运行,而在虚拟化技术中,则可以同时运行多个操作系统,而且每一个操作系统中都有多个程序运行,每一个操作系统都运行在一个虚拟的CPU或者是虚拟主机上;而超线程技术只是单CPU模拟双CPU来平衡程序运行性能,这两个模拟出来的CPU是不能分离的,只能协同工作。
虚拟化技术也与VMware Workstation等同样能达到虚拟效果的软件不同,是一个巨大的技术进步,具体表现在减少软件虚拟机相关开销和支持更广泛的操作系统方面。
虚拟化对于不同的人来说可能意味着不同的东西,这要取决与他们所从事的工作领域的环境。通用的解释是它包含许多使服务器得到加强的虚拟机。有经验的程序员可能还记得,曾有一段时间他们担心是否有可用内存来存放自己的程序指令和数据。现在最基本的操作系统提供了虚拟内存的功能,这样程序员就不用再考虑这个问题了。
然而,虚拟化技术的内涵远远不止于虚拟内存和虚拟服务器。目前,我们已经有了网络虚拟化、微处理器 服务器虚拟化虚拟化、文件虚拟化和存储虚拟化等技术。如果我们在一个更广泛的环境中或从更高级的抽象(如任务负载虚拟化和信息虚拟化)来思考虚拟化技术,虚拟化技术就变成了一个非常强大的概念,可以为最终用户、应用程序和企业提供很多优点。
根据 Hypervisor 的实现方式和所处的位置,虚拟化又分为两种:
全虚拟化:Hypervisor 直接安装在物理机上,多个虚拟机在 Hypervisor 上运行。Hypervisor 实现方式一般是一个特殊定制的 Linux 系统。Xen 和 VMWare 的 ESXi 都属于这个类型
半虚拟化:物理机上首先安装常规的操作系统,比如 Redhat、Ubuntu 和 Windows。Hypervisor 作为 OS 上的一个程序模块运行,并对管理虚拟机进行管理。KVM、VirtualBox 和 VMWare Workstation 都属于这个类型

kvm简介

KVM,是Keyboard Video Mouse的缩写,KVM 通过直接连接键盘、视频和鼠标 (KVM) 端口,能够访问和控制计算机。KVM 技术无需目标服务器修改软件。这就意味着可以在Bios环境下,随时访问目标计算机。KVM 提供真正的主板级别访问,并支持多平台服务器和串行设备。KVM 技术已经从最初的基础SOHO办公型,发展成为企业 IT 基础机房设施管理系统。可以从kvm 客户端管理软件轻松的直接访问位于多个远程位置的服务器和设备。KVM over IP 解决方案具备完善的多地点故障转移功能、符合新服务器管理标准 (IPMI) 的直接界面,以及将本地存储媒体映射至远程位置的功能。

kvm虚拟化部署

环境准备

首先开启虚拟化功能

安装kvm

关闭防火墙和selinux

[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vi /etc/selinux/config 
SELINUX=disabled
[root@localhost ~]# reboot

安装工具

[root@localhost ~]# yum -y install epel-release vim wget net-tools unzip zip gcc gcc-c++

验证CPU是否支持KVM;如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU的支持的

[root@localhost ~]# egrep -o 'vmx|svm' /proc/cpuinfo
vmx
vmx
vmx
vmx

安装kvm

yum -y install qemu-kvm qemu-kvm-tools qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils libguestfs-tools

用br0来桥接ens33网卡

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-br0
[root@localhost network-scripts]# cat ifcfg-br0
TYPE=Bridge
DEVICE=br0
NM_CONTROLLED=no
BOOTPROTO=static
NAME=br0
ONBOOT=yes
IPADDR=192.168.247.50
NETMASK=255.255.255.0
GATEWAY=192.168.247.2
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@localhost network-scripts]# vim ifcfg-ens33 
[root@localhost network-scripts]# cat ifcfg-ens33 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=no

重启网卡

[root@localhost ~]# systemctl restart network
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 00:0c:29:d7:8d:e3 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fed7:8de3/64 scope link 
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:d7:8d:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.247.50/24 brd 192.168.247.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed7:8de3/64 scope link 
       valid_lft forever preferred_lft forever

启动服务

[root@localhost ~]# systemctl enable --now libvirtd
[root@localhost ~]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-06-19 02:46:32 CST; 9s ago
     Docs: man:libvirtd(8)
           https://libvirt.org
 Main PID: 2960 (libvirtd)
    Tasks: 19 (limit: 32768)
   CGroup: /system.slice/libvirtd.service
           ├─2960 /usr/sbin/libvirtd
           ├─3074 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq...
           └─3075 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq...

Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: started, version 2....
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: compile time option...
Jun 19 02:46:33 localhost.localdomain dnsmasq-dhcp[3074]: DHCP, IP range...
Jun 19 02:46:33 localhost.localdomain dnsmasq-dhcp[3074]: DHCP, sockets ...
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: reading /etc/resolv...
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: using nameserver 11...
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: using nameserver 8....
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: read /etc/hosts - 2...
Jun 19 02:46:33 localhost.localdomain dnsmasq[3074]: read /var/lib/libvi...
Jun 19 02:46:33 localhost.localdomain dnsmasq-dhcp[3074]: read /var/lib/...
Hint: Some lines were ellipsized, use -l to show in full.

验证安装结果

[root@localhost ~]# lsmod|grep kvm
kvm_intel             188740  0 
kvm                   637289  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]# virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------

[root@localhost ~]# virsh --version
4.5.0
[root@localhost ~]# virt-install --version
1.5.0
[root@localhost ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@localhost ~]# ll /usr/bin/qemu-kvm
lrwxrwxrwx 1 root root 21 Jun 19 02:48 /usr/bin/qemu-kvm -> /usr/libexec/qemu-kvm

查看网桥信息

[root@localhost ~]# brctl show 
bridge name	bridge id		STP enabled	interfaces
br0		8000.000c29d78de3	no		ens33
virbr0		8000.525400f76263	yes		virbr0-nic

kvm web 页面安装

安装依赖包

[root@localhost ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx python-devel

从github上下载webvirtmgr代码

[root@localhost ~]# git clone git://github.com/retspen/webvirtmgr.git
Cloning into 'webvirtmgr'...
remote: Enumerating objects: 5614, done.
remote: Total 5614 (delta 0), reused 0 (delta 0), pack-reused 5614
Receiving objects: 100% (5614/5614), 2.97 MiB | 1.25 MiB/s, done.
Resolving deltas: 100% (3606/3606), done.

安装webvirtmgr

[root@localhost ~]# git clone git://github.com/retspen/webvirtmgr.git
Cloning into 'webvirtmgr'...
remote: Enumerating objects: 5614, done.
remote: Total 5614 (delta 0), reused 0 (delta 0), pack-reused 5614
Receiving objects: 100% (5614/5614), 2.97 MiB | 1.25 MiB/s, done.
Resolving deltas: 100% (3606/3606), done.
[root@localhost ~]# cd webvirtmgr/
[root@localhost webvirtmgr]# cat requirements.txt 
django==1.5.5
gunicorn==19.5.0
# Utility Requirements
# for SECURE_KEY generation
lockfile>=0.9
# Uncoment for support ldap
#django-auth-ldap==1.2.0
[root@localhost webvirtmgr]# pip install -r requirements.txt 

检查sqlite3是否安装

[root@localhost webvirtmgr]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> exit()

初始化账号信息

[root@localhost webvirtmgr]# python manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table servers_compute
Creating table instance_instance
Creating table create_flavor

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes  //是否创建超级管理员账号
Username (leave blank to use 'root'):     //直接回车默认为root
Email address: 1228322088@qq.com  
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)

将网站移值指定目录并设置属组和属主

[root@localhost webvirtmgr]# mkdir -p /var/www
[root@localhost webvirtmgr]# cp -r /root/webvirtmgr/ /var/www/
[root@localhost webvirtmgr]# chown -R nginx.nginx /var/www/webvirtmgr/

因为要用192.168.247.51的web页面来管理192.168.247.50的kvm,所以要做免密登录,将web主机的公钥给kvm主机

[root@localhost webvirtmgr]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:N+wmjKqtQTxmftfwCOe6gzOLEbHC+3BfHPg8Ff5sbUU root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|.        .     E |
|.+    . ...   .  |
|+.* ..o.So+    . |
|.*.. ++Booo.. .  |
|.ooo. =*= o+ o   |
| oB+o+. .o. .    |
|. +B=+           |
+----[SHA256]-----+
[root@localhost webvirtmgr]# ssh-copy-id 192.168.247.50
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.247.50 (192.168.247.50)' can't be established.
ECDSA key fingerprint is SHA256:w6Kbwkn18/Aj5eoWDcNRGLWpWsdEa6r4gYvyX8ZBKeQ.
ECDSA key fingerprint is MD5:e8:7f:6c:96:23:f1:e8:e3:4e:cd:1e:7f:50:d7:a9:38.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.247.50's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.247.50'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost webvirtmgr]# ssh 192.168.247.50
Last login: Sat Jun 19 03:08:24 2021 from 192.168.247.1
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 00:0c:29:d7:8d:e3 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:d7:8d:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.247.50/24 brd 192.168.247.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed7:8de3/64 scope link 
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:f7:62:63 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:f7:62:63 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# exit
logout
Connection to 192.168.247.50 closed.

配置nginx

[root@localhost webvirtmgr]# cd /etc/nginx/
[root@localhost nginx]# mv nginx.conf nginx.conf-bak
[root@localhost nginx]# vim /etc/nginx/nginx.conf
[root@localhost nginx]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events 
    worker_connections 1024;


http 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server 
        listen       80;
        server_name  localhost;

        include /etc/nginx/default.d/*.conf;

        location / 
            root html;
            index index.html index.htm;
        

        error_page 404 /404.html;
            location = /40x.html 
        

        error_page 500 502 503 504 /50x.html;
            location = /50x.html 
        
    

[root@localhost nginx]# vim /etc/nginx/conf.d/webvirtmgr.conf
[root@localhost nginx]# cat /etc/nginx/conf.d/webvirtmgr.conf 
server 
    listen 80 default_server;

    server_name $hostname;
    #access_log /var/log/nginx/webvirtmgr_access_log;

    location /static/ 
        root /var/www/webvirtmgr/webvirtmgr;
        expires max;
    

    location / 
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-Proto $remote_addr;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        client_max_body_size 1024M;
    

修改bind绑定的是本机的8000端口

[root@localhost nginx]# vim /var/www/webvirtmgr/conf/gunicorn.conf.py 
bind = '0.0.0.0:8000'
backlog = 2048

修改supervisord.conf文件

[root@localhost nginx]# cat >> /etc/supervisord.conf <<EOF
> [program:webvirtmgr]
> command=/usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
> directory=/var/www/webvirtmgr
> autostart=true
> autorestart=true
> logfile=/var/log/supervisor/webvirtmgr.log
> log_stderr=true
> user=nginx
> 
> [program:webvirtmgr-console]
> command=/usr/bin/python2 /var/www/webvirtmgr/console/webvirtmgr-console
> directory=/var/www/webvirtmgr
> autostart=true
> autorestart=true
> stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
> redirect_stderr=true
> user=nginx
> EOF

启动supervisord

[root@localhost nginx]# systemctl enable --now supervisord
[root@localhost nginx]# systemctl restart nginx
[root@localhost nginx]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128       *:8000                  *:*                  
LISTEN      0      100       *:6080                  *:*                  
LISTEN      0      128       *:111                   *:*                  
LISTEN      0      128       *:80                    *:*                  
LISTEN      0      5      192.168.122.1:53                    *:*                  
LISTEN      0      128       *:22                    *:*                  
LISTEN      0      100    127.0.0.1:25                    *:*                  
LISTEN      0      128    127.0.0.1:6010                  *:*                  
LISTEN      0      128    [::]:111                [::]:*                  
LISTEN      0      128    [::]:22                 [::]:*                  
LISTEN      0      100       [::1]:25                 [::]:*                  
LISTEN      0      128       [::1]:6010               [::]:*    

配置nginx账户

[root@localhost nginx]# su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/nginx/.ssh/id_rsa): 
Created directory '/var/lib/nginx/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /var/lib/nginx/.ssh/id_rsa.
Your public key has been saved in /var/lib/nginx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:dtfZyqMBdsKY5IIHy9EgsQVAavRcAtBnI2Ln3FkONUg nginx@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|=*=++Eoo         |
|+.==*= ..        |
|oo=*+.* .        |
|.  + B + +   . o |
|    + o S * o o .|
|     . o o = . . |
|            . +  |
|             o . |
|            .    |
+----[SHA256]-----+
-bash-4.2$ ssh-copy-id root@192.168.247.50
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/lib/nginx/.ssh/id_rsa.pub"
The authenticity of host '192.168.247.50 (192.168.247.50)' can't be established.
ECDSA key fingerprint is SHA256:w6Kbwkn18/Aj5eoWDcNRGLWpWsdEa6r4gYvyX8ZBKeQ.
ECDSA key fingerprint is MD5:e8:7f:6c:96:23:f1:e8:e3:4e:cd:1e:7f:50:d7:a9:38.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.247.50's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.247.50'"
and check to make sure that only the key(s) you wanted were added.

-bash-4.2$ exit
logout

[root@localhost nginx]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:root
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@localhost nginx]# systemctl restart nginx
[root@localhost ~]# systemctl restart libvirtd     //(kvm)主机

web界面操作


配置了免密登录所以用ssh连接

创建存储

[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     2.9G     0  2.9G   0% /dev
tmpfs                        2.9G     0  2.9G   0% /dev/shm
tmpfs                        2.9G   12M  2.9G   1% /run
tmpfs                        2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/mapper/centos_192-root   50G  2.0G   49G   4% /
/dev/mapper/centos_192-home   44G   33M   44G   1% /home
/dev/sda1                   1014M  152M  863M  15% /boot
tmpfs                        585M     0  585M   0% /run/user/0
[root@localhost ~]# mkdir kvm


进入此存储

[root@localhost kvm]# ls
CentOS-Stream-8-x86_64-20201211-dvd1.iso













故障案例

案例1

web界面配置完成后可能会出现以下错误界面

解决方法是安装novnc并通过novnc_server启动一个vnc

[root@localhost ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Aug  6  2018 /etc/rc.local -> rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 513 Mar 11 22:35 /etc/rc.d/rc.local
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 513 Mar 11 22:35 /etc/rc.d/rc.local

[root@localhost ~]# vim /etc/rc.d/rc.local
......此处省略N行
# that this script will be executed during boot.

touch /var/lock/subsys/local
nohup novnc_server 172.16.12.128:5920 &

[root@localhost ~]# . /etc/rc.d/rc.local

做完以上操作后再次访问即可正常访问

案例2

第一次通过web访问kvm时可能会一直访问不了,一直转圈,而命令行界面一直报错(too many open files)

此时需要对nginx进行配置

[root@localhost ~]# vim /etc/nginx/nginx.conf
....此处省略N行
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 655350;    //添加此行配置

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
....此处省略N行

[root@localhost ~]# systemctl restart nginx

然后对系统参数进行设置

[root@localhost ~]# vim /etc/security/limits.conf
....此处省略N行
# End of file
* soft nofile 655350
* hard nofile 655350

以上是关于kvm虚拟化的主要内容,如果未能解决你的问题,请参考以下文章

kvm创建新虚拟机

实时 KVM —— 实时虚拟化可能吗?

libvirt-java怎么获得kvm虚拟机内存使用率

libvirt-java怎么获得kvm虚拟机内存使用率

KVM虚拟机快照备份

KVM虚拟机安装