From 342bcb1c243726c05bc8fc0ef3a32f18b47ad61a Mon Sep 17 00:00:00 2001 From: azam Date: Sat, 7 Jul 2018 03:05:06 +0900 Subject: [PATCH] Make Serf LAN & WAN port configurable from CLI Make RPC port accessible to CLI Add tests and documentation for server-port, serf-lan-port, serf-wan-port CLI arguments --- agent/config/flags.go | 3 ++ agent/config/flags_test.go | 12 +++++++ agent/config/runtime_test.go | 39 +++++++++++++++++++++++ website/source/docs/agent/options.html.md | 9 ++++++ 4 files changed, 63 insertions(+) diff --git a/agent/config/flags.go b/agent/config/flags.go index 3bad0eaef0..616e0f6a41 100644 --- a/agent/config/flags.go +++ b/agent/config/flags.go @@ -56,6 +56,7 @@ func AddFlags(fs *flag.FlagSet, f *Flags) { add(&f.Config.AdvertiseAddrLAN, "advertise", "Sets the advertise address to use.") add(&f.Config.AdvertiseAddrWAN, "advertise-wan", "Sets address to advertise on WAN instead of -advertise address.") add(&f.Config.BindAddr, "bind", "Sets the bind address for cluster communication.") + add(&f.Config.Ports.Server, "server-port", "Sets the server port to listen on.") add(&f.Config.Bootstrap, "bootstrap", "Sets server to bootstrap mode.") add(&f.Config.BootstrapExpect, "bootstrap-expect", "Sets server to expect bootstrap mode.") add(&f.Config.ClientAddr, "client", "Sets the address to bind for client access. This includes RPC, DNS, HTTP and HTTPS (if configured).") @@ -91,8 +92,10 @@ func AddFlags(fs *flag.FlagSet, f *Flags) { add(&f.Config.RetryJoinMaxAttemptsLAN, "retry-max", "Maximum number of join attempts. Defaults to 0, which will retry indefinitely.") add(&f.Config.RetryJoinMaxAttemptsWAN, "retry-max-wan", "Maximum number of join -wan attempts. Defaults to 0, which will retry indefinitely.") add(&f.Config.SerfBindAddrLAN, "serf-lan-bind", "Address to bind Serf LAN listeners to.") + add(&f.Config.Ports.SerfLAN, "serf-lan-port", "Sets the Serf LAN port to listen on.") add(&f.Config.SegmentName, "segment", "(Enterprise-only) Sets the network segment to join.") add(&f.Config.SerfBindAddrWAN, "serf-wan-bind", "Address to bind Serf WAN listeners to.") + add(&f.Config.Ports.SerfWAN, "serf-wan-port", "Sets the Serf WAN port to listen on.") add(&f.Config.ServerMode, "server", "Switches agent to server mode.") add(&f.Config.EnableSyslog, "syslog", "Enables logging to syslog.") add(&f.Config.UI, "ui", "Enables the built-in static web UI server.") diff --git a/agent/config/flags_test.go b/agent/config/flags_test.go index d7bb053701..c222e569d7 100644 --- a/agent/config/flags_test.go +++ b/agent/config/flags_test.go @@ -48,6 +48,18 @@ func TestParseFlags(t *testing.T) { args: []string{`-dns-port`, `1`}, flags: Flags{Config: Config{Ports: Ports{DNS: pInt(1)}}}, }, + { + args: []string{`-serf-lan-port`, `1`}, + flags: Flags{Config: Config{Ports: Ports{SerfLAN: pInt(1)}}}, + }, + { + args: []string{`-serf-wan-port`, `1`}, + flags: Flags{Config: Config{Ports: Ports{SerfWAN: pInt(1)}}}, + }, + { + args: []string{`-server-port`, `1`}, + flags: Flags{Config: Config{Ports: Ports{Server: pInt(1)}}}, + }, { args: []string{`-join`, `a`, `-join`, `b`}, flags: Flags{Config: Config{StartJoinAddrsLAN: []string{"a", "b"}}}, diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 9326e8ff6b..1127ac34e3 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -643,6 +643,19 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { rt.DataDir = dataDir }, }, + { + desc: "-serf-lan-port", + args: []string{ + `-serf-lan-port=123`, + `-data-dir=` + dataDir, + }, + patch: func(rt *RuntimeConfig) { + rt.SerfPortLAN = 123 + rt.SerfAdvertiseAddrLAN = tcpAddr("10.0.0.1:123") + rt.SerfBindAddrLAN = tcpAddr("0.0.0.0:123") + rt.DataDir = dataDir + }, + }, { desc: "-serf-wan-bind", args: []string{ @@ -654,6 +667,19 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { rt.DataDir = dataDir }, }, + { + desc: "-serf-wan-port", + args: []string{ + `-serf-wan-port=123`, + `-data-dir=` + dataDir, + }, + patch: func(rt *RuntimeConfig) { + rt.SerfPortWAN = 123 + rt.SerfAdvertiseAddrWAN = tcpAddr("10.0.0.1:123") + rt.SerfBindAddrWAN = tcpAddr("0.0.0.0:123") + rt.DataDir = dataDir + }, + }, { desc: "-server", args: []string{ @@ -667,6 +693,19 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { rt.DataDir = dataDir }, }, + { + desc: "-server-port", + args: []string{ + `-server-port=123`, + `-data-dir=` + dataDir, + }, + patch: func(rt *RuntimeConfig) { + rt.ServerPort = 123 + rt.RPCAdvertiseAddr = tcpAddr("10.0.0.1:123") + rt.RPCBindAddr = tcpAddr("0.0.0.0:123") + rt.DataDir = dataDir + }, + }, { desc: "-syslog", args: []string{ diff --git a/website/source/docs/agent/options.html.md b/website/source/docs/agent/options.html.md index 42e233c552..8d7894d3c9 100644 --- a/website/source/docs/agent/options.html.md +++ b/website/source/docs/agent/options.html.md @@ -387,6 +387,12 @@ will exit with an error at startup. within its network segment. See the [Network Segments Guide](/docs/guides/segments.html) for more details. By default, this is an empty string, which is the default network segment. +* `-serf-lan-port` - the Serf LAN port to listen on. + This overrides the default Serf LAN port 8301. This is available in Consul 1.2.2 and later. + +* `-serf-wan-port` - the Serf WAN port to listen on. + This overrides the default Serf WAN port 8302. This is available in Consul 1.2.2 and later. + * `-server` - This flag is used to control if an agent is in server or client mode. When provided, an agent will act as a Consul server. Each Consul cluster must have at least one server and ideally @@ -396,6 +402,9 @@ will exit with an error at startup. participate in a WAN gossip pool with server nodes in other datacenters. Servers act as gateways to other datacenters and forward traffic as appropriate. +* `-server-port` - the server RPC port to listen on. + This overrides the default server RPC port 8300. This is available in Consul 1.2.2 and later. + * `-non-voting-server` - (Enterprise-only) This flag is used to make the server not participate in the Raft quorum, and have it only receive the data replication stream. This can be used to add read scalability to a cluster in cases where a high volume of