部署kvm
部署kvm
环境准备
grep -E "vmx|svm" /proc/cpuinfo #cpu是否支持虚拟化 (BIOS注意开启对应功能)
lsmod | grep kvm #检查kvm模块是否加载
sed -r -i 's/^\s*SELINUX=.*/SELINUX=disabled/' /etc/selinux/config #关闭selinux
最小化安装
yum install -y libvirt virt-install qemu-kvm bridge-utils
启动服务
systemctl enable libvirtd.service #虚拟化服务
systemctl start libvirtd.service
创建iso目录
mkdir /iso
将CentOS-7-x86_64-Minimal-2207-02.iso上传到/iso目录下
通过命令virt-install 新建虚拟机:
virt-install --os-variant centos7.0 \
--name server01 \
--vcpus 1,maxvcpus=2 \
--memory 512,maxmemory=1024 \
--disk device=disk,bus=scsi,path=/var/lib/libvirt/images/server01.disk01,format=qcow2,size=5,boot_order=1 \
--network network=default,model=virtio,boot_order=2 \
--location /iso/CentOS-7-x86_64-Minimal-2207-02.iso \
--extra-args "console=ttyS0" \
--nographics \
--accelerate \
--autostart &
列出所有虚拟机
virsh list --all
使用console连接
virsh console server01
如果要使用可视化界面安装需要linux安装可视化界面,并且按照virt-manage
yum groups install -y "Server with GUI" "GNOME Desktop"
yum groups install -y "Virtualization Host" "network-file-system-client" "remote-system-management" "virtualization-platform"
yum install -y virt-manager acpid virt-install virt-viewer openssh-askpass libguestfs-tools
启动图形化
systemctl restart display-manager
virt-manager