KVM

CentOS 7

yum makecache

yum install -y kvm qemu-kvm libvirt python-virtinst

service libvirtd start

chkconfig libvirtd on

virsh iface-bridge eth0 br0

ethtool -K br0 gso off

ethtool -K br0 tso off

iptables -I INPUT -s 10.0.1.1 -p tcp -m tcp --dport 5900:5909 -j ACCEPT

# Create Linux KVM Host

virt-install --name doc --vcpus 1 --ram 1024 --cdrom /www/kvm/iso/CentOS-7-x86_64-Minimal-1810.iso --disk /www/kvm/disk/doc.img,size=10 --autostart --network bridge=br0 --noautoconsole --graphics vnc,listen=0.0.0.0,password=123456

# Create Win KVM Host

virt-install --name test --vcpus 2 --ram 4096 --cdrom /www/kvm/iso/cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408.iso --disk /www/kvm/disk/test.img,size=100 --autostart --network bridge=br0 --noautoconsole --graphics vnc,listen=0.0.0.0,password=wenbor

###################################################

# 创建虚拟硬盘

qemu-img create -f qcow2 /www/vps/centos.qcow2 20G

# 快照

virsh snapshot-create-as centos centos_1

# 迁移

qemu-img create -f qcow2 /www/vps/redis.qcow2 100G

virsh migrate --live --persistent --undefinesource --verbose kvm qemu+ssh://192.168.1.10/system

# 压缩镜像文件

qemu-img convert -c -O qcow2 /www/old.qcow2 /www/new.qcow2

# 描述

virsh desc nginx2 --config --new-desc "IP : 1.1.1.1"

# 添加硬盘

virsh attach-disk win \
--source /www/kvm/image/win-disk.img \
--target vda \
--persistent

# 硬盘扩容
qemu-img resize test.img +100G

# 修改 CPU 数量

virsh setvcpus vps 2 --maximum --config
virsh setvcpu2 vps 2 --config

# 修改虚拟机内存

virsh setmaxmem vps 2097152 --config
virsh setmem vps 2097152--config

# 管理虚拟机文件

yum install -y libguestfs-tools

# 查看虚拟机文件

virt-cat -d vps /etc/hosts
virt-ls -d vps /etc
virt-copy-out -d vps /etc/hosts .
virt-copy-in -d vps /tmp/01 /tmp/02

CentOS 8

yum install -y qemu-kvm libvirt

systemctl start libvirtd

virsh iface-bridge enp3s0f0 br0

nmcli c add type bridge con-name br0 ifname br0 autoconnect yes