CentOS 7 安装部署 KVM

1.关闭虚拟机

打开相关选项

打开虚拟机centos7

连接xshell

测试网络,现在就是没问题的,因为我们要使用网络源

安装 GNOME 桌面环境

安装KVM 模块

安装KVM 调试工具

构建虚拟机的命令行工具

qemu 组件,创建磁盘、启动虚拟机等

输入这条命令,只要有输出,就是支持虚拟化

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbas~~~~

检查 KVM 模块是否安装:

将 系 统 的 默 认 运 行 target 更 改 为

graphical.targe。

root@localhost \~\]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target 开启 libvirtd 服务,以开启相关支持。 \[root@localhost \~\]# systemctl start libvirtd \[root@localhost \~\]# systemctl enable libvirtd \[root@localhost \~\]# virt-manager ![](https://i-blog.csdnimg.cn/direct/57150c923a6a483d92556ae51dc8ac5e.png)[http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso](http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso "http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso") 进入这个目录 \[root@localhost images\]# pwd /var/lib/libvirt/images 在这个目录当中上传一个centos7镜像,这个比较小 \[root@localhost images\]# ll 总用量 996352 -rw-r--r--. 1 root root 1020264448 6月 24 16:52 CentOS-7-x86_64-Minimal-2009.iso \[root@localhost images\]# ![](https://i-blog.csdnimg.cn/direct/ef25b9ab74884be3a0440d9e09e793f5.png) ![](https://i-blog.csdnimg.cn/direct/151f3eded262464eb283ebc0d982316e.png) ![](https://i-blog.csdnimg.cn/direct/3273653d9d8944bfb8664f1f1980dced.png) ![](https://i-blog.csdnimg.cn/direct/cb5094c58e7343728a231e37cc6df059.png) ![](https://i-blog.csdnimg.cn/direct/0902b9410d8f45c19612aa4b2415fd7a.png)![](https://i-blog.csdnimg.cn/direct/dc0e0a5c96454a50bf1915602fc173d2.png)![](https://i-blog.csdnimg.cn/direct/2e98d32b2add4c83b9a17870ec407cf9.png)![](https://i-blog.csdnimg.cn/direct/a93282189f074526920fd20ea535b1d3.png)![](https://i-blog.csdnimg.cn/direct/5dae06ab3053415bbc28e4d0f7988f69.png)![](https://i-blog.csdnimg.cn/direct/7784e2b33854411d8e1bbca13e5192ad.png)![](https://i-blog.csdnimg.cn/direct/18a889ed70db4e738595a4564622644b.png)![](https://i-blog.csdnimg.cn/direct/062dfb31ae204d2b8f0066e96656ffc7.png) 然后,点击"开始安装" ![](https://i-blog.csdnimg.cn/direct/0c99803484df44a0b14ba5c9bab0e2cb.png)![](https://i-blog.csdnimg.cn/direct/9afc0bb00a4442b49efa3843909c3633.png)![](https://i-blog.csdnimg.cn/direct/560175a6ce454ef9ad5a109e6470daad.png) 重启就可以了 ![](https://i-blog.csdnimg.cn/direct/e9ff4eb9236a4954ad8f7b902b890db1.png) 我们已经进入到字符界面了 ![](https://i-blog.csdnimg.cn/direct/94130c487c93463db5bfb261fa67eab2.png) 使用管理员用户登录 ![](https://i-blog.csdnimg.cn/direct/7c511fe61d424a16b31651bdd9f095f7.png)发现迷你版的镜像没有ifcofig命令 yum -y install net-tools ![](https://i-blog.csdnimg.cn/direct/cfddeda652884f1a80f8d994747f0052.png) ![](https://i-blog.csdnimg.cn/direct/62b8a5041af3497e9b6246412f237959.png)\[root@localhost \~\]# virsh -h //查看命令帮助 virsh \[options\]... \[\

virsh [options]... <command> [args...]

options:

-c | --connect=URI hypervisor connection URI

-d | --debug=NUM debug level [0-4]

-e | --escape <char> set escape sequence for console

-h | --help this help

-k | --keepalive-interval=NUM

keepalive interval in seconds, 0 for disable

-K | --keepalive-count=NUM

number of possible missed keepalive messages

-l | --log=FILE output logging to file

-q | --quiet quiet mode

-r | --readonly connect readonly

-t | --timing print timing information

-v short version

-V long version

--version[=TYPE] version, TYPE is short or long (default short)

commands (non interactive mode):

Domain Management (help keyword 'domain')

attach-device 从一个XML文件附加装置

attach-disk 附加磁盘设备

attach-interface 获得网络界面

autostart 自动开始一个域

blkdeviotune 设定或者查询块设备 I/O 调节参数。

blkiotune 获取或者数值 blkio 参数

blockcommit 启动块提交操作。

blockcopy 启动块复制操作。

blockjob 管理活跃块操作

blockpull 使用其后端映像填充磁盘。

blockresize 创新定义域块设备大小

change-media 更改 CD 介质或者软盘驱动器

console 连接到客户会话

cpu-stats 显示域 cpu 统计数据

create 从一个 XML 文件创建一个域

define 从一个 XML 文件定义(但不开始)一个域

desc 显示或者设定域描述或者标题

destroy 销毁(停止)域

detach-device 从一个 XML 文件分离设备

detach-device-alias detach device from an alias

detach-disk 分离磁盘设备

detach-interface 分离网络界面

domdisplay 域显示连接 URI

domfsfreeze Freeze domain's mounted filesystems.

domfsthaw Thaw domain's mounted filesystems.

domfsinfo Get information of domain's mounted filesystems.

domfstrim 在域挂载的文件系统中调用 fstrim。

domhostname 输出域主机名

domid 把一个域名或 UUID 转换为域 id

domif-setlink 设定虚拟接口的链接状态

domiftune 获取/设定虚拟接口参数

domjobabort 忽略活跃域任务

domjobinfo 域任务信息

domname 将域 id 或 UUID 转换为域名

domrename rename a domain

dompmsuspend 使用电源管理功能挂起域

dompmwakeup 从 pmsuspended 状态唤醒域

domuuid 把一个域名或 id 转换为域 UUID

domxml-from-native 将原始配置转换为域 XML

domxml-to-native 将域 XML 转换为原始配置

dump 把一个域的内核 dump 到一个文件中以方便分析

dumpxml XML 中的域信息

edit 编辑某个域的 XML 配置

event Domain Events

inject-nmi 在虚拟机中输入 NMI

iothreadinfo view domain IOThreads

iothreadpin control domain IOThread affinity

iothreadadd add an IOThread to the guest domain

iothreaddel delete an IOThread from the guest domain

send-key 向虚拟机发送序列号

send-process-signal 向进程发送信号

lxc-enter-namespace LXC 虚拟机进入名称空间

managedsave 管理域状态的保存

managedsave-remove 删除域的管理保存

managedsave-edit edit XML for a domain's managed save state file

managedsave-dumpxml Domain information of managed save state file in XML

managedsave-define redefine the XML for a domain's managed save state file

memtune 获取或者数值内存参数

perf Get or set perf event

metadata show or set domain's custom XML metadata

migrate 将域迁移到另一个主机中

migrate-setmaxdowntime 设定最大可耐受故障时间

migrate-getmaxdowntime get maximum tolerable downtime

migrate-compcache 获取/设定压缩缓存大小

migrate-setspeed 设定迁移带宽的最大值

migrate-getspeed 获取最长迁移带宽

migrate-postcopy Switch running migration from pre-copy to post-copy

numatune 获取或者数值 numa 参数

qemu-attach QEMU 附加

qemu-monitor-command QEMU 监控程序命令

qemu-monitor-event QEMU Monitor Events

qemu-agent-command QEMU 虚拟机代理命令

reboot 重新启动一个域

reset 重新设定域

restore 从一个存在一个文件中的状态恢复一个域

resume 重新恢复一个域

save 把一个域的状态保存到一个文件

save-image-define 为域的保存状态文件重新定义 XML

save-image-dumpxml 在 XML 中保存状态域信息

save-image-edit 为域保存状态文件编辑 XML

schedinfo 显示/设置日程安排变量

screenshot 提取当前域控制台快照并保存到文件中

set-lifecycle-action change lifecycle actions

set-user-password set the user password inside the domain

setmaxmem 改变最大内存限制值

setmem 改变内存的分配

setvcpus 改变虚拟 CPU 的号

shutdown 关闭一个域

start 开始一个(以前定义的)非活跃的域

suspend 挂起一个域

ttyconsole tty 控制台

undefine 取消定义一个域

update-device 从 XML 文件中关系设备

vcpucount 域 vcpu 计数

vcpuinfo 详细的域 vcpu 信息

vcpupin 控制或者查询域 vcpu 亲和性

emulatorpin 控制火车查询域模拟器亲和性

vncdisplay vnc 显示

guestvcpus query or modify state of vcpu in the guest (via agent)

setvcpu attach/detach vcpu or groups of threads

domblkthreshold set the threshold for block-threshold event for a given block device or it's backing chain element

Domain Monitoring (help keyword 'monitor')

domblkerror 在块设备中显示错误

domblkinfo 域块设备大小信息

domblklist 列出所有域块

domblkstat 获得域设备块状态

domcontrol 域控制接口状态

domif-getlink 获取虚拟接口链接状态

domifaddr Get network interfaces' addresses for a running domain

domiflist 列出所有域虚拟接口

domifstat 获得域网络接口状态

dominfo 域信息

dommemstat 获取域的内存统计

domstate 域状态

domstats get statistics about one or multiple domains

domtime domain time

list 列出域

Host and Hypervisor (help keyword 'host')

allocpages Manipulate pages pool size

capabilities 性能

cpu-baseline 计算基线 CPU

cpu-compare 使用 XML 文件中描述的 CPU 与主机 CPU 进行对比

cpu-models CPU models

domcapabilities domain capabilities

freecell NUMA可用内存

freepages NUMA free pages

hostname 打印管理程序主机名

hypervisor-cpu-baseline compute baseline CPU usable by a specific hypervisor

hypervisor-cpu-compare compare a CPU with the CPU created by a hypervisor on the host

maxvcpus 连接 vcpu 最大值

node-memory-tune 获取或者设定节点内存参数

nodecpumap 节点 cpu 映射

nodecpustats 输出节点的 cpu 状统计数据。

nodeinfo 节点信息

nodememstats 输出节点的内存状统计数据。

nodesuspend 在给定时间段挂起主机节点

sysinfo 输出 hypervisor sysinfo

uri 打印管理程序典型的URI

version 显示版本

Interface (help keyword 'interface')

iface-begin 生成当前接口设置快照,可在今后用于提交 (iface-commit) 或者恢复 (iface-rollback)

iface-bridge 生成桥接设备并为其附加一个现有网络设备

iface-commit 提交 iface-begin 后的更改并释放恢复点

iface-define define an inactive persistent physical host interface or modify an existing persistent one from an XML file

iface-destroy 删除物理主机接口(启用它请执行 "if-down")

iface-dumpxml XML 中的接口信息

iface-edit 为物理主机界面编辑 XML 配置

iface-list 物理主机接口列表

iface-mac 将接口名称转换为接口 MAC 地址

iface-name 将接口 MAC 地址转换为接口名称

iface-rollback 恢复到之前保存的使用 iface-begin 生成的更改

iface-start 启动物理主机接口(启用它请执行 "if-up")

iface-unbridge 分离其辅助设备后取消定义桥接设备

iface-undefine 取消定义物理主机接口(从配置中删除)

Network Filter (help keyword 'filter')

nwfilter-define 使用 XML 文件定义或者更新网络过滤器

nwfilter-dumpxml XML 中的网络过滤器信息

nwfilter-edit 为网络过滤器编辑 XML 配置

nwfilter-list 列出网络过滤器

nwfilter-undefine 取消定义网络过滤器

nwfilter-binding-create create a network filter binding from an XML file

nwfilter-binding-delete delete a network filter binding

nwfilter-binding-dumpxml XML 中的网络过滤器信息

nwfilter-binding-list list network filter bindings

Networking (help keyword 'network')

net-autostart 自动开始网络

net-create 从一个 XML 文件创建一个网络

net-define define an inactive persistent virtual network or modify an existing persistent one from an XML file

net-destroy 销毁(停止)网络

net-dhcp-leases print lease info for a given network

net-dumpxml XML 中的网络信息

net-edit 为网络编辑 XML 配置

net-event Network Events

net-info 网络信息

net-list 列出网络

net-name 把一个网络UUID 转换为网络名

net-start 开始一个(以前定义的)不活跃的网络

net-undefine undefine a persistent network

net-update 更新现有网络配置的部分

net-uuid 把一个网络名转换为网络UUID

Node Device (help keyword 'nodedev')

nodedev-create 根据节点中的 XML 文件定义生成设备

nodedev-destroy 销毁(停止)节点中的设备

nodedev-detach 将节点设备与其设备驱动程序分离

nodedev-dumpxml XML 中的节点设备详情

nodedev-list 这台主机中中的枚举设备

nodedev-reattach 重新将节点设备附加到他的设备驱动程序中

nodedev-reset 重置节点设备

nodedev-event Node Device Events

Secret (help keyword 'secret')

secret-define 定义或者修改 XML 中的 secret

secret-dumpxml XML 中的 secret 属性

secret-event Secret Events

secret-get-value secret 值输出

secret-list 列出 secret

secret-set-value 设定 secret 值

secret-undefine 取消定义 secret

Snapshot (help keyword 'snapshot')

snapshot-create 使用 XML 生成快照

snapshot-create-as 使用一组参数生成快照

snapshot-current 获取或者设定当前快照

snapshot-delete 删除域快照

snapshot-dumpxml 为域快照转储 XML

snapshot-edit 编辑快照 XML

snapshot-info 快照信息

snapshot-list 为域列出快照

snapshot-parent 获取快照的上级快照名称

snapshot-revert 将域转换为快照

Storage Pool (help keyword 'pool')

find-storage-pool-sources-as 找到潜在存储池源

find-storage-pool-sources 发现潜在存储池源

pool-autostart 自动启动某个池

pool-build 建立池

pool-create-as 从一组变量中创建一个池

pool-create 从一个 XML 文件中创建一个池

pool-define-as 在一组变量中定义池

pool-define define an inactive persistent storage pool or modify an existing persistent one from an XML file

pool-delete 删除池

pool-destroy 销毁(删除)池

pool-dumpxml XML 中的池信息

pool-edit 为存储池编辑 XML 配置

pool-info 存储池信息

pool-list 列出池

pool-name 将池 UUID 转换为池名称

pool-refresh 刷新池

pool-start 启动一个(以前定义的)非活跃的池

pool-undefine 取消定义一个不活跃的池

pool-uuid 把一个池名称转换为池 UUID

pool-event Storage Pool Events

Storage Volume (help keyword 'volume')

vol-clone 克隆卷。

vol-create-as 从一组变量中创建卷

vol-create 从一个 XML 文件创建一个卷

vol-create-from 生成卷,使用另一个卷作为输入。

vol-delete 删除卷

vol-download 将卷内容下载到文件中

vol-dumpxml XML 中的卷信息

vol-info 存储卷信息

vol-key 为给定密钥或者路径返回卷密钥

vol-list 列出卷

vol-name 为给定密钥或者路径返回卷名

vol-path 为给定密钥或者路径返回卷路径

vol-pool 为给定密钥或者路径返回存储池

vol-resize 创新定义卷大小

vol-upload 将文件内容上传到卷中

vol-wipe 擦除卷

Virsh itself (help keyword 'virsh')

cd 更改当前目录

echo echo 参数

exit 退出这个非交互式终端

help 打印帮助

pwd 输出当前目录

quit 退出这个非交互式终端

connect 连接(重新连接)到 hypervisor

(指定 help <group> 获取组中命令的详情)

(使用 --help <command> 来获得这个命令的详细信息)

查看 KVM 的配置文件存放目录

查看虚拟机状态

centos7.0 就是我们刚才安装的虚拟机

关闭虚拟机

开启虚拟机

强制关闭

这个时候,我们再看一下状态:

通过配置文件启动虚拟机系统

看状态

挂起虚拟机

看一下状态

配置虚拟机实例伴随宿主机自动启动

恢复虚拟机

导出虚拟机配置

把centos7.0 的配置放到centos7.1 里面

看现在的配置文件

删除虚拟机

这是的centos7.0 的配置文件已经没有了

现在没有运行的虚拟机

进入到配置文件目录

进行配置文件的重命名

重新定义

看现在的状态

修改虚拟机配置信息(用来修改系统内存大小、磁盘文件等信息)

直接通过 vim 命令修改:

或者这样也可以

相当于编辑上面的配置文件

安装一下这个东西

var/lib/libvirt/images/: 这是我们放镜像的地方

大家在做的时候看自己的情况

查看当前磁盘格式

在宿主机上查看kvm虚拟机centos7.0 的dns地址

查看虚拟机状态

看状态

克隆一个机器

再看一下状态,发现有centos7.1

开启这个图centos7.1

生成快照(理解成VMware的快照)

查看虚拟机快照的版本信息

root@localhost \~\]# virsh snapshot-current centos7.0 \ \1656584049\ \shutoff\ \1656584049\ \ \ \ \ \ \ \centos7.0\ \8f9cd4d6-a1d1-4296-bf6e-379682af6b05\ \1048576\ \1048576\ \1\ \ \/machine\ \ \ \hvm\ \ \ \ \ \ \ \Broadwell-IBRS\ \ \ \ \ \ \ \ \ \ \ \ \ \ \destroy\ \restart\ \destroy\ \ \ \ \ \ \/usr/libexec/qemu-kvm\ \ \ \ \ \ \

\ \ \ \ \ \ \
\ \ \
\ \ \ \
\ \ \ \
\ \ \ \
\ \ \
\ \ \
\ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \
\ \ \
\ \ \ \ \ \ \ \
\ \ \ \
\ \ \
\ \ \
\ \ \
\ \ \ \ \ \ 查看快照时间 ![](https://i-blog.csdnimg.cn/direct/1e65b2bf736f4495a77d8bb4728dc4c0.png) 创建新的快照 ![](https://i-blog.csdnimg.cn/direct/5455600b04384fddba9e60b593188d3e.png) 查看快照时间 \[root@localhost \~\]# virsh snapshot-list centos7.0 名称 生成时间 状态 ------------------------------------------------------------ 1656584049 2024-11-20 18:14:09 +0800 shutoff 1656584521 2024-11-20 18:22:01 +0800 shutoff 切换原先的状态 ![](https://i-blog.csdnimg.cn/direct/5288c849b8a84520a513c8928ff0e3f6.png) 看信息 ![](https://i-blog.csdnimg.cn/direct/6401ffbdd0f34f979fd827a4caa94776.png) ![](https://i-blog.csdnimg.cn/direct/d1d997ce3b0c4897b352a5b8d7edb03b.png) 好了,有关于centos7安装部署kvm 以及kvm的基本操作就到这里了,谢谢大家! 注意:本文来源于 [centos7安装部署kvm,照做就行_centos kvm-CSDN博客](https://blog.csdn.net/weixin_47556601/article/details/125529706?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522c81d1f996203681e1bdc8b76b3d7eedf%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=c81d1f996203681e1bdc8b76b3d7eedf&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-125529706-null-null.142%5Ev100%5Epc_search_result_base8&utm_term=centos7%E5%AE%89%E8%A3%85kvm&spm=1018.2226.3001.4187 "centos7安装部署kvm,照做就行_centos kvm-CSDN博客")

相关推荐
dragon_perfect44 分钟前
adoc(asciidoc)转为markdown的方法,把.adoc文件转换为markdown格式
linux·运维·deepseek本地知识库
苹果醋31 小时前
SpringCloud Alibaba场景实践(Nacos篇)
java·运维·spring boot·mysql·nginx
编码小笨猪7 小时前
浅谈Linux中一次系统调用的执行过程
linux·服务器·c++
早起鸟儿8 小时前
docker-Dockerfile 配置
java·linux·运维·docker
虚妄狼8 小时前
【Docker Desktop】Windows11安装 Docker Desktop
运维·docker·容器
Hello.Reader9 小时前
NGINX 四层上游模块`ngx_stream_upstream_module` 实战指南
运维·nginx
IT成长日记9 小时前
【Docker基础】Docker核心概念:命名空间(Namespace)与资源隔离联系
运维·docker·namespace·资源隔离·命令空间
Mikhail_G9 小时前
Python应用八股文
大数据·运维·开发语言·python·数据分析
再ZzZ11 小时前
Docker安装PaddleOCR并提供接口服务(CPU)
运维·docker·容器
love530love11 小时前
是否需要预先安装 CUDA Toolkit?——按使用场景分级推荐及进阶说明
linux·运维·前端·人工智能·windows·后端·nlp