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: [email protected]
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
[email protected]'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 [email protected]
/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.
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
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’
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章