kvm虚拟化
一、虚拟化介绍
虚拟化是一种将计算机资源进行抽象化的技术,可以将一台物理计算机划分为多个虚拟计算机,每个虚拟计算机都具有独立的操作系统和应用程序。通过虚拟化,可以将计算机的处理能力、存储空间和网络带宽等资源进行有效的利用和管理。
虚拟化技术有多种形式,包括服务器虚拟化、存储虚拟化和网络虚拟化等。其中,服务器虚拟化是最常见的形式,它可以将一台物理服务器划分为多个虚拟服务器,每个虚拟服务器都可以独立运行不同的操作系统和应用程序。这样可以提高服务器的利用率,减少硬件成本,并且方便管理和维护。
虚拟化技术的好处包括:
- 资源利用率提高:通过虚拟化,可以将计算机的资源进行合理的分配和利用,提高资源的利用率,减少资源的浪费。
- 灵活性增强:虚拟化可以将计算机的资源进行灵活的配置和管理,可以根据需求动态地分配资源,提高系统的灵活性和可扩展性。
- 管理简化:虚拟化可以将多个物理计算机集中管理,简化了系统的管理和维护工作,提高了管理效率。
- 高可用性:通过虚拟化,可以实现虚拟机的快速迁移和容错,提高系统的可用性和容灾能力。
虚拟化技术在云计算、数据中心和企业IT环境中得到广泛应用,为用户提供了更加灵活、可靠和高效的计算资源。
二、虚拟化的优势:
- 提高资源利用率:通过虚拟化,可以将多个虚拟计算机运行在同一台物理计算机上,提高资源的利用率
- .灵活性和可扩展性:通过虚拟化,可以动态分配和调整资源,满足不同应用程序和工作负载的需求
- 简化管理和部署:通过虚拟化,可以集中管理和部署虚拟计算机,简化系统管理和维护
- 提高可靠性和灾备能力:通过虚拟化,可以实现虚拟机的快速备份、迁移和恢复,提高系统的可靠性和灾备能力
三、全虚拟化和半虚拟化
根据 Hypervisor 的实现方式和所处的位置,虚拟化又分为两种:
- 全虚拟化
- 半虚拟化
全虚拟化:
Hypervisor 直接安装在物理机上,多个虚拟机在 Hypervisor 上运行。Hypervisor 实现方式一般是一个特殊定制的 Linux 系统。Xen 和 VMWare 的 ESXi 都属于这个类型
半虚拟化:
物理机上首先安装常规的操作系统,比如 Redhat、Ubuntu 和 Windows。Hypervisor 作为 OS 上的一个程序模块运行,并对管理虚拟机进行管理。KVM、VirtualBox 和 VMWare Workstation 都属于这个类型
理论上讲:
全虚拟化一般对硬件虚拟化功能进行了特别优化,性能上比半虚拟化要高;
半虚拟化因为基于普通的操作系统,会比较灵活,比如支持虚拟机嵌套。嵌套意味着可以在KVM虚拟机中再运行KVM。
四、kvm介绍
KVM(Kernel-based Virtual Machine)是一种开源的虚拟化解决方案,它是基于Linux内核的虚拟化模块。KVM允许在同一台物理计算机上同时运行多个虚拟机,每个虚拟机可以运行自己的操作系统,并与物理计算机共享硬件资源。
KVM的工作原理是通过将Linux内核转变为一个虚拟机管理程序(Hypervisor),它可以直接访问物理计算机的硬件资源,并为虚拟机提供虚拟化的功能。KVM使用硬件辅助虚拟化技术(如Intel VT或AMD-V)来提高性能和安全性。
五、kvm部署
准备工作
主机说明 | 主机名 | IP | 系统 |
---|---|---|---|
kvm服务机 | kvm | 192.168.10.136 | CentOS-7 |
kvm web机 | kVm-web | 192.168.10.135 | CentOS-7 |
部署前请确保你的CPU虚拟化功能已开启。分为两种情况:
- 虚拟机要设置虚拟化Intel VT-x/EPT 或AMD-V/RVI(V)
- 物理机要在BIOS里开启CPU虚拟化
关闭防火墙和selinux
[root@kvm ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@kvm ~]# setenforce 0
[root@kvm ~]# sed -i s/SELINUX=.*/SELINUX=disabled/ /etc/selinux/config
配置yum源
[root@kvm ~]# rm -rf /etc/yum.repos.d/*
[root@kvm ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@kvm ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@kvm ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@Kvm ~]# yum makecache
安装kvm
验证CPU是否支持KVM
[root@Kvm ~]# egrep -o 'vmx|svm' /proc/cpuinfo #如果结果中有vmx(Intel)或svm(AMD)字样,就说明CPU是支持的kvm的
vmx
vmx
vmx
vmx
vmx
vmx
vmx
vmx
[root@Kvm ~]#
安装工具包
[root@Kvm ~]# yum -y install epel-release vim wget net-tools unzip zip gcc gcc-c++
安装kvm
[root@localhost ~]# 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
虚拟机中的网段要好物理机的网段一致,否则不能通信,所有我们要把虚拟机设置成桥接模式。这样的话KVM的虚拟机就可以通过该桥接网卡和公司内部其他服务器处于同一网段。
[root@Kvm ~]# cd /etc/sysconfig/network-scripts/ #进入存放网卡配置文件的目录
[root@Kvm network-scripts]# ls
ifcfg-ens33 #我的主机上的网卡配置文件叫这个名字
[root@Kvm network-scripts]# cp ifcfg-ens33 ifcfg-br0 #复制一份并改名
[root@Kvm network-scripts]# ls
ifcfg-br0 ifcfg-ens33
[root@Kvm network-scripts]#
修改ifcfg-br0网卡配置文件
[root@Kvm network-scripts]# vim ifcfg-br0
TYPE="Bridge"
NM_CONTROLLED="no"
BOOTPROTO="static"
DEFROUTE="yes"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
IPADDR=192.168.10.135
NETMASK=255.255.255.0
GATEWAY=192.168.10.2
DNS1=114.114.114.114
修改真实网卡配置文件
[root@Kvm network-scripts]# vim ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
BRIDGE="br0"
NM_CONTROLLED="no" #删掉IP地址,网关、DNS改为BRIDGE=br,意思是桥接到bro网卡
[root@Kvm network-scripts]#
重启网络服务
[root@Kvm network-scripts]# ifdown ens33;ifup ens33 #禁用再开启网卡
[root@Kvm network-scripts]# systemctl restart network #重启网卡
将 libvirtd 服务设为开机自启
[root@kvm network-scripts]# systemctl enable --now libvirtd
[root@kvm network-scripts]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-10-18 00:22:10 CST; 3s ago
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 2516 (libvirtd)
Tasks: 19 (limit: 32768)
CGroup: /system.slice/libvirtd.service
├─2516 /usr/sbin/libvirtd
├─2627 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/u...
└─2628 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/u...
[root@kvm ~]# 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:a5:57:0d brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fea5:570d/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:a5:57:0d brd ff:ff:ff:ff:ff:ff
inet 192.168.10.135/24 brd 192.168.10.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea5:570d/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:af:da:1a 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:af:da:1a brd ff:ff:ff:ff:ff:ff
验证安装结果
[root@kvm ~]# lsmod|grep kvm
kvm_intel 174841 0
kvm 578518 1 kvm_intel
irqbypass 13503 1 kvm
[root@kvm ~]#
测试并验证安装结果
[root@kvm ~]# virsh -c qemu:///system list #测试并验证安装结果
Id Name State
----------------------------------------------------
[root@kvm ~]# virsh --version #查看virsh的版本号
4.5.0
[root@kvm ~]# virt-install --version #查看virsh-install的版本号
1.5.0
[root@kvm ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
[root@kvm ~]#
[root@kvm ~]# ll /usr/bin/qemu-kvm #做一个软连接
lrwxrwxrwx 1 root root 21 Oct 18 00:23 /usr/bin/qemu-kvm -> /usr/libexec/qemu-kvm
[root@kvm ~]# which qemu-kvm
/usr/bin/qemu-kvm
[root@kvm ~]#
[root@kvm ~]# lsmod |grep kvm #查看有没有kvm模块
kvm_intel 174841 0
kvm 578518 1 kvm_intel
irqbypass 13503 1 kvm
[root@kvm ~]# brctl show #查看网桥信息
bridge name bridge id STP enabled interfaces
br0 8000.000c29a5570d no ens33
virbr0 8000.525400db538d yes virbr0-nic
[root@kvm ~]#
部署kvm web管理界面
kvm 的 web 管理界面是由 webvirtmgr 程序提供的。
安装依赖包
[root@kvm-web ~]# yum -y install git python2-pip python3-pip libvirt-python libxml2-python python-websockify supervisor nginx python-devel
从github上下载webvirtmgr代码
[root@kvm-web ~]# git clone https://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 | 305.00 KiB/s, done.
Resolving deltas: 100% (3606/3606), done.
[root@kvm-web ~]# ls
anaconda-ks.cfg webvirtmgr
[root@kvm-web ~]#
安装webvirtmgr
[root@kvm-web ~]# cd webvirtmgr/
[root@kvm-web webvirtmgr]# pip install -r requirements.txt
Collecting django==1.5.5 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/38/49/93511c5d3367b6b21fc2995a0e53399721afc15e4cd6eb57be879ae13ad4/Django-1.5.5.tar.gz (8.1MB)
100% |████████████████████████████████| 8.1MB 48kB/s
Collecting gunicorn==19.5.0 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/f9/4e/f4076a1a57fc1e75edc0828db365cfa9005f9f6b4a51b489ae39a91eb4be/gunicorn-19.5.0-py2.py3-none-any.whl (113kB)
100% |████████████████████████████████| 122kB 78kB/s
Collecting lockfile>=0.9 (from -r requirements.txt (line 5))
Downloading https://files.pythonhosted.org/packages/c8/22/9460e311f340cb62d26a38c419b1381b8593b0bb6b5d1f056938b086d362/lockfile-0.12.2-py2.py3-none-any.whl
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
You are using pip version 8.1.2, however version 23.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@kvm webvirtmgr]#
检查sqlite3是否安装
[root@kvm-web webvirtmgr]# python
Python 2.7.5 (default, Jun 20 2023, 11:36:40)
[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@kvm-web webvirtmgr]#
初始化帐号信息
[root@kvm-web 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'): admin #设定web端超级管理员账号名称
Email address: 3198621637@qq.com #设定超级管理员邮箱
Password: #设置密码
Password (again): #确认密码密码
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
拷贝web网页至指定目录
[root@kvm-web ~]# mkdir /var/www
[root@kvm-web ~]# cp -r webvirtmgr /var/www/
[root@kvm-web ~]# ls /var/www/
webvirtmgr
[root@kvm-web ~]# chown -R nginx.nginx /var/www/webvirtmgr/
[root@kvm-web ~]# ll /var/www/
total 4
drwxr-xr-x 20 nginx nginx 4096 Oct 18 10:26 webvirtmgr
[root@kvm-web ~]#
给本机的root用户配置免密登录
生成密钥
[root@kvm-web ~]# 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:ttwJ/QxC5o1rSiEW4XogABP+z/t1OrUmvoDe/XYY39E root@kvm
The key's randomart image is:
+---[RSA 2048]----+
|*. . |
|o. . . |
|... o o |
| ..o . + + |
| ..+ . S + .|
| oo..+ * B .E|
| +..=.+.B . .|
| ..oo+oo= o . |
| ooo.=B.. |
+----[SHA256]-----+
发送密钥给kvm主机
[root@kvm-web ~]# ssh-copy-id root@192.168.10.136 #密钥发送给kvm主机
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.135 (192.168.10.135)' can't be established.
ECDSA key fingerprint is SHA256:w4w55e2nJ/D8mNis2rairBPM/yT758efmqgkmbld4+w.
ECDSA key fingerprint is MD5:98:66:6b:e7:25:47:7c:f5:5a:b3:00:49:bc:a8:bb:2a.
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.10.135's password: #这里输入root用户的密码
Permission denied, please try again.
root@192.168.10.135's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.10.135'"
and check to make sure that only the key(s) you wanted were added.
此时root用户可以免密登录对方主机
[root@kvm-web ~]# ssh root@192.168.10.135
Last login: Thu Oct 19 10:01:30 2023 from 192.168.10.136
[root@kvm ~]# exit
logout
Connection to 192.168.10.135 closed.
[root@kvm-web ~]#
配置端口转发
[root@kvm-web ~]# ssh 192.168.10.136 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60
Last login: Wed Oct 18 10:20:22 2023 from 192.168.10.10
[root@kvm ~]# exit #这里一定要退出ssh
logout
配置nginx
#先备份原配置文件
[root@kvm-web ~]# mv /etc/nginx/nginx.conf /opt/
#直接替换下面的内容
[root@kvm-web ~]# vim /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 {
}
}
}
配置nginx的虚拟主机
[root@kvm-web ~]# vim /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@kvm-web ~]# ls /var/www/webvirtmgr/conf/
conf.d gunicorn.conf.py init initd libvirt-bootstrap.sh saltstack
[root@kvm-web ~]#
[root@kvm-web ~]# vim /var/www/webvirtmgr/conf/gunicorn.conf.py
...
bind = '0.0.0.0:8000' #确保此处绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口
backlog = 2048
...
[root@kvm ~]#
将nginx服务设为开机自启
[root@kvm-web ~]# systemctl enable --now nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@kvm-web ~]#
设置supervisor,直接在最后面添加以下内容
[root@kvm-web ~]# vim /etc/supervisord.conf
...
[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
设置supervisord开机自启
[root@kvm-web ~]# systemctl enable --now supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
配置nginx用户
[root@kvm-web ~]# su - nginx -s /bin/bash #进入nginx用户
-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:YRbYMYh/piJI5KoXSyaz7y9ZSSI4rmYMpbXmsGq3Jj4 nginx@kvm-web
The key's randomart image is:
+---[RSA 2048]----+
| . ++. |
| . . o .o |
|+ . + |
|+o+ . .oo. |
|+B + . +S |
|O.B + . |
|=@ * . |
|=E*o |
|B=B+o |
+----[SHA256]-----+
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ chmod 0600 ~/.ssh/config
-bash-4.2$ ssh-copy-id root@192.168.10.135 #将公钥发送到kvm web端超级管理员用户所在的~/.ssh/authorized_keys文件中
/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 '192.168.10.135' (ECDSA) to the list of known hosts.
root@192.168.10.135's password: #等待时间可能会很长
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.10.135'"
and check to make sure that only the key(s) you wanted were added.
-bash-4.2$ exit
logout
[root@kvm-web ~]#
生成配置文件
[root@kvm-web ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@kvm-web ~]# 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@kvm-web ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
重启nginx服务
[root@kvm-web ~]# systemctl restart nginx
重启kvm主机上的kvm服务
[root@kvm-web ~]# ssh root@192.168.10.136 "systemctl restart libvirtd" #如果之前的免密登录成功则不需要输入密码
[root@kvm-web ~]#
重启主机
[root@kvm-web ~]# reboot
kvm web界面管理
安装novnc并通过novnc_server启动一个vnc
[root@kvm ~]# yum -y install novnc
[root@kvm ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Apr 11 2018 /etc/rc.d/rc.local
[root@kvm ~]# chmod +x /etc/rc.d/rc.local
[root@kvm ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 473 Apr 11 2018 /etc/rc.d/rc.local
[root@kvm ~]#
[root@kvm ~]# vim /etc/rc.d/rc.local
...
# that this script will be executed during boot.
touch /var/lock/subsys/local
nohup novnc_server 172.16.12.128:5920 &
[root@kvm ~]#
[root@kvm ~]# . /etc/rc.d/rc.local
nohup: ignoring input and appending output to ‘nohup.out’
#直接回车
[1]+ Exit 1 nohup novnc_server 172.16.12.128:5920
[root@kvm ~]#
用kvm-web主机的ip访问
账户和密码是之前设置过的admin
kvm连接管理
创建ssh连接
kvm存储管理
创建存储
因为它的存储库位置在/var/lib/libvirt/images 路径下,所有我们要把镜像放到这个位置
[root@kvm ~]# ls
anaconda-ks.cfg CentOS-Stream-8-x86_64-20220228-dvd1.iso #这个是镜像文件
[root@kvm ~]# mv CentOS-Stream-8-x86_64-20220228-dvd1.iso /var/lib/libvirt/images/
[root@kvm ~]# ls /var/lib/libvirt/images/
CentOS-Stream-8-x86_64-20220228-dvd1.iso
[root@kvm ~]#
重新加载网页
创建系统安装镜像
自定义虚拟机名称和磁盘大小
添加成功如下图所示
kvm网络管理
添加桥接网络
桥接网络添加成功
kvm虚机实例管理
创建一个虚拟机
设置虚拟机参数
连接光盘至虚拟机
设置在 web 上访问虚拟机的密码
启动虚拟机
虚拟机系统安装
成功登录并访问外网