文章转载自DPDK与SPDK开源社区
Vagrant基本概况
Vagrant是用于创建和提供可移植虚拟机的开源项目。使用Vagrant,您可以在极短的时间内启动多台虚拟机。它将允许您尝试同时使用几个操作系统或发行版本,而不会打断您下载ISO文件。
在SPDK中使用Vagrant
Vagrant还提供了一种快速方法,可以在不需要任何特殊硬件的情况下运行启用基本NVMe的虚拟机沙箱。 SPDK的Vagrant环境支持Ubuntu 16.04和CentOS 7.2。 此环境需要Vagrant 1.9.4或更高版本、VirtualBox 5.1或更高版本、以及匹配的VirtualBox扩展包。
虚拟机从位于/ SPDK的源构建SPDK和DPDK。
注意:
如果您处于公司防火墙之内,请在尝试启动虚拟机之前在您的环境中设置http_proxy和https_proxy。同时还要确保你已经安装了可选的vagrant模块vagrant-proxyconf:
1 2 3 |
export http_proxy=... export https_proxy=... vagrant plugin install vagrant-proxyconf |
如果您想使用kvm/libvirt,您还应该安装vagrant-libvirt。
1.Vagrant的环境配置
本文将演示如何在CentOS 7环境中配置和使用Vagrant。
步骤1
在 CentOS 7 主机系统上安装 VirtualBox 5.1 (假设主机系统未安装任何依赖项)。首先安装 VirtualBox 依赖项:
1 2 |
#yum –y install gcc dkms make qt libgomp patch #yum –y install kernel-headers kernel-devel binutils glibc-headers glibc-devel font-forge |
然后添加VirtualBox库:
1 2 |
#cd /etc/yum.repo.d/ #wget http://download/virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo |
步骤2
在CentOS 7中安装Vagrant。在这里,我们使用yum命令安装2.0.2版本。对于64位计算机,请使用以下命令:
1 |
#yum -y install https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm |
对于32位计算机,请使用以下命令:
1 |
#yum -y install https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_i686.rpm |
然后创建一个目录来安装操作系统:
1 |
#mkdir ~/vagrant && cd ~/vagrant |
安装vagrant-proxyconf,这将使您能够在虚拟机中使用与主机相同的代理:
1 |
#vagrant plugin install vagrant-proxyconf |
安装 vagrant-cachier:
1 |
#vagrant plugin install vagrant-cachier |
在虚拟机中安装操作系统, 使用以下命令自动创建Vagrantfile, 以Ubuntu为例:
1 |
#vagrant init Ubuntu/xenial64 |
由于Vagrant cloud box文件已被重定向,我们可能需要执行另一个步骤来更改Vagrantfile中的以下行。
将下面这行:
1 |
config.vm.box = "ubuntu/xenial64" |
替换为以下内容(这是为了将Vagrant引导到正确的文件夹位置):
1 2 |
config.vm.box = "http://cloud-images.ubuntu.com/releases/xenial/release-201604 20.3/ubuntu-16.04-server-cloudimg-amd64-vagrant.box" |
然后使用以下命令在虚拟机上启动和安装操作系统,这将花费几分钟的时间,但具体耗时取决于网络速度:
1 |
#vagrant up |
现在可以使用以下命令登录到虚拟机:
1 |
#vagrant ssh |
2.SPDK虚拟机配置,以及运行简单的Hello World实例
步骤1
在主机上下载SPDK并进入文件夹/spdk/scripts/vagrant,SPDK创建了现有的Vagrant文件,您可能需要更改Vagrantfile中的以下行。
将下面这行:
1 |
config.vm.box = "ubuntu/xenial64" |
替换为以下内容(这是为了将Vagrant引导到正确的文件夹位置)
1 |
config.vm.box = " https://vagrantcloud.com/puppetlabs/boxes/ubuntu-16.04-64-nocm/versions/1.0.0/providers/virtualbox.box" |
或者您可以将virtualbox.box文件直接下载到本地文件夹,并将其分配给config.vm.box,如下所示:
1 |
config.vm.box = "ubuntu-16.04-x86_64-virtualbox-nocm-1.0.0.box" |
然后运行以下命令来启动虚拟机,这将花费几分钟的时间:
1 |
#vagrant up |
然后可以使用以下命令登录到虚拟机中:
1 |
#vagrant ssh |
使用以下命令更改为root用户:
1 |
#sudo su |
步骤2
使用以下命令检查虚拟机中是否存在NVMe设备:
1 2 |
#lspci -nn | grep "Non" 00:0e.0 Non-Volatile memory controller [0108]: InnoTek Systemberatung GmbH Device [80ee:4e56] |
步骤3
在虚拟机上下载最新的DPDK和SPDK。
1 2 3 |
#git clone https://github.com/spdk/spdk.git #cd spdk/ #git submodule update --init |
步骤4
在虚拟机上安装相关依赖包。
1 |
#./scripts/pkgdep.sh |
步骤5
编译SPDK,探测uio, uio_pci_generic驱动并运行setup.sh脚本:
1 2 3 4 5 6 |
#./configure #make #modprobe uio #modprobe uio_pci_generic #./scripts/setup.sh 0000:00:0e.0 (80ee 4e56): nvme -> uio_pci_generic |
步骤6
在示例中运行“Hello World”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#./examples/nvme/hello_world/hello_world Starting SPDK v18.07-pre / DPDK 18.02.0 initialization... [ DPDK EAL parameters: hello_world -c 0x1 --file-prefix=spdk0 --base-virtaddr=0x1000000000 --proc-type=auto ] EAL: Detected 2 lcore(s) EAL: Auto-detected process type: PRIMARY EAL: Multi-process socket /var/run/.spdk0_unix EAL: Probing VFIO support... Initializing NVMe Controllers EAL: PCI device 0000:00:0e.0 on NUMA socket 0 EAL: probe driver: 80ee:4e56 spdk_nvme Attaching to 0000:00:0e.0 Attached to 0000:00:0e.0 Using controller ORCL-VBOX-NVME-VER12 (VB1234-56789 ) with 1 namespaces. Namespace ID: 1 size: 1GB Initialization complete. INFO: using host memory buffer for IO Hello world! |
3.故障分析
1.虚拟机操作系统1404无法加载uio_pci_generic模块,导致./script/setup.sh失败。
解决方案:
您可以从网站:https://vagrantcloud.com/puppetlabs/boxes/直接下载 virtualbox 文件到您的本地环境, 然后将其分配给您的 vm.config.box
2.启动的操作系统无法加载uio_pci_generic,这是运行SPDK驱动程序的基础。
解决方案:
使用以下命令将相应的内核源文件下载到虚拟机。
1 |
#wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.15.1.tar.gz |
解压并编译相应的内核:
1 2 |
#tar zxvf linux-4.15.1.tar.gz #cd linux-4.15.1 |
从现有内核复制配置文件:
1 2 3 4 |
#cp /boot/config-4.15.0-20-generic .config #make menuconfig #apt-get install libncurses5-dev #make |
检查已编译的uio_pci_generic.ko文件:
1 |
#find / -name uio_pci_generic* |
3.调整vmdk文件的大小
通常,vagrant将为vm分配10G磁盘空间,在配置期间,我们需要安装大量的库,因此空间将在短时间内耗尽。 您可以参考以下关于如何调整大小的链接:https://www.jeffgeerling.com/blogs/jeff-geerling/resizing-virtualbox-disk-image
我们列出了以下步骤作为参考:
1 2 3 4 5 6 7 8 9 10 |
a. Vagrant halt <vm id> b. cd ~/VirtualBox\ VMs/ c. cd vagrant_default_1531825753654_13384/ d. vboxmanage clonehd ubuntu-artful-17.10-cloudimg.vmdk ubuntu-artful-17.10-cloudimg-disk001.vdi --format vdi e. vboxmanage modifyhd ubuntu-artful-17.10-cloudimg-disk001.vdi --resize 40960 f. vboxmanage clonehd ubuntu-artful-17.10-cloudimg-disk001.vdi ubuntu-artful-17.10-cloudimg-disk001.vmdk --format vmdk(在这里,您将获得一个UUID,记录它并在下一步中用旧的UUID替换) g. vim vagrant_default_1531908878564_1555.vbox, 在两个地方更改相应的ubuntu-artful-17.10-cloudimg-disk001.vmdk的UUID以及vmdk文件名 h. vagrant up i. vagrant ssh j. df –h |
然后您将看到磁盘空间现在是40GB。
常见问题
对于笔记本电脑和个人电脑等服务器,只有一个单独的CPU,因此分配给虚拟机的CPU应该只有一个,这意味着虚拟机中的CPU不应超过主机上的CPU。
RDMA支持在虚拟机中运行NVMf loopback。限于篇幅,关于这部分的介绍会在之后的推送中进行。
RDMA支持在主机上同时运行两个vagrant来运行NVMf测试。限于篇幅,关于这部分的介绍会也将在之后的推送中进行。敬请期待。
参考文献
1.https://www.tecmint.com/how-to-install-vagrant-on-centos-7/
2.https://ci.spdk.io/download/events/2018-summit/day2_01_VerkampLogicalVolumes.pdf
3.http://www.spdk.io/doc/logical_volumes.html