2017-10-06 72 views
0

我想使用Vagrant在我的本地計算機(Mac OS X)上設置帶有UI的Consul羣集。 到目前爲止,我只是跟着官方領事文檔的入門指導:https://www.consul.io/intro/getting-started/join.html運行Vagrant領事:端口轉發從客人到主機不能在Mac OS X上工作

爲了能夠從主機訪問UI,我只是簡單地添加這一行所提供的Vagrantfile(https://github.com/hashicorp/consul/blob/master/demo/vagrant-cluster/Vagrantfile

n1.vm.network "forwarded_port", guest: 8500, host: 8500 

要啓動領事與客戶機上的UI我ssh到機器,然後只需添加-ui標誌所提供的命令:

consul agent -server -bootstrap-expect=1 \ 
    -data-dir=/tmp/consul -node=agent-one -bind=172.20.20.10 \ 
    -enable-script-checks=true -config-dir=/etc/consul.d -ui 

領事啓動沒有問題並從客戶機我可以執行:

curl -v 'http://localhost:8500/ui/' 

並返回預期的HTML頁面。

試圖通過瀏覽器訪問http://localhost:8500/ui/或通過主機上的curl不起作用。在主機上使用捲曲結果如下:

* Trying ::1... 
* TCP_NODELAY set 
* Connection failed 
* connect to ::1 port 8500 failed: Connection refused 
* Trying 127.0.0.1... 
* TCP_NODELAY set 
* Connected to localhost (127.0.0.1) port 8500 (#0) 
> GET /ui/ HTTP/1.1 
> Host: localhost:8500 
> User-Agent: curl/7.54.0 
> Accept: */* 
> 
* Empty reply from server 
* Connection #0 to host localhost left intact 
curl: (52) Empty reply from server 

任何我缺少正確設置端口轉發? 運行vagrant up後的日誌看對我好:

n1: Forwarding ports... 
    n1: 8500 (guest) => 8500 (host) (adapter 1) 

回答

2

你有2種選擇:

  1. 使用靜態IP(無論是public networkprivate network),這樣你會綁定你領事代理的靜態IP(比如172.20.20.10),你將能夠通過http://172.20.20.10:8500/ui/從Web瀏覽器訪問

注:在這種情況下,你不需要公頃已經轉發的端口在Vagrantfile

  • consul doc on bind option
  • 應當綁定到內部羣集通信的地址。這是集羣中所有其他節點都應該可以訪問的IP地址。默認情況下,這是"0.0.0.0",這意味着領事會綁定到所有地址在本地機器上

    這樣你就可以從你的主機上的虛擬機達到領事運行

    NB:我的喜好去進行選擇#1

    +0

    謝謝,你是對的。我已經在專用網絡中指定了IP,所以不需要端口轉發。 我缺少的還是指定要綁定的客戶端IP地址。 (https://www.consul.io/docs/agent/options.html#_client)。 因此,最後使用這個命令,UI可以從主機上獲得,地址爲 'http://172.20.20.10:8500/ui /'。 因此,該命令需要如下所示: 'consul agent -server -bootstrap-expect = 1 -data-dir =/tmp/consul -node = agent-one -bind = 172.20.20.10 -client = 172.20.20.10 -enable-script-checks = true -config-dir =/etc/consul.d -ui' – user2350644

    相關問題