vagrant

使用libvirt配置多节点的Vagrant集群

2017-02-27  本文已影响817人  大山鼠

如今很多实验室都装备有大内存,高主频,多核心的高性能服务器,所以很多虚拟机的实验其实是可以在实验室完成的,而且相对于在公有云,其测试结果更准确。目前,我认为最好的方式就是在实验室搭建Vagrant+libvirt+KVM的虚拟机集群。本文讲介绍如何在CentOS/Fedora/Redhat上搭建Vagrant+libvirt的虚拟机集群。

特点

步骤

使用传统网络名称

节点之间SSH互联

安装和配置libvirt

注意,hostname的名字必须准确

安装和配置Vagrant

rpm -ivh https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.rpm
dnf -y install qemu libvirt libvirt-devel ruby-devel gcc
vagrant plugin install vagrant-libvirt

编写Vagrantfile

其中,master为远程主机,slave为本地主机,远程主机在libvirt.host中设置主机名称

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  config.vm.define "master" do |master|
    master.vm.box = "centos/7"
    master.vm.provider :libvirt do |libvirt|
        libvirt.host = "e2104"
        libvirt.driver = "kvm"
        libvirt.username = "root"
        libvirt.password = "111111"
        libvirt.connect_via_ssh = true
    end
    master.vm.network :public_network, :dev => "eth0", :mode => 'bridge', :ip => "10.0.2.111"
  end

  config.vm.define "slave" do |master|
    master.vm.box = "centos/7"
    master.vm.network :public_network, :dev => "eth0", :mode => 'bridge', :ip => "10.0.2.110"
  end
end

启动虚拟机

vagrant up master
vagrant up slave

注意事项

yum remove libvirt libvirt-client
reboot
yum install libvirt libvirt-devel
country = AU
state = Queensland
locality = Brisbane
organization = libvirt.org
cn = e2105  #(必须为主机名)
tls_www_client
encryption_key
signing_key
上一篇 下一篇

猜你喜欢

热点阅读