虚拟化技术汇总

Tags: 系统设计 

目录

摘要

经常需要在一台工作的电脑上,使用虚拟技术,模拟部署系统,这里记录了一些可用的工具,已经遇到问题的解决。

kvm

kvm

libvirt

http://libvirt.org/

http://libvirt.org/format.html

网络接入

可以通过配置<devices>的子元素<interface>,将虚拟机以不同的方式接入不同的网络:

<devices>
    <interface>
    ...
    </interface>
</devices>

<interface>代表网卡设备,可以通过配置它的<address>子元素,将其绑定到指定pci插槽。

Virtual network (虚拟网络)

Depending on the virtual network’s “forward mode” configuration,

the network may be totally isolated (no <forward> element given),

NAT’ing to an explicit network device or to the default route (<forward mode='nat'>),

routed with no NAT (<forward mode='route'/>),

or connected directly to one of the host’s network interfaces (via macvtap) or bridge devices ((<forward mode='bridge|private|vepa|passthrough'/> Since 0.9.4)

<devices>

    <interface type='network'>
        <source network='default'/>
    </interface>

    <interface type='network'>
        <source network='default' portgroup='engineering'/>
        <target dev='vnet7'/>
        <mac address="00:11:22:33:44:55"/>
        <virtualport>
            <parameters instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/>
        </virtualport>
    </interface>

</devices>

Bridge to LAN (桥接模式)

<devices>

    <!-- 创建名为vnetN的tun设备,将其接入br0 -->
    <interface type='bridge'>
        <source bridge='br0'/>
    </interface>

    <!-- 创建名为vnet7的tun设备,将其接入br1 -->
    <interface type='bridge'>
        <source bridge='br1'/>
        <target dev='vnet7'/>
        <mac address="00:11:22:33:44:55"/>
    </interface>

    <!-- 创建名为vnet7的tun设备,将其接入br1 -->
    <interface type='bridge'>
        <source bridge='ovsbr'/>
        <virtualport type='openvswitch'>
            <parameters profileid='menial' interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/>
        </virtualport>
    </interface>

</devices>

Userspace SLIRP stack (NAT模式)

The virtual network has DHCP & DNS services and will give the guest VM addresses starting from 10.0.2.15.

The default router will be 10.0.2.2 and the DNS server will be 10.0.2.3.

This networking is the only option for unprivileged users who need their VMs to have outgoing access.

<devices>
<interface type='user'/>

<interface type='user'>
    <mac address="00:11:22:33:44:55"/>
</interface>

</devices>

Generic ethernet connection

Provides a means for the administrator to execute an arbitrary script to connect the guest’s network to the LAN.

<devices>

<!-- 默认使用/etc/qemu-ifup脚本设置 -->
<interface type='ethernet'/>

<!-- 默认使用/etc/qemu-ifup-mynet脚本设置 -->
<interface type='ethernet'>
    <target dev='vnet7'/>
    <script path='/etc/qemu-ifup-mynet'/>
</interface>

</devices>

Direct attachment to physical interface

Provides direct attachment of the virtual machine’s NIC to the given physical interface of the host.

This setup requires the Linux macvtap driver to be available. (Since Linux 2.6.34.)

One of the modes ‘vepa’ (‘Virtual Ethernet Port Aggregator’), ‘bridge’ or ‘private’ can be chosen for the operation mode of the macvtap device.

vepa:

All VMs' packets are sent to the external bridge. Packets whose destination is a VM on the same host 
as where the packet originates from are sent back to the host by the VEPA capable bridge 
(today's bridges are typically not VEPA capable).

bridge:

Packets whose destination is on the same host as where they originate from are directly delivered to
the target macvtap device. Both origin and destination devices need to be in bridge mode for direct delivery.
If either one of them is in vepa mode, a VEPA capable bridge is required.

private:

All packets are sent to the external bridge and will only be delivered to a target VM on the same host 
if they are sent through an external router or gateway and that device sends them back to the host. 
This procedure is followed if either the source or destination device is in private mode.

passthrough:

This feature attaches a virtual function of a SRIOV capable NIC directly to a VM without losing the migration capability.
All packets are sent to the VF/IF of the configured network device.
Depending on the capabilities of the device additional prerequisites or limitations may apply; 
for example, on Linux this requires kernel 2.6.38 or newer.

<devices>
    <interface type='direct' trustGuestRxFilters='no'>
        <source dev='eth0' mode='vepa'/>
    </interface>
</devices>

PCI Passthrough

A PCI network device (specified by the element) is directly assigned to the guest using generic device passthrough.

Multicast tunnel

A multicast group is setup to represent a virtual network.

Any VMs whose network devices are in the same multicast group can talk to each other even across hosts.

This mode is also available to unprivileged users. There is no default DNS or DHCP support and no outgoing network access.

TCP tunnel

A TCP client/server architecture provides a virtual network. One VM provides the server end of the network, all other VMS are configured as clients.

All network traffic is routed between the VMs via the server.

There is no default DNS or DHCP support and no outgoing network access.

To provide outgoing network access, one of the VMs should have a 2nd NIC which is connected to one of the first 4 network types and do the appropriate routing

UDP unicast tunnel

A UDP unicast architecture provides a virtual network which enables connections between QEMU instances using QEMU’s UDP infrastructure.

Vagrant

Mac上安装

使用brew安装vargrant和virtualbox

brew cask install virtualbox
brew cask install vagrant

如果安装virtualbox的时候遇到错误:

error: Failure while executing; `/usr/bin/sudo -E -- env LOGNAME=lijiao USER=lijiao USERNAME=lijiao /usr/sbin/installer -pkg /usr/local/Caskroom/virtualbox/5.2.18,124319/VirtualBox.pkg -target /` exited with 1. Here's the output:
installer: Package name is Oracle VM VirtualBox
installer: Installing at base path /
installer: The install failed (安装器遇到了一个错误,导致安装失败。请联系软件制造商以获得帮助。)
...

需要到Mac的Security&Privacy的“Allow apps downloaded from”中设置允许来自Oracle Aemerica. Inc的软件。设置之后,重启电脑,重新安装。

下载安装box

box就是virtualbox的虚拟机镜像,Vargrant还支持aws, 以后用到再来补充。

查找box: https://vagrantcloud.com/boxes/search

安装box:

vagrant box add ubuntu/trusty64

境外的资源获取很慢,可以到下面到镜像站下载box文件:

http://mirrors.opencas.cn/ubuntu-vagrant/vagrant/

vargrant box add [box文件到url地址,或者本地路径]

查看:

vargrant box list

启动

建立一个新目录,作为vargrant虚拟机的工作目录:

mkdir VargrantTest
cd VargrantTest

注意下面的vargrant命令必须在工作目录下执行。

初始化:

vargrant init

修改初始化后得到的Vargrantfile文件:

config.vm.box = "base"    //默认是base,修改为要是用的box 

启动:

vagrant up

SSH登录进入系统:

vagrant ssh

查看状态:

vagrant status

其他操作:

vagrant -h

Virtualbox

设置Serial Number等DMI信息

VirtualBox的虚拟机默认没有Serial Number:

[vagrant@localhost ~]$ sudo dmidecode |grep Serial
Serial Number: 0
Serial Number: 0
Serial Number: Not Specified

设置方法(官方设置手册:

VBoxManage setextradata VM_NAME VBoxInternal/Devices/pcbios/0/Config/DmiSystemSerial "ABC12345"

In case your VM is configured to use EFI firmware you need to replace pcbios by efi in the keys.

在设置前,可以用VBoxManage list vms 查看虚拟机是否存在:

$ VBoxManage list vms
"OpenStack_default_1450335064104_94502" {d576c27d-f9b3-4f19-b2e8-49775b75f2b0}
"Ubuntu_default_1451556534267_81756" {f1d56285-4ec8-431f-9c41-acc5c9edba23}
"ONOS_default_1451891349199_4105" {358501fa-5029-4faf-ba5a-215eca35abe8}

参考

  1. https://docs.vagrantup.com/

系统设计

  1. Netflix 的异地多活设计: Active-Active for Multi-Regional Resiliency
  2. Facebook 的缓存系统实践经验《Scaling Memcache at Facebook》
  3. 多机数据系统的正确性与一致性
  4. 《大型网站技术架构: 核心原理与案例分析》阅读摘录
  5. 《分布式金融架构课》阅读笔记2: 线性一致的分布式数据系统的实现过程
  6. 《分布式金融架构课》阅读笔记1: 单机&多机并发/多副本读写正确性和一致性
  7. 《消息队列高手课》阅读笔记: Rabbit/Rocket/Kafka/模型/消息事务/保序等
  8. 《消息队列高手课》阅读笔记: Rabbit/Rocket/Kafka/模型/消息事务/保序等
  9. 《Redis核心技术与实践》阅读笔记: 数据类型/存储开销/Rehash/案例等
  10. 《Redis核心技术与实践》阅读笔记: 数据类型/存储开销/Rehash/案例等
  11. 《高并发系统设计40问》阅读笔记: 数据库/缓存/消息队列/分布式服务
  12. 《高并发系统设计40问》阅读笔记: 数据库/缓存/消息队列/分布式服务
  13. 《MySQL实战45讲》阅读笔记: 索引类型/数据可靠性/事务/间隙锁/临时表等
  14. 系统性能分析方法论: 统计图谱工具
  15. 张磊《深入剖析Kubernetes》专栏的阅读笔记
  16. 代理服务软件haproxy、nginx、envoy对比,以及开源的API网关项目对比
  17. 蓝绿部署、金丝雀发布(灰度发布)、A/B测试的准确定义
  18. 阿里巴巴的应用限流和服务降级是怎样实现的?|如何打造平台稳定能力
  19. 陈皓《左耳听风》专栏的阅读笔记(持续更新)
  20. 好雨云帮,一款不错的国产开源PaaS
  21. 怎样为软件的不同版本命名?
  22. 怎样选择开源项目的license?
  23. Glusterfs的架构
  24. 怎样设计一个企业级的PaaS平台?
  25. 几种常见的LDAP系统
  26. DNS SRV介绍(一种用DNS做服务发现的方法)
  27. DNS,DNS-Domain Name System
  28. 思科的网络设备
  29. 虚拟化技术汇总
  30. 认证与授权系统的汇总
  31. 高可用实现方法汇总
  32. 编译器汇总
  33. Linux系统的优化方法
  34. CentOS7的一些变化
  35. 分布式系统的一些知识
  36. 计算机编程语言的特性汇总
  37. 网络通信的一些基础知识
  38. PCIE总线的一些知识
  39. 操作系统的API
  40. 网卡的一些知识
  41. Linux系统的构建过程
  42. 数据结构与算法
  43. CPU的相关知识

推荐阅读

Copyright @2011-2019 All rights reserved. 转载请添加原文连接,合作请加微信lijiaocn或者发送邮件: [email protected],备注网站合作

友情链接:  系统软件  程序语言  运营经验  水库文集  网络课程  微信网文  发现知识星球