節點

2017-03-02 29 views
0

我嘗試在一個maschine在兩個節點上運行我的應用程序的集羣上運行鳳凰城項目: https://dockyard.com/blog/2016/01/28/running-elixir-and-phoenix-projects-on-a-cluster-of-nodes節點

我創建配置文件:

[{kernel, 
    [ 
    {sync_nodes_optional, ['[email protected]', '[email protected]']}, 
    {sync_nodes_timeout, 10000} 
    ]} 
]. 

我(從1號航站樓)運行:

elixir --name [email protected] --erl "-config sys.config" -S mix phoenix.server 

,然後(從終端2):

elixir --name [email protected] --erl "-config sys.config" -S mix phoenix.server 

,我得到:

** (Mix) Could not start application app: App.start(:normal, []) returned an error: shutdown: failed to start child: App.Endpoint 
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server 
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, App.Endpoint.HTTP} 
    ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup 
    ** (EXIT) {:listen_error, App.Endpoint.HTTP, :eaddrinuse} 

我做錯了什麼?

回答

1

由於您正在嘗試爲同一臺計算機上運行的兩個節點使用相同的端口(默認情況下爲4000),您正在收到此錯誤。

嘗試做:

PORT=4001 elixir --name [email protected] --erl "-config sys.config" -S mix phoenix.server 

您需要更改dev.exs使用環境變量作爲端口支持:

config :my_app, MyApp.Endpoint, 
    http: [port: String.to_integer(System.get_env("PORT") || "4000")], 
+1

@Wulpo那是不可能的。有關更多信息,請參閱http://stackoverflow.com/questions/1694144/can-two-applications-listen-to-the-same-port。 – Gazler

+0

它正在工作,但我的第一個意圖是:在2臺PC上運行2個應用程序實例並使用一個URL。 當我更改端口時,它將是「不同」的應用程序。 (分發編程/計算) – Wulpo

+3

@Wulpo如果你在兩臺不同的物理機器上運行,那麼你可以在同一個端口上運行它們。 – Gazler