一、創建三個consul節點(一個server+兩個client)html
具體的過程見http://www.cnblogs.com/java-zhao/p/5375132.htmljava
1)在終端下啓動vagrantnode
vagrant up(Vagrantfile仍是創建兩個節點,以下)linux
1 # -*- mode: ruby -*- 2 # vi: set ft=ruby : 3 $script = <<SCRIPT 4 echo Installing dependencies... 5 sudo apt-get update 6 sudo apt-get install -y unzip curl 7 echo Fetching Consul... 8 cd /tmp/ 9 wget https://releases.hashicorp.com/consul/0.6.1/consul_0.6.1_linux_amd64.zip -O consul.zip 10 echo Installing Consul... 11 unzip consul.zip 12 sudo chmod +x consul 13 sudo mv consul /usr/bin/consul 14 sudo mkdir /etc/consul.d 15 sudo chmod a+w /etc/consul.d 16 SCRIPT 17 18 # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 19 VAGRANTFILE_API_VERSION = "2" 20 21 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 22 config.vm.box = "debian/wheezy64" 23 24 config.vm.provision "shell", inline: $script 25 26 config.vm.define "n110" do |n1| 27 n1.vm.hostname = "n110" 28 n1.vm.network "private_network", ip: "192.168.21.110" 29 end 30 31 config.vm.define "n111" do |n2| 32 n2.vm.hostname = "n111" 33 n2.vm.network "private_network", ip: "192.168.21.111" 34 end 35 end
2)進入n110節點並啓動爲server模式shell
2.1)進入n110節點:vagrant ssh n110bootstrap
2.2)啓動consul:瀏覽器
說明:ruby
3)進入n111節點並啓動爲client模式less
3.1)進入n111節點:vagrant ssh n111ssh
3.2)啓動consul:
3.3)加入集羣:
4)將本機節點啓動爲client模式並打開UI
4.1)啓動consul:
說明:本機啓動UI
4.2)加入集羣:
啓動完成後,最好查看一下每個節點的consul集羣成員。
二、在本機瀏覽器訪問UI
訪問遠程服務端點的UI
說明:在新版本的consul中訪問遠程服務端點的UI是有問題的,可能須要配置什麼。老版本沒問題。
解決方法:
consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -node=server-110 -bind=192.168.21.110 -dc=zjgdc1 -client 0.0.0.0 -ui
說明:-client 0 0 0 0 -ui-->使得客戶端能夠直接經過url訪問服務端的consul ui
訪問本機的UI
http://localhost:8500/ui/
打開nodes節點,以下: