lig 发表于 2017-6-24 09:02:38

qemu-kvm和openvswitch安装部署-qemu-kvm和openvswitch原型环境部署和基本测试 (1)

qemu-kvm和openvswitch安装部署
  本文包含两个部分:


[*]qemu-kvm的安装部署
[*]openvswitch的安装部署
  参考文档:
  kvm官网:http://www.linux-kvm.org/page/Documents
  qemu文档:kvm官网把qemu文档(qemu user manual)直接指向wiki了,^_^
  
http://wiki.qemu.org/Qemu-doc.html
  
***

1. qemu-kvm的安装部署

环境准备
  1). 内核需要支持KVM。KVM版本>=2.6.20。
  2007年2月,Linux 2.6.20内核开始支持KVM
  

$ uname -r  

  2). CPU需要开启虚拟化,Intel VT或者AMD-V.在BIOS里设置。
  检查CPU是否开启了虚拟化(参考/etc/sysconfig/moduleskvm.modules),执行以下命令,返回数值大于0则表示已经开启了虚拟化。
  Intel CPU:
  

$ grep -c vmx /proc/cpuinfo  

  AMD CPU:
  

$ grep -c svm /proc/cpuinfo  

加载KVM内核模块
  

# modprobe kvm  

  执行以下命令,显示kvm条目则表示kvm模块已经加载。
  

# lsmod|grep kvm  
kvm_intel             14808157
  
kvm                   4611261 kvm_intel
  

  加入开机自动加载
  

# vi /etc/sysconfig/modules/openvswitch.modules  

  

#!/bin/sh  

  
if [ $(grep -c vmx /proc/cpuinfo) -ne 0 ]; then
  modprobe -b kvm-intel >/dev/null 2>&1
  
fi
  

  
if [ $(grep -c svm /proc/cpuinfo) -ne 0 ]; then
  modprobe -b kvm-amd >/dev/null 2>&1
  
fi
  

  
modprobe -b vhost_net >/dev/null 2>&1
  

  设置modules文件为755权限。
  

chmod 755 kvm.modules  

  注: vhost_net是网络加速的一个内核模块,如果不适用vhostnet,则可以不用加载。

安装qemu-kvm工具
  通过yum安装Linux用户层(user space) KVM管理工具即可。
  

# yum install -y qemu-kvm  

  主要命令:
  

$ /usr/bin/qemu-img # 创建磁盘  

  
$ /usr/lib/libexec/qemu-kvm # 创建虚拟机
  

  注: 如果需要使用libvirtd API和virsh命令,则需要安装libvirtd。如果需要使用virt-manager从图形界面创建虚拟机,则需要安装virt-manager。本次测试由于仅使用qemu-kvm创建虚拟机,所以仅需要安装qemu-kvm工具。

2. openvswitch的安装部署
  参考! https://github.com/openvswitch/ovs/blob/branch-2.3/INSTALL。

版本
  与kvm属于Linux内核模块不同,openvswitch并不包含在Linux内核中,需要单独下载编译加载。所以,不同版本的openvswitch对于Linux内核版本有不同要求。
  最新openvswitch版本为2.5,匹配Linux 3.10以上(>=RHEL 7.0/CentOS 7.0)。
  本次选择匹配Linux 2.6.32 (>=RHEL 6.4/ CentOS 6.4)的openvswitch版本,2.3.3。
  该版本支持以下特性:
  

* Standard 802.1Q VLAN model with trunk and access ports  
* NIC bonding with or without LACP on upstream switch
  
* NetFlow, sFlow(R), and mirroring for increased visibility
  
* QoS (Quality of Service) configuration, plus policing
  
* GRE, GRE over IPSEC, VXLAN, and LISP tunneling
  
* 802.1ag connectivity fault management
  
* OpenFlow 1.0 plus numerous extensions
  
* Transactional configuration database with C and Python bindings
  
* High-performance forwarding using a Linux kernel module
  

安装方式
  两种安装方式:


[*]userspace,这个属于exprience
[*]linux kernal module,
  本次测试采用内核方式安装,即核心功能通过openvswitch内核模块实现。

环境准备
  1). 内核版本>=2.6.32。
  

$ uname -r  

  2). Python环境:python 2.4 或者以上
  

$ python --version  

  3). 编译环境
  gcc/GNU make
  4). 依赖
  ①需要安装linux kernal
  

\# yum install linux-kernal  

  ② make时报找不到某个文件,
  
/lib/modules/2.6.32-358.el6.x86_64/build/include/generated/utsrelease.h
  解决办法:在/lib/modules/2.6.32-358.el6.x86_64/build/include下新建一个generated文件夹,从linux/utsrelease.h中copy过去。
  注: github上的要求比较详细,但是如果选用和操作系统相匹配的openvswitch,那默认的yum安装的组件都会满足要求。

编译安装用户层工具和内核模块
  

$ ./configure --with-linux=/lib/modules/`uname -r`/build #配置  
$ make #编译
  
# make install #安装ovs
  
# make modules_install #安装内核模块
  

加载openvswitch模块
  

# modprobe openvswitch #加载内核模块  
# lsmod|grep openvswitch #检查是否有openvswitch
  

  加入开机自动加载
  

# vi /etc/sysconfig/modules/openvswitch.modules  

  

#!/bin/sh  

  
if [ -f /lib/modules/2.6.32-358.el6.x86_64/extra/openvswitch.ko ]; then
  /sbin/modprobe openvswitch > /dev/null 2>&1
  
fi
  

  
exit 0
  

  设置modules文件为755权限。
  

chmod 755 openvswitch.modules  

主要命令
  运行命令位于:/usr/local/bin/
  ovs-appctl / ovs-dpctl / ovs-ofctl / ovs-vsctl
页: [1]
查看完整版本: qemu-kvm和openvswitch安装部署-qemu-kvm和openvswitch原型环境部署和基本测试 (1)