KVM虚拟化介绍 安装

一、kvm虚拟化介绍

虚拟化分类

1、虚拟化,是指通过虚拟化技术将一台计算机虚拟为多台逻辑计算机。在一台计算机上同时运行多个逻辑计算机,每个逻辑计算机可运行不同的操作系统,并且应用程序都可以在相互独立的空间内运行而互相不影响,从而显著提高计算机的工作效率。

虚拟化使用软件的方法重新定义划分 IT 资源,可以实现 IT 资源的动态分配、灵活调度、跨域共享,提高 IT 资源利用率,使 IT 资源能够真正成为社会基础设施,服务于各行各业中灵活多变的应用需求。

2、虚拟化层次种类:

(1) 完全虚拟化 — 最流行的虚拟化方法使用名为 hypervisor 的一种软件,在虚拟服务器和底层硬件之间建立一个抽象层。 VMware 和微软的VirtualPC 是代表该方法的两个商用产品,而基于核心的虚拟机 (KVM) 是面向 Linux 系统的开源产品hypervisor 可以捕获 CPU 指令,为指令访问硬件控制器和外设充当中介。因而,完全虚拟化技术几乎能让任何一款操作系统不用改动就能安装到虚拟服务器上,而它们不知道自己运行在虚拟化环境下。主要缺点是, hypervisor 给处理器带来开销

(2)准虚拟化 — 完全虚拟化是处理器密集型技术,因为它要求 hypervisor管理各个虚拟服务器,并让它们彼此独立。减轻这种负担的一种方法就是,改动客户端操作系统,让它以为自己运行在虚拟环境下,能够与hypervisor 协同工作。这种方法就叫准虚拟化 (para-virtualization)Xen 是开源准虚拟化技术的一个例子。操作系统作为虚拟服务器在 Xen hypervisor 上运行之前,它必须在核心层面进行某些改变。因此, Xen 适用于 BSD 、 Linux 、 Solaris 及其他开源操作系统,但不适合对像Windows 这些专有的操作系统进行虚拟化处理,因为它们无法改动。准虚拟化技术的优点是性能高。经过准虚拟化处理的服务器可与hypervisor 协同工作,其响应能力几乎不亚于未经过虚拟化处理的服务器。准虚拟化与完全虚拟化相比优点明显,以至于微软和 VMware 都在开发这项技术,以完善各自的产品。

(3)系统虚拟化 — 就操作系统层的虚拟化而言,没有独立的hypervisor 层。相反,主机操作系统本身就负责在多个虚拟服务器之间分配硬件资源,并且让这些服务器彼此独立。一个明显的区别是,如果使用操作系统层虚拟化,所有虚拟服务器必须运行同一操作系统 ( 不过每个实例有各自的应用程序和用户。

账户 ) 。虽然操作系统层虚拟化的灵活性比较差,但本机速度性能比较高。此外,由于架构在所有虚拟服务器上使用单一、标准的操作系统,管理起来比异构环境要容易。

(4)桌面虚拟化 — 服务器虚拟化主要针对服务器而言,而虚拟化最接近用户的还是要算的上桌面虚拟化了,桌面虚拟化主要功能是将分散的桌面环境集中保存并管理起来,包括桌面环境的集中下发,集中更新,集中管理。桌面虚拟化使得桌面管理变得简单,不用每台终端单独进行维护,每台终端进行更新。终端数据可以集中存储在中心机房里,安全性相对传统桌面应用要高很多。桌面虚拟化可以使得一个人拥有多个桌面环境,也可以把一个桌面环境供多人使用。

3、虚拟化架构分类

(1)1型虚拟化
在这里插入图片描述
Hypervisor 直接安装在物理机上,多个虚拟机在 Hypervisor 上运行。Hypervisor 实现方式一般是一个特殊定制的 Linux 系统。Xen 和 VMWare 的 ESXi 都属于这个类型。
(2)2型虚拟化
在这里插入图片描述
物理机上首先安装常规的操作系统,比如 Redhat、Ubuntu 和 Windows。Hypervisor 作为 OS 上的一个程序模块运行,并对管理虚拟机进行管理。KVM、VirtualBox 和 VMWare Workstation 都属于这个类型。

KVM — 全称是基于内核的虚拟机(Kernel-based Virtual Machine)

是一个开源软件,基于内核的虚拟化技术,实际是嵌入系统的一个虚拟化模块,通过优化内核来使用虚拟技术,该内核模块使得 Linux 变成了一个Hypervisor,虚拟机使用 Linux 自身的调度器进行管理。

KVM 是基于虚拟化扩展(Intel VT 或者 AMD-V)的 X86 硬件的开源的 Linux 原生的全虚拟化解决方案。KVM 中,虚拟机被实现为常规的 Linux 进程,由标准 Linux 调度程序进行调度;虚机的每个虚拟 CPU 被实现为一个常规的 Linux 进程。这使得 KMV 能够使用 Linux 内核的已有功能。但是,KVM 本身不执行任何硬件模拟,需要客户空间程序通过 /dev/kvm 接口设置一个客户机虚拟服务器的地址空间,向它提供模拟的 I/O,并将它的视频显示映射回宿主的显示屏。目前这个应用程序是 QEMU。

Linux 上的用户空间、内核空间、虚机:

Guest:客户机系统,包括CPU(vCPU)、内存、驱动(Console、网卡、I/O 设备驱动等),被 KVM 置于一种受限制的 CPU 模式下运行。

KVM:运行在内核空间,提供CPU 和内存的虚级化,以及客户机的 I/O 拦截。Guest 的 I/O 被 KVM 拦截后,交给 QEMU 处理。

QEMU:修改过的为 KVM 虚机使用的 QEMU 代码,运行在用户空间,提供硬件 I/O 虚拟化,通过IOCTL /dev/kvm 设备和 KVM 交互。

4、KVM有一个内核模块叫 kvm.ko,只用于管理虚拟 CPU 和内存。IO 的虚拟化,就交给 Linux 内核和qemu来实现。

Libvirt:是 KVM 的管理工具。Libvirt 除了能管理 KVM 这种 Hypervisor,还能管理 Xen,VirtualBox 等。OpenStack 底层也使用 Libvirt。

Libvirt 包含 3 个东西:后台 daemon 程序 libvirtd、API 库和命令行工具 virsh

(1)libvirtd是服务程序,接收和处理 API 请求;

(2)API 库使得其他人可以开发基于 Libvirt 的高级工具,比如 virt-manager,这是个图形化的 KVM 管理工具,后面我们也会介绍;

(3)virsh 是我们经常要用的 KVM 命令行工具,后面会有使用的示例。作为 KVM 和 OpenStack 的实施人员,virsh 和 virt-manager 是一定要会用的。

虚拟化VT开启确认

KVM 本身也有一些弱点,那就是相比裸金属虚拟化架构的 Xen 、 VMware ESX 和 HyperV , KVM 是运行在 Linux 内核之上的寄居式虚拟化架构,会消耗比较多的计算资源;不过针对这一点, Intel 、 AMD 已经在处理器设计上有专门的VT-x 和 AMD-V 扩展,这种特性在每次硬件更新的时候也会更新,往往每次更新后都对虚拟化性能和速度上有明显的提升,所以长远来看,也不是什么大问题。

KVM 的虚拟化需要硬件支持(需要处理器支持虚拟化:如 Intel 厂商的 Intel-VT ( vmx )技术&&AMD 厂商的 AMD-V ( svm )技术。是基于硬件的完全虚拟化。而 Xen 早期则是基于软件模拟的半虚拟化( Para-Virtualization ),新版本则是基于硬件支持的完全虚拟化。但 Xen 本身有自己的进程调度器,存储管理模块等,所以代码较为庞大。

知识拓展:

CPU 虚拟化给我们带来了哪些好处?

CPU 的虚拟化技术可以将单 CPU 模拟多 CPU 并行,允许一个平台同时运行多个操作系统,并且应用程序都可以在相互独立的空间内运行而互不影响,从而显著提高计算机的工作效率。

虚拟化技术与多任务超线程的技术的区别?

虚拟化技术与多任务以及超线程技术是完全不同的。多任务是指在一个操作系统中多个程序同时并行运行,而在虚拟化技术中,则可以同时运行多个操作系统,而且每一个操作系统中都有多个程序运行,每一个操作系统都运行在一个虚拟的 CPU 或者是虚拟主机上;而超线程技术只是单 CPU 模拟双 CPU 来平衡程序运行性能,这两个模拟出来的 CPU 是不能分离的,只能协同工作。

kvm安装

环境:centos 7.7-1908
ip :
外网:10.0.0.41
内网: 176.16.1.41

1、关闭防火墙与selinux
[root@ c7-41 ~]# systemctl stop firewalld
[root@ c7-41 ~]# systemctl disable firewalld
[root@ c7-41 ~]# setenforce 0
[root@ c7-41 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
2、安装环境依赖
[root@ c7-41 ~]# yum -y install epel-release vim wget net-tools unzip zip gcc gcc-c++
3、配置环境修改网站访问并发量
#末尾添加  星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。
[root@ c7-41 ~]# cat /etc/security/limits.conf | grep -w "*" | grep -v "^#"
* soft nofile 65535                  
* hard nofile 65535

#末尾添加
[root@ c7-41 ~]# cat /etc/pam.d/login | sed -n "19p"
session    required     /lib/security/pam_limits.so

#末尾添加
[root@ c7-41 ~]# cat /etc/profile | grep -w "ulimit"
ulimit -n 65535

[root@ c7-41 ~]# source /etc/profile
[root@ c7-41 ~]# ulimit -n

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

在这里插入图片描述

[root@ c7-41 ~]#  egrep -o 'vmx|svm' /proc/cpuinfo
vmx
5、kvm安装
[root@ c7-41 ~]# 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

6、启动服务,验证安装结果
[root@ c7-41 ~]#  systemctl start libvirtd
[root@ c7-41 ~]# systemctl enable libvirtd
[root@ c7-41 ~]# lsmod|grep kvm
kvm_intel             188644  0
kvm                   621480  1 kvm_intel
irqbypass              13503  1 kvm
[root@ c7-41 ~]# virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------

[root@ c7-41 ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@ c7-41 ~]# ll /usr/bin/qemu-kvm
lrwxrwxrwx 1 root root 21 May  4 19:16 /usr/bin/qemu-kvm -> /usr/libexec/qemu-kvm

kvm web管理界面安装

kvm 的 web 管理界面是由 webvirtmgr 程序提供的

1、安装依赖包

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

#升级pip 
[root@ c7-41 ~]# pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 921kB/s
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
Successfully installed pip-20.1

pip 20.0.2文档 https://pip.pypa.io/en/stable/user_guide/#config-file
pip是一个很好用的第三方库安装方式,但是默认的源没法连接,就算有时候可以成功率也很低,所以换成国内镜像源比较方便。
将pip源更换到国内镜像

用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。

临时方法

阿里云 https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) https://pypi.douban.com/simple/ 
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/

从github上下载webvirtmgr代码

[root@ c7-41 ~]# cd /usr/local/src/
[root@ c7-41 src]# 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.98 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (3602/3602), done.

安装webvirtmgr

[root@ c7-41 webvirtmgr]# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting django==1.5.5
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/49/93511c5d3367b6b21fc2995a0e53399721afc15e4cd6eb57be879ae13ad4/Django-1.5.5.tar.gz (8.1 MB)
     |████████████████████████████████| 8.1 MB 4.6 MB/s
Collecting gunicorn==19.5.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f9/4e/f4076a1a57fc1e75edc0828db365cfa9005f9f6b4a51b489ae39a91eb4be/gunicorn-19.5.0-py2.py3-none-any.whl (113 kB)
     |████████████████████████████████| 113 kB 45.0 MB/s
Collecting lockfile>=0.9
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c8/22/9460e311f340cb62d26a38c419b1381b8593b0bb6b5d1f056938b086d362/lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Could not build wheels for django, since package 'wheel' is not installed.
Installing collected packages: django, gunicorn, lockfile
    Running setup.py install for django ... done
Successfully installed django-1.5.5 gunicorn-19.5.0 lockfile-0.12.2

检查sqlite3是否安装

[root@ c7-41 webvirtmgr]# python
Python 2.7.5 (default, Aug  7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> exit()

2、初始化帐号信息


[root@ c7-41 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'):
Email address: 154766385@qq.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)

拷贝web网页至指定目录
[root@ c7-41 webvirtmgr]# mkdir /var/www
[root@ c7-41 webvirtmgr]# cp -r /usr/local/src/webvirtmgr/ /var/www/
[root@ c7-41 webvirtmgr]# chown -R nginx.nginx /var/www/webvirtmgr/
生成密钥 首次生成直接回车,不是则Overwrite (y/n)? y 选择覆盖

[root@ c7-41 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:iZDG3XqewDYS7WXxhW2Gc3WpMiDGjkk5LkaGx+Rd6c0 root@c7-41
The key's randomart image is:
+---[RSA 2048]----+
|  +.  o.o  +... o|
| ..*.B.* ++.=  o |
|  +.O.X B o=  .  |
|   + O B E o .   |
|  . o O S   o    |
|     o = .       |
|        o        |
|                 |
|                 |
+----[SHA256]-----+

由于这里webvirtmgr和kvm服务部署在同一台机器,所以这里本地信任。如果kvm部署在其他机器,则需要更换ip
[root@ c7-41 webvirtmgr]# ssh-copy-id 10.0.0.41
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.0.0.41 (10.0.0.41)' can't be established.
ECDSA key fingerprint is SHA256:Zp63J/kTvnYc3to3flnLUoagIIVYMYA3hwcDdjoPFdA.
ECDSA key fingerprint is MD5:af:6d:49:41:09:7b:a5:e9:13:e1:51:1f:20:fc:31:17.
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@10.0.0.41's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '10.0.0.41'"
and check to make sure that only the key(s) you wanted were added.
端口转发,查看
[root@ c7-41 ~]# ss -antl
State      Recv-Q Send-Q           Local Address:Port                          Peer Address:Port
LISTEN     0      100                  127.0.0.1:25                                       *:*
LISTEN     0      128                  127.0.0.1:6080                                     *:*
LISTEN     0      128                  127.0.0.1:8000                                     *:*
LISTEN     0      128                          *:111                                      *:*
LISTEN     0      5                192.168.122.1:53                                       *:*
LISTEN     0      128                          *:22                                       *:*
LISTEN     0      100                      [::1]:25                                    [::]:*
LISTEN     0      128                      [::1]:6080                                  [::]:*
LISTEN     0      128                      [::1]:8000                                  [::]:*
LISTEN     0      128                       [::]:111                                   [::]:*
LISTEN     0      128                       [::]:22                                    [::]:*

配置nginx

[root@ c7-41 ~]# 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 {
        }
    }
}

添加webvirtmgr.conf
[root@ c7-41 ~]# 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@ c7-41 ~]# cat /var/www/webvirtmgr/conf/gunicorn.conf.py | sed -n "23,24p"
bind = '127.0.0.1:8000'
backlog = 2048

启动nginx
[root@ c7-41 nginx]# systemctl start nginx
设置supervisor
#末尾添加
[root@ c7-41 ~]# cat /etc/supervisord.conf | sed -n "130,146p"
[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

启动supervisor并设置开机自动启动
[root@ c7-41 nginx]# systemctl start supervisord
[root@ c7-41 nginx]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@ c7-41 nginx]# systemctl status supervisord
● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-05-04 19:33:43 CST; 16s ago
 Main PID: 9833 (supervisord)
   CGroup: /system.slice/supervisord.service
           ├─9833 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
           └─9969 /usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gun...

May 04 19:33:43 c7-41 systemd[1]: Starting Process Monitoring and Control Daemon...
May 04 19:33:43 c7-41 systemd[1]: Started Process Monitoring and Control Daemon.
May 04 19:33:44 c7-41 python2[9837]: detected unhandled Python exception in '/var/www/webvirtmgr/console...sole'
May 04 19:33:46 c7-41 python2[9869]: detected unhandled Python exception in '/var/www/webvirtmgr/console...sole'
May 04 19:33:49 c7-41 python2[9914]: detected unhandled Python exception in '/var/www/webvirtmgr/console...sole'
May 04 19:33:53 c7-41 python2[9944]: detected unhandled Python exception in '/var/www/webvirtmgr/console...sole'
Hint: Some lines were ellipsized, use -l to show in full.

配置nginx用户 未创建nginx用户,所以用su命令赋予它交互式登录的权限

[root@ c7-41 nginx]# su - nginx -s /bin/bash
[nginx@ c7-41 ~]$ 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:Jnd4sQ/eEe0wDl5Zd+OVxa0tP4Vpnw5yFiukfdz2IRk nginx@c7-41
The key's randomart image is:
+---[RSA 2048]----+
|              .oO|
|             +.o*|
|          o * .* |
|         o B E* o|
|      . S X +.B+o|
|       + = B @ *o|
|          . O = +|
|               ..|
|                 |
+----[SHA256]-----+


[nginx@ c7-41 ~]$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
[nginx@ c7-41 ~]$ chmod 0600 ~/.ssh/config
[nginx@ c7-41 ~]$ ssh-copy-id root@10.0.0.41
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/var/lib/nginx/.ssh/id_rsa.pub"
/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
Warning: Permanently added '10.0.0.41' (ECDSA) to the list of known hosts.
root@10.0.0.41's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@10.0.0.41'"
and check to make sure that only the key(s) you wanted were added.
[nginx@ c7-41 ~]$ exit
logout
[root@ c7-41 ~]# cat /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@ c7-41 nginx]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@ c7-41 nginx]# systemctl restart supervisord
[root@ c7-41 nginx]# systemctl restart libvirtd

kvm web界面管理

浏览器访问:http://10.0.0.41
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

通过远程连接软件上传ISO镜像文件至存储目录/var/lib/libvirt/images/
#上传镜像
[root@ c7-41 ~]# cd /var/lib/libvirt/images
[root@ c7-41 images]# ll
total 4554752
-rw-r--r-- 1 root root 4664066048 May  4 19:43 CentOS-7-x86_64-DVD-1908.iso
在web界面查看ISO镜像文件是否存在

在这里插入图片描述

创建系统安装镜像

在这里插入图片描述
在这里插入图片描述

kvm网络管理

在这里插入图片描述
在这里插入图片描述

实例管理 实例(虚拟机的创建)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

虚拟机插入光盘

在这里插入图片描述

设置在web上访问虚拟机的密码

在这里插入图片描述

启动虚拟机

在这里插入图片描述
在这里插入图片描述

虚拟机安装

在这里插入图片描述

接下来就是正常的虚拟机安装过程。

在这里插入图片描述

可能遇到的问题

1、web页面刷新不出来

虚拟机报错:命令行界面一直报错(too many open files)
解决方法:https://blog.51cto.com/inbank2012/1097939

2、控制台连接失败

在这里插入图片描述
如果出现上图报错或者连接超时
解决方法:

安装novnc并通过novnc_server启动一个vnc

[root@ c7-41 images]# yum -y install novnc
#在末尾添加
[root@ c7-41 ~]# cat /etc/rc.d/rc.local | grep "nohup"
nohup novnc_server 172.16.12.128:5920 &
[root@ c7-41 images]# . /etc/rc.d/rc.local
[root@ c7-41 images]# nohup: ignoring input and appending output to ‘nohup.out’
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值