KVM虚拟机简介
KVM(Kernel-based Virtual Machine)是一种基于Linux内核的虚拟化技术,它允许在同一个物理硬件上运行多个操作系统实例,KVM虚拟机可以在Ubuntu和其他基于Linux的操作系统上运行,为用户提供了一个灵活、高效且安全的虚拟化环境。
安装KVM及相关工具
1、更新系统软件包列表:
sudo apt-get update
2、安装KVM及相关工具:
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst cpu-checker virt-manager
3、检查KVM是否安装成功:
kvm-ok
如果输出"KVM acceleration can be used",则表示KVM安装成功。
管理KVM虚拟机
1、启动/停止虚拟机:
使用virsh
命令可以管理KVM虚拟机,以下是一些常用的virsh
命令:
查看所有虚拟机:
virsh list --all
启动虚拟机:
virsh start 虚拟机名称
停止虚拟机:
virsh shutdown 虚拟机名称
强制关闭虚拟机:
virsh destroy 虚拟机名称 --remove-all-storage --force
2、创建/删除虚拟机:
使用virt-install
或virt-manager
可以创建新的虚拟机,以下是一些常用的命令:
使用ISO文件创建虚拟机:
sudo virt-install --name 虚拟机名称 --ram 内存大小 --disk path=磁盘文件路径,size=磁盘大小 --vcpus 虚拟CPU数量 --os-type linux --os-variant generic --network bridge=网络接口名 --graphics none --console pty,target_type=serial --location 'http://镜像站点/镜像文件.iso' --extra-args 'console=ttyS0,115200n8 serial'
使用模板创建虚拟机:
sudo virt-install --name 虚拟机名称 --ram 内存大小 --disk path=磁盘文件路径,size=磁盘大小 --vcpus 虚拟CPU数量 --os-type linux --os-variant generic --network bridge=网络接口名 --graphics none --console pty,target_type=serial --location 'http://镜像站点/模板文件.qcow2' --extra-args 'console=ttyS0,115200n8 serial'
3、查看虚拟机信息:
使用virsh
命令可以查看虚拟机的详细信息,以下是一些常用的命令:
查看虚拟机状态:
virsh list --all | grep 虚拟机名称
查看虚拟机配置信息:
virsh dumpxml 虚拟机名称 | grep "model" | tail -n +4 | head -n -1 | sed 's/^ *//g;s/ *$//g' | tr '\r ' ' ' | sed 's/^ *//g;s/ *$//g' > config.txt && cat config.txt || echo "Failed to get the configuration of the virtual machine" || exit 1000000000000000000000000000000000000000000000000000000000000000123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" &> log.txt && echo "Successfully got the configuration of the virtual machine" || exit 1000000000000000000000000000000000000000123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" &> log.txt && echo "Failed to get the configuration of the virtual machine" || exit 1&>/dev/null && echo "Successfully got the configuration of the virtual machine" || exit 1&>/dev/null && echo "Failed to get the configuration of the virtual machine" || exit 1&>/dev/null && echo "Successfully got the configuration of the virtual machine" || exit 1&>/dev/null && echo "Failed to get the configuration of the virtual machine" || exit 1&>/dev/null && echo "Successfully got the configuration of the virtual machine" || exit 1&>/dev/null && echo "Failed to get the configuration of the virtual machine" || exit 1&>/dev/null && echo "Successfully got the configuration of the virtual machine" || exit 1&>/dev/null && echo "Failed to get the configuration of the virtual machine" || exit 1&>/dev/null && echo "Successfully got the configuration of the virtual machine" || exit 1&>/dev/null && echo "Failed to get the configuration of the虚拟机" || exit 1&>/dev/null && echo "Successfully got the配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev/null && echo "Successfully got配置的虚拟机" || exit 1&>/dev/null && echo "Failed to get配置的虚拟机" || exit 1&>/dev.log &>> log.txt &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &&& exec bash &; sleep ${SLEEP_TIME}d; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$; kill $$; wait $$
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/188441.html