cat /proc/cpuinfo | egrep 'vmx|svm'
vi /etc/sysconfig/selinux
将 /etc/sysconfig/selinux 中的 SELinux=enforcing 修改为 SELinux=disabled
通过 yum 安装 kvm 基础包和管理工具
kvm相关安装包及其作用:
yum -y install qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools bridge-utils virt-install
或
yum -y install qemu-kvm libvirt virt-install bridge-utils
reboot
lsmod | grep kvm
kvm_intel 183621 8
kvm 586948 1 kvm_intel
irqbypass 13503 5 kvm
systemctl start libvirtd
systemctl enable libvirtd
systemctl status libvirtd
systemctl is-enabled libvirtd
#进入宿机网络目录
cd /etc/sysconfig/network-scripts/
#复制一个网卡文件 ifcfg-em3(是我的网络,这里需要选择你的自己宿机的网卡名称)
cp ifcfg-em3 ifcfg-br0
#编辑 ifcfg-em3 网卡
vim ifcfg-em3
-------ifcfg-em3网卡配置-------
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=em3
UUID=d3e91580-2303-4071-b2de-80af25bba255
DEVICE=em3
#把 ONBOOT=on 改成 ONBOOT=yes
ONBOOT=yes
#在 ifcfg-em3 里面添加BRIDGE=br0
BRIDGE=br0
------------------------------
#编辑 ifcfg-br0 网卡
vim ifcfg-br0
------ifcfg-br0 网卡配置-------
#把 TYPE=Ethernet 改成 TYPE=Bridge
TYPE=Bridge
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
#把 NAME=em3 改成 NAME=br0
NAME=br0
UUID=d3e91580-2303-4071-b2de-80af25bba255
#把 DEVICE=em3 改成 NAME=br0
DEVICE=br0
#把 ONBOOT=on 改成 ONBOOT=yes
ONBOOT=yes
#在 ifcfg-em3 里面删除 BRIDGE=br0
#BRIDGE=br0
dhclient br0
systemctl restart network
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: em1: mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether d0:94:66:6f:b6:0c brd ff:ff:ff:ff:ff:ff
3: em2: mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether d0:94:66:6f:b6:0d brd ff:ff:ff:ff:ff:ff
4: em3: mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether d0:94:66:6f:b6:0e brd ff:ff:ff:ff:ff:ff
5: em4: mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether d0:94:66:6f:b6:0f brd ff:ff:ff:ff:ff:ff
6: virbr0: mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:49:88:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: virbr0-nic: mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:49:88:6f brd ff:ff:ff:ff:ff:ff
# 查看这个网卡是否获取IP地址
9: br0: mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d0:94:66:6f:b6:0e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.191/24 brd 192.168.1.255 scope global noprefixroute dynamic br0
valid_lft 6852sec preferred_lft 6852sec
inet6 fe80::776e:d476:4ce3:21f0/64 scope link noprefixroute
valid_lft forever preferred_lft forever
11: vnet0: mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:04:9c:58 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe04:9c58/64 scope link
valid_lft forever preferred_lft forever
13: vnet1: mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:d8:fc:e4 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fed8:fce4/64 scope link
valid_lft forever preferred_lft forever
systemctl start libvirtd
ps aux |grep libvirtd
root 18982 0.0 0.1 1605052 26812 ? Ssl Mar01 0:11 /usr/sbin/libvirtd
root 80967 0.0 0.0 112712 972 pts/0 S+ 14:50 0:00 grep --color=auto libvirtd
brctl show
# 配置桥接网卡 interfaces 必须显示宿机网卡名称,不然就是网络没配置成功
bridge name bridge id STP enabled interfaces
br0 8000.d094666fb60e no em3
# NAT模式的网卡
virbr0 8000.52540049886f yes virbr0-nic
yum install wget
cd /tmp
wget http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso
官网下载网址:https://www.centos.org/
命令说明:
#创建一个 VMS 目录
mkdir /home/vms
virt-install --virt-type=kvm --name=centos01 --vcpus=2 --memory=4096 --location=/tmp/CentOS-7-x86_64-DVD-1810.iso --disk path=/home/vms/centos01.qcow2,size=40,format=qcow2 --network bridge=br0 --graphics none --extra-args='console=ttyS0' --force
详细安装地址:http://note.youdao.com/noteshare?id=2c13806b8e82c9920fdaa632cdc953e4
virsh list --all
Id Name State
----------------------------------------------------
2 centos01 running
4 centos02 running
6 centos03 running
# centos01 是虚拟机的名称
virsh console centos01
# 查看网络
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
# 这样显示是虚拟机没有网络
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:cd:d9:d2 brd ff:ff:ff:ff:ff:ff
# 进入网络配置文件夹
cd /etc/sysconfig/network-scripts/
# 修改 ifcfg-eth0 配置
vi ifcfg-eth0
-------ifcfg-eth0网卡配置-------
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=6b810a16-9069-44f5-bee5-ee98c5c122ff
DEVICE=eth0
#把 ONBOOT=on 改成 ONBOOT=yes
ONBOOT=yes
-----------------------------
# 获取IP地址
dhclient eth0
# 查看网络
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
# 显示了IP地址,证明网络获取成功
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:cd:d9:d2 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.71/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 7192sec preferred_lft 7192sec
inet6 fe80::d526:6f0b:3ad6:7421/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# 重启网络服务
systemctl restart network
ls /etc/libvirt/qemu/
networks centos01.xml
ls /etc/libvirt/qemu/networks/
autostart default.xml
ls /etc/libvirt/qemu/networks/autostart/
default.xml
# 进入指定的虚拟机,进入的时候还需要按一下回车
virsh console 虚拟机名称
# 启动虚拟机
virsh start 虚拟机名称
# 关闭虚拟机
virsh shutdown 虚拟机名称
# 强制停止虚拟机
virsh destroy 虚拟机名称
# 彻底销毁虚拟机,会删除虚拟机配置文件,但不会删除虚拟磁盘
virsh undefine 虚拟机名称
# 设置宿主机开机时该虚拟机也开机
virsh autostart 虚拟机名称
# 解除开机启动
virsh autostart --disable 虚拟机名称
# 挂起虚拟机
virsh suspend 虚拟机名称
# 恢复挂起的虚拟机
virsh resume 虚拟机名称