CentOS 7
- 版本
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-862.3.3.el7.x86_64 #1 SMP Fri Jun 15 04:15:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- 关闭 SElinux (Security-Enhanced Linux: 对所有资源的访问控制)
vi /etc/sysconfig/selinux
SELINUX=disabled
- 系统升级:
yum update
安装软件
KVM 是最底层的 Hypervisor, 用来模拟 CPU 的运行, Linux 内核默认支持 KVM,可以通过
modprobe kvm
进行加载,通过lsmod | grep kvm
进行查看。Qemu-kvm 是一个完整的模拟器,运行在用户层,构建在 KVM 之上,调用 KVM 接口,并且提供了完整的网络和I/O支持,安装 qemu-kvm:
yum install qemu-kvm
Libvirt 是通过调用 qemu-kvm 管理虚拟机的工具,它提供了一套虚拟机操作 API,可以通过
virsh
调用,安装 libvirt:yum install libvirt
Libvirt-python 是 libvirt 为 python 提供的 API,安装 libvirt-python:
yum install libvirt-python
安装 libvirt 的客户端:
yum install libvirt-client
安装 基于 libvirt 的虚拟机创建命令行工具:
yum install virt-install
安装 基于 libvirt 的图形化虚拟机管理工具:
yum install virt-manager
安装 基于 libvirt 用于显示 guest OS 图形化 console 的工具:
yum install virt-viewer
安装 基于 libvirt 用于查看虚拟机资源使用情况的工具:
yum install virt-top
安装 基于 libvirt 的使用 python 安装虚拟机的工具:
yum install python-virtinst
安装 虚拟机磁盘管理工具:
yum install libguestfs-tools
启动 libvirtd 并设置其为开机启动
systemctl start libvirtd
systemctl enable libvirtd
[root@localhost ~]# virsh -c qemu:///system list
Id Name State
----------------------------------------------------
- 安装 openvswitch:
yum install openvswitch
KVM 网络配置 -- Bridge
前往 CentOS 网络配置文件目录:
cd /etc/sysconfig/network-scripts/
添加网桥设备脚本文件:
vi ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
也可以在该网桥上配置宿主机的静态 IP 地址:
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.2.6
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DEFROUTE=yes
ONBOOT=yes
NM_CONTROLLED=no
- 关闭网卡设备,并修改网卡设备脚本文件:
ifdown enp133s0f0
,vi ifcfg-enp133s0f0
HWADDR=00:0C:BD:00:DE:20
TYPE=Ethernet
BOOTPROTO=none
NM_CONTROLLED=no
DEVICE=enp133s0f0
ONBOOT=yes
BRIDGE=br0
- 启动网卡,启动网桥:
ifup enp133s0f0
,ifup br0
[root@localhost network-scripts]# ip add
...
4: enp133s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 00:0c:bd:00:de:20 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:bdff:fe00:de20/64 scope link
valid_lft forever preferred_lft forever
...
17: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:0c:bd:00:de:20 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:bdff:fe00:de20/64 scope link
valid_lft forever preferred_lft forever
...
如果网桥上有配置静态 IP 地址,会在 br0 上显示。
- 查看网桥:
[root@localhost network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000cbd00de20 no enp133s0f0
br1 8000.000cbd00de21 no enp133s0f1
br2 8000.000cbd00de22 no enp133s0f2
br3 8000.000cbd00de23 no enp133s0f3
KVM 网络配置 -- vSwitch
启动 openvswitch 并设置其为开机启动:
systemctl start openvswitch
,systemctl enable openvswitch
在
/etc/sysconfig/network-scripts
目录下, 配置 OVS Bridge 脚本:vi ifcfg-br20
DEVICE=br20
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
- 关闭网卡,修改网卡脚本:
ifdown enp7s0f0
,vi ifcfg-enp7s0f0
HWADDR=00:0C:BD:06:43:8A
DEVICETYPE=ovs
TYPE=OVSPort
DEVICE=enp7s0f0
NM_CONTROLLED=no
ONBOOT=yes
OVS_BRIDGE=br20
- 启动网卡,启动 OVS Bridge:
ifup enp7s0f0
,ifup br20
[root@localhost network-scripts]# ip add
...
11: enp7s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP group default qlen 1000
link/ether 00:0c:bd:06:43:8b brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:bdff:fe06:438b/64 scope link
valid_lft forever preferred_lft forever
...
14: br20: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 00:0c:bd:06:43:8a brd ff:ff:ff:ff:ff:ff
inet6 fe80::60d0:9eff:fea0:b263/64 scope link
valid_lft forever preferred_lft forever
...
- 查看 vswitch:
[root@localhost network-scripts]# ovs-vsctl show
7cb9a643-bff7-4d85-8f4d-1cb8077bb117
Bridge "br20"
Port "br20"
Interface "br20"
type: internal
Port "vnet4"
Interface "vnet4"
Port "enp7s0f0"
Interface "enp7s0f0"
Bridge "br11"
Port "ens65f1"
Interface "ens65f1"
Port "br11"
Interface "br11"
type: internal
Bridge mgmt
Port "enp1s0f0"
Interface "enp1s0f0"
Port "vnet0"
Interface "vnet0"
Port mgmt
Interface mgmt
type: internal
Bridge "br21"
Port "enp7s0f1"
Interface "enp7s0f1"
Port "vnet10"
Interface "vnet10"
Port "br21"
Interface "br21"
type: internal
Port "vnet7"
Interface "vnet7"
ovs_version: "2.0.0"
- 重启 network 失败,并提示 bridge 已存在,可以通过
ovs-vsctl del-br BRIDGE
后,重启 network 解决。
WebVirtMgr 部署见: WebVirtMgr + NGINX 环境 在 CentOS 7 上的部署