centos KVM

  1. 安装对应软件包

root@etxtest2 \~\]# yum -y install qemu-kvm \[root@etxtest2 \~\]# yum -y install libvirt-daemon \[root@etxtest2 \~\]# yum -y install libvirt-client \[root@etxtest2 \~\]# yum -y install libvirt-daemon-driver-qemu.x86_64 \[root@etxtest2 \~\]# yum -y install virt-manager

2.安装后可以通过virt-manager来启动图

  • 新建一台虚拟机,安装OS即可,此步骤忽略
  • virsh命令,进入交互模式

root@etxtest2 \~\]# virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # > 纯命令模式: > > 常用命令: > > virsh list #正在运行的虚拟机 > > virsh list --all > > virsh dominfo xxx #查看虚拟机信息 > > virsh autostart xxx > > virsh autostart --disable xxx > > virsh shutdown xxx > > virsh destroy xxx #强制关闭 > > virsh reboot xxx > > virsh start xxx > > 虚拟机的配置文件及磁盘文件 > > ![](https://i-blog.csdnimg.cn/direct/80a9dbf1b13044ab8781ece0fd379e45.png) > > 使用virsh查看虚拟机的xml描述信息 > > virsh dumpxml xxx > 3.新建一台虚拟机:需要准备两个文件,一个xml文件,一个磁盘文件 > root@build:/global/softwaredata/kvm/ubuntu# cp 2504-clone.qcow2 wenwutest.qcow2 > > root@build:/etc/libvirt/qemu# cp ubuntu25.04-clone.xml wenwutest.xml xml文件里面有**四个**地方需要修改 其中uuid可以通过三中方法来实现 网卡可以通过1和3来实现 1.直接修改里面的值 2.uuidgen命令来生成一个uuid 3.直接删除这行,系统启动的时候会自动生成uuid > \wenwutest\ > > \349bfeae-bb1f-4105-ba11-f508bd923222\ > > \ > > \ 把新建的虚拟机导入: root@build:/etc/libvirt/qemu# virsh define /etc/libvirt/qemu/wenwutest.xml #导入 root@build:\~# virsh list --all Id Name State -------------------------------------------------- 1 zhangchengyue-virtual-usb-clone running 2 linan running 3 zhangyongliang running 9 fanwenyang running - fanwenyang-virtual-usb shut off - flower shut off - ubuntu25.04-clone shut off **- wenwutest shut off** - wll shut off root@build:\~# virsh start wenwutest #启动虚拟机 取消导入:仅仅删除xml文件 root@build:/etc/libvirt/qemu# virsh undefine /etc/libvirt/qemu/wenwutest.xml 但是磁盘镜像没有删除 4.COW写时复制 ![](https://i-blog.csdnimg.cn/direct/85b7b98978f344bfa5be581398bb632e.png) ![](https://i-blog.csdnimg.cn/direct/f3f4cc0219e14cbea23ec33834294061.png) > root@build:/global/softwaredata/kvm/ubuntu# qemu-img create -f qcow2 -b /global/softwaredata/kvm/ubuntu/2504-clone.qcow2 /global/softwaredata/kvm/ubuntu/test01.qcow2 -F qcow2 100G > > root@build:/global/softwaredata/kvm/ubuntu# qemu-img info test01.qcow2 #可以看到实际占用大小不到1M > root@build:/etc/libvirt/qemu# virsh edit ubuntu25.04-clone #修改四个地方 > > root@build:\~# virsh start test01 > > Domain 'test01' started ![](https://i-blog.csdnimg.cn/direct/440e5bd13487451bad314764512fdc14.png) 删除: > root@build:/global/softwaredata/kvm/ubuntu# virsh shutdown test01 > > Domain 'test01' is being shutdown > > root@build:/global/softwaredata/kvm/ubuntu# virsh undefine test01 > > Domain 'test01' has been undefined > > rm -rf /global/softwaredata/kvm/ubuntu/test01.qcow2 5.虚拟机关机的时候,离线访问里面的资源 guestmount ![](https://i-blog.csdnimg.cn/direct/8302572ec38e4c9c973f619254792042.png) ![](https://i-blog.csdnimg.cn/direct/b97ee0adafd84f56a2d21ca50b3e103d.png)

相关推荐
橘子真甜~43 分钟前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
拾贰_C2 小时前
【Linux | Windows | Terminal Command】 Linux---grep | Windows--- findstr
linux·运维·服务器
阿华hhh3 小时前
Linux系统编程(标准io)
linux·开发语言·c++
虹科网络安全3 小时前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石3 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
alengan3 小时前
linux上面写python3日志服务器
linux·运维·服务器
yBmZlQzJ4 小时前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH30734 小时前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器
Rose sait4 小时前
【环境配置】Linux配置虚拟环境pytorch
linux·人工智能·python
小卒过河01044 小时前
使用apache nifi 从数据库文件表路径拉取远程文件至远程服务器目的地址
运维·服务器·数据库