ruby 测试:在Vagrant机器中安装Consul

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 测试:在Vagrant机器中安装Consul相关的知识,希望对你有一定的参考价值。

**forked from https://github.com/hashicorp/consul/tree/master/demo/vagrant-cluster**

# Vagrant Consul Demo

This demo provides a very simple Vagrantfile that creates 3 nodes,
one at "172.20.20.10", "172.20.20.11" and "172.20.20.12". Both are running
a standard Ubuntu distribution and the script will install Consul and Web UI in all of them.

To get started, you can start the cluster by just doing:

    $ vagrant up

Once it is finished, you should be able to see the following:

    $ vagrant status
    Current machine states:
    n1                        running (virtualbox)
    n2                        running (virtualbox)
    n3                        running (virtualbox)

At this point the two nodes are running and you can SSH in to play with them:

    $ vagrant ssh n1
    ...
    $ vagrant ssh n2
    ...
    $ vagrant ssh n3
    ...

To learn more about starting Consul, joining nodes and interacting with the agent,
checkout the [getting started guide](http://www.consul.io/intro/getting-started/install.html).

## To destroy Vagrant machines

    $ vagrant destroy -f
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT

echo Updating linux
sudo apt-get update && sudo apt-get -y upgrade

echo Installing dependencies...
sudo apt-get install -y unzip curl
sudo apt-get -y autoremove

echo Fetching Consul...
cd /tmp/
wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip -O consul.zip

echo Installing Consul...
unzip consul.zip
sudo chmod +x consul
sudo mv consul /usr/bin/consul

echo Setup config folder...
sudo mkdir /etc/consul.d
sudo chmod a+w /etc/consul.d

echo Installing Consul Web UI
cd /tmp/
wget https://dl.bintray.com/mitchellh/consul/0.5.2_web_ui.zip -O web_ui.zip
unzip web_ui.zip
sudo mv dist /opt/

SCRIPT

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.boot_timeout = 60

  config.vm.provision "shell", inline: $script

  config.vm.define "n1" do |n1|
      n1.vm.hostname = "n1"
      n1.vm.network "private_network", ip: "172.20.20.10", virtualbox__intnet: true, auto_config: true
  end

  config.vm.define "n2" do |n2|
      n2.vm.hostname = "n2"
      n2.vm.network "private_network", ip: "172.20.20.11", virtualbox__intnet: true, auto_config: true
  end

  config.vm.define "n3" do |n3|
      n3.vm.hostname = "n3"
      n3.vm.network "private_network", ip: "172.20.20.12", virtualbox__intnet: true, auto_config: true
  end
end

以上是关于ruby 测试:在Vagrant机器中安装Consul的主要内容,如果未能解决你的问题,请参考以下文章

在 Vagrant 中安装 Jenkins 后,无法从浏览器连接

在 ubuntu vagrant box 中安装 gd 后出现“Composer Update”错误

使用 vagrant 在桌面环境下运行虚拟机

如何在Laravel项目中安装PHPunit

Vagrant 中配置局域网端口

无法在Win系统上的Ubuntu虚拟机中安装Scrapy(Shell)