centos7 安装kvm
在本地服务器主机安装kvm环境,然后安装多个系统,供内网用户使用
环境准备
系统centos7.9 主机24C128G 磁盘6T
1 安装准备
1.1 查看CPU是否支持虚拟化
grep -E 'svm|vmx' /proc/cpuinfo
1.2关闭SElinux
vim /etc/selinux/config
SELINUX=disabled
2 安装
安装kvm相关软件
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
#安装python-urllib3依赖时可能会报错:
unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename
解决方法:
cd /usr/lib/python2.7/site-packages/urllib3/packages
然后删除所有ssl开头的文件
3 启动服务
systemctl enable libvirtd && systemctl start libvirtd
lsmod |grep kvm
#查看kvm,kvm_intel模块是否加载
4 配置网络
桥接主机网络,便于后续给虚拟机分配独立的ip
4.1 修改主网卡/etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
4.2 新建网桥/etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
DEVICE=br0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.2.106
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=114.114.114.114
4.3 启用网络转发
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p /etc/sysctl.conf
4.4 重启网络或主机
#reboot
systemctl restart NetworkManager
systemctl restart network
4.5 关闭NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager
4.6 查看网络
ip addr 输出下代表正常
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
link/ether 00:0c:29:a7:8f:9e brd ff:ff:ff:ff:ff:ff
10: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:29:a7:8f:9e brd ff:ff:ff:ff:ff:ff
inet 192.168.2.106/24 brd 192.168.2.255 scope global noprefixroute br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea7:8f9e/64 scope link
valid_lft forever preferred_lft forever
5 查看是否安装正常
systemctl status libvirtd
virsh list
安装虚拟机见后续文章