1. grep -Eoc '(vmx|svm)' /proc/cpuinfo
  2. apt update
  3. apt install cpu-checker
  4. apt install uml-utilities
  5. $ kvm-ok
  6. INFO: /dev/kvm exists
  7. KVM acceleration can be used
  8. # qemu-kvm -为KVM管理程序提供硬件仿真的软件。
  9. # libvirt-daemon-system -用于将libvirt守护程序作为系统服务运行的配置文件。
  10. # libvirt-clients -用于管理虚拟化平台的软件。
  11. # bridge-utils -一组用于配置以太网桥的命令行工具。
  12. # virtinst -一组用于创建虚拟机的命令行工具。
  13. # virt-manager -易于使用的GUI界面和支持命令行工具,用于通过libvirt管理虚拟机。
  14. apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst
  15. apt install virt-manager
  16. ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu-kvm
  17. ln -s /usr/bin/qemu-system-x86_64 /usr/bin/qemu-kvm
  18. systemctl is-active libvirtd active
  19. systemctl status libvirtd.service
  20. systemctl start libvirtd.service
  21. systemctl enable libvirtd --now
  22. # 安装完成后,可能需要将用户添加到“ libvirt”和“ kvm”组中,执行后需要重启。
  23. # $USER 是一个环境变量,包含当前登录用户的名称。
  24. usermod -aG libvirt $USER
  25. usermod -aG kvm $USER
  26. $ brctl show
  27. bridge name bridge id STP enabled interfaces
  28. virbr0 8000.525400f83616 yes virbr0-nic
  29. qemu-img create -f qcow2 ceph.qcow2 20G
  30. qemu-img info ceph.qcow2
  31. # -m 4096 # 虚拟机内存4096MB
  32. # -smp 4 # 虚拟机4个vcpu
  33. # -hda # 硬盘文件
  34. # -cdrom # 光盘文件
  35. # -boot # 启动顺序,从光盘启动d,从硬盘启动c,优先硬盘再光盘启动-boot order=c
  36. # -vnc :1 # VNC
  37. # --nographic # 不使用图形界面,console
  38. qemu-kvm -m 4096 -smp 4 --enable-kvm -boot d -hda ceph.qcow2 -cdrom /root/backup/ubuntu-20.04.3-live-server-amd64.iso
  39. qemu-kvm -name ceph -m 4096 -smp 4 --enable-kvm -boot c -hda ceph.qcow2 --nographic
  40. # 安装
  41. mkdir -p /data/kvm
  42. mkdir -p /plot1/ceph
  43. # 每个虚拟机创建后,其配置信息保存在/etc/libvirt/qemu目录中,文件名与虚拟机相同,格式为XML
  44. virt-install \
  45. --connect qemu:///system \
  46. --virt-type kvm \
  47. --name ceph-vm \
  48. --os-type linux \
  49. --os-variant ubuntu20.04 \
  50. --vcpus 2 \
  51. --memory 4096 \
  52. --disk path=/data/kvm/ceph.qcow2,size=20,format=qcow2,bus=virtio \
  53. --cdrom /data/kvm/ubuntu-20.04.3-live-server-amd64.iso \
  54. --network bridge=br0,model=virtio \
  55. --graphics vnc,port=5900,listen=0.0.0.0,password=vnccephqwer1234
  56. # 查看当前网卡硬件信息
  57. # 如果出现"*-network DISABLED" 请找到"logical name"的名称,
  58. # 然后使用命令 ifconfig [logcial name] inet up 启用这个网卡
  59. lshw -class network
  60. netplan apply && dhclient -r && dhclient
  61. # 虚拟网络ssss
  62. brctl show
  63. ifconfig virbr0
  64. virsh net-list
  65. virsh net-list --all
  66. virsh net-info default
  67. virsh net-dumpxml default > virbr0-default-bak.xml
  68. virsh net-edit default
  69. # 重启libvirtd服务后会恢复
  70. virsh net-destroy default
  71. # 彻底删除,重启系统后也不会恢复
  72. virsh net-undefine default
  73. # 从一个default.xml文件定义(但不开始)一个网络, /etc/libvirt/qemu/networks/default.xml
  74. virsh net-define /var/lib/libvirt/network/default.xml
  75. virsh net-define /etc/libvirt/qemu/networks/default.xml
  76. # 开始一个(以前定义的default)不活跃的网络,执行后ifconfig可见virbr0
  77. virsh net-start default
  78. # 执行后Autostart外会变成yes
  79. virsh net-autostart default
  80. virsh dumpxml ceph-vm
  81. virsh domiflist ceph-vm
  82. virsh domifaddr ceph-vm --source arp
  83. virsh detach-interface ceph-vm --type bridge --mac 52:54:00:9a:40:df --config
  84. virsh attach-interface ceph-vm --type bridge --source br0 --model virtio --config
  85. # 查看 VNC 自动端口
  86. virsh list
  87. virsh list --all
  88. virsh dominfo ceph-vm
  89. virsh vncdisplay ceph-vm
  90. virsh edit ceph-vm
  91. virsh start ceph-vm
  92. virsh reboot ceph-vm
  93. virsh reset ceph-vm
  94. virsh shutdown ceph-vm
  95. virsh destroy ceph-vm
  96. virsh undefine ceph-vm
  97. rm -f /data/kvm/ceph.qcow2
  98. rm -f /etc/libvirt/qemu/ceph-vm.xml
  1. #从官方服务器下载,速度较慢
  2. wget https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
  3. #会路由到最近的服务器,速度很快
  4. wget -O ubuntu-20.04.3-live-server-amd64.iso https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso?_ga=2.204086288.1811206795.1644655504-1350955962.1643189248
  1. # 硬盘
  2. qemu-img create -f qcow2 -o size=90G,preallocation=falloc /plot1/ceph/osd-11.qcow2
  3. qemu-img create -f qcow2 -o size=10G,preallocation=metadata /plot1/ceph/osd-11.qcow2
  4. qemu-img create -f qcow2 /plot1/ceph/osd-11.qcow2 90G
  5. qemu-img info osd-11.qcow2
  6. virsh domblklist ceph-vm
  7. virsh attach-disk ceph-vm /plot1/ceph/osd-11.qcow2 vdb --subdriver=qcow2 --live --config
  8. virsh attach-disk ceph-vm /plot1/ceph/osd-11.qcow2 vdb # 有问题,虚拟机内不显示硬盘空间总大小
  9. virsh detach-disk ceph-vm --target vdb --live --config
  10. virsh detach-disk ceph-vm vdb --persistent
  11. # 网络
  12. netplan generate
  13. netplan apply
  14. netplan try
  15. systemctl list-units | grep network
  16. # desktop: Network Service
  17. systemctl restart network-manager.service
  18. systemctl stop NetworkManager.service
  19. systemctl disable NetworkManager.service
  20. # server: Network Service
  21. systemctl restart systemd-networkd.service
  22. ip addr
  1. # 例子 /usr/share/doc/netplan/examples/bridge.yaml
  2. # 桥接单网卡1 /etc/netplan/*.yaml
  3. network:
  4. version: 2
  5. renderer: networkd
  6. ethernets:
  7. enp6s0:
  8. dhcp4: no
  9. bridges:
  10. br0:
  11. dhcp4: yes
  12. interfaces: [enp6s0]
  13. parameters:
  14. stp: true
  15. forward-delay: 4
  16. # 桥接单网卡2
  17. network:
  18. version: 2
  19. ethernets:
  20. enp6s0:
  21. dhcp4: false
  22. bridges:
  23. br0:
  24. addresses: [192.168.0.1/24]
  25. gateway4: 192.168.0.254
  26. nameservers:
  27. addresses: [114.114.114.114,8.8.8.8]
  28. interfaces: [enp6s0]
  29. # 动态IP
  30. network:
  31. version: 2
  32. ethernets:
  33. enp1s0:
  34. dhcp4: true
  35. # 静态IP
  36. network:
  37. version: 2
  38. ethernets:
  39. enp1s0:
  40. addresses: [192.168.0.11/24]
  41. gateway4: 192.168.0.254
  42. nameservers:
  43. addresses: [114.114.114.114, 8.8.8.8, 8.8.4.4]
  1. # 开启转发支持forward
  2. # 修改为net.ipv4.ip_forward = 1
  3. vim /etc/sysctl.conf
  4. # 生效
  5. sysctrl -p

https://netplan.io/examples/
https://ubuntu.com/server/docs/virtualization-libvirt
https://wiki.libvirt.org/page/Networking
https://www.linux-kvm.org/page/UbuntuNetworking

IP地址段范围写法

kvm虚拟机的四种网络模式

[RESOLU] Erreur du paquet de traitement du paquet lvm2

Every time I install or remove a package I get LVM2 error [duplicate]

Ubuntu 16.04安装KVM

Installing KVM on CentOS or RHEL

KVM guest virtual network configuration using Open vSwitch

kvm虚拟化小结(二)nat上网

/proc/sys/net/ipv4/ 下网络参数的理解以及sysctl命令修改内核参数

sysctl命令及改变net.ipv4.ip_forward = 1方法

[linux学习]sysctl 以及 net.ipv4.ip_forward

Ubuntu20.04网络配置 & 网卡绑定

Ubuntu20.04配置KVM并设置网桥

Netplan-介绍

ubuntu18.04/20.04使用netplan设置网络

Ubuntu20.04 网络配置

virbr0-nic是如何创建的?

虚拟化之KVM(上)

ubuntu20.04使用kvm搭建虚拟机+bridge网桥,亲测有效

KVM-网络配置

kvm虚拟机添加网卡

kvm虚拟机添加网卡

ubuntu20.04 安装桥接虚拟机

ubuntu20.04 安装kvm

ubuntu20.04使用kvm搭建虚拟机+bridge网桥,亲测有效

How to Setup Bridge Networking with KVM on Ubuntu 20.04

Netplan configuration examples

macvtap实践教程

「KVM」- Networking

Creating an Ubuntu 20.04 KVM Networked Bridge Interface

Ubuntu Server 20.04 安装 KVM 虚拟机

KVM之virsh管理虚拟机硬盘配置

kvm libvirt qemu 磁盘 NIC 热添加和删除

KVM中的宿主机网络配置

ubuntu20.04使用kvm搭建虚拟机+bridge网桥,亲测有效

使用virt-install手动创建qcow2镜像并安装ISO

Linux系统关闭virbr0

Guest 安装

kvm在线添加硬件

linux kvm 的虚拟机处于暂停状态怎么开机 和 KVM-Virsh指令

烂泥: KVM虚拟机Linux系统增加硬盘

virsh命令删除与添加虚拟磁盘

kvm虚拟化小结(十四)virbr0网段修改

Ubuntu 20.04的静态网络配置

【一笔带过】关于Ubuntu20.04的kvm网桥IP配置问题

自建远程桌面过程 vnc + frp

centos7上使用virt-install命令创建kvm虚拟机

虚拟化技术之kvm虚拟机创建工具virt-install

virt-install命令—-详解

kvm虚拟机扩展磁盘容量