1.环境准备
查看系统版本内核及IP
[root@linux-node4 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@linux-node4 ~]# uname -r
3.10.0-327.18.2.el7.x86_64
[root@linux-node4 ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2{print $3}'
192.168.56.14
[root@linux-node4 ~]# hostname
linux-node4.example.com
#关闭iptables和selinux
VMware Station打开虚拟化支持
2.创建虚拟机
2.1 安装KVM支持组件
[root@linux-node4 ~]# grep -E '(vmx|svm)' /proc/cpuinfo #检查机器是否支持KVM
flags : vmx fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge...
[root@linux-node4 ~]# yum install qemu-kvm qemu-kvm-tools libvirt virt-install -y #安装KVM支持组件,组件上篇已经介绍过
[root@linux-node4 ~]# systemctl start libvirtd #启动kvm管理工具
[root@linux-node4 ~]# systemctl enable libvirtd #设为开机自动启动
[root@linux-node4 ~]# ifconfig #libvirt启动后会自动创建一个桥接网卡,默认地址为192.168.122.1
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:28:1d:d4 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@linux-node4 ~]# ps aux |grep dnsmasq #默认还会启动dnsmasq,给虚拟机提供dns和dhcp服务
nobody 2259 0.0 0.0 15552 888 ? S 14:59 0:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 2260 0.0 0.0 15524 180 ? S 14:59 0:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
[root@linux-node4 ~]# iptables -t nat -vnL #安装libvirt时会创建一个virbr0虚拟网卡,默认通过nat来让虚拟机通信
Chain POSTROUTING (policy ACCEPT 219 packets, 16553 bytes)
pkts bytes target prot opt in out source destination
0 0 RETURN all -- * * 192.168.122.0/24 224.0.0.0/24
0 0 RETURN all -- * * 192.168.122.0/24 255.255.255.255
26 1560 MASQUERADE tcp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
29 1908 MASQUERADE udp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
2 168 MASQUERADE all -- * * 192.168.122.0/24 !192.168.122.0/24
[root@linux-node4 ~]# lsmod |grep kvm
kvm_intel 162153 3
kvm 525409 1 kvm_intel
2.2 创建虚拟机磁盘
2.3 创建虚拟机
3.安装配置虚拟机
3.1 启动虚拟机时,赶紧使用vnc客户端连接,地址为192.168.56.14:5900
3.2 即可看到虚拟机启动界面,修改网卡参数,安装系统
3.3 进入系统后,修改网络配置,然后重启网卡
◎注意事项