github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/configuration/index.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: Agent Configuration
     4  description: Learn about the configuration options available for the Nomad agent.
     5  ---
     6  
     7  # Nomad Configuration
     8  
     9  Nomad agents have a variety of parameters that can be specified via
    10  configuration files or command-line flags. Configuration files are written in
    11  [HCL][hcl]. Nomad can read and combine parameters from multiple configuration
    12  files or directories to configure the Nomad agent.
    13  
    14  ## Load Order and Merging
    15  
    16  The Nomad agent supports multiple configuration files, which can be provided
    17  using the `-config` CLI flag. The flag can accept either a file or folder. In
    18  the case of a folder, any `.hcl` and `.json` files in the folder will be loaded
    19  and merged in lexicographical order. Directories are not loaded recursively.
    20  
    21  For example:
    22  
    23  ```shell-session
    24  $ nomad agent -config=server.conf -config=/etc/nomad -config=extra.json
    25  ```
    26  
    27  This will load configuration from `server.conf`, from `.hcl` and `.json` files
    28  under `/etc/nomad`, and finally from `extra.json`.
    29  
    30  As each file is processed, its contents are merged into the existing
    31  configuration. When merging, any non-empty values from the latest config file
    32  will append or replace parameters in the current configuration. An empty value
    33  means `""` for strings, `0` for integer or float values, and `false` for
    34  booleans. Since empty values are ignored you cannot disable a parameter like
    35  `server` mode once you've enabled it.
    36  
    37  Please note that `plugin` blocks for a given plugin always replace and
    38  override each other, rather than being merged.
    39  
    40  Here is an example Nomad agent configuration that runs in both client and server
    41  mode.
    42  
    43  ```hcl
    44  data_dir  = "/var/lib/nomad"
    45  
    46  bind_addr = "0.0.0.0" # the default
    47  
    48  advertise {
    49    # Defaults to the first private IP address.
    50    http = "1.2.3.4"
    51    rpc  = "1.2.3.4"
    52    serf = "1.2.3.4:5648" # non-default ports may be specified
    53  }
    54  
    55  server {
    56    enabled          = true
    57    bootstrap_expect = 3
    58  }
    59  
    60  client {
    61    enabled       = true
    62  }
    63  
    64  plugin "raw_exec" {
    65    config {
    66      enabled = true
    67    }
    68  }
    69  
    70  consul {
    71    address = "1.2.3.4:8500"
    72  }
    73  
    74  ```
    75  
    76  ~> Note that it is strongly recommended **not** to operate a node as both
    77  `client` and `server`, although this is supported to simplify development and
    78  testing.
    79  
    80  ## General Parameters
    81  
    82  - `acl` `(`[`ACL`]`: nil)` - Specifies configuration which is specific to ACLs.
    83  
    84  - `addresses` `(Addresses: see below)` - Specifies the bind address for
    85    individual network services. Any values configured in this stanza take
    86    precedence over the default [bind_addr](#bind_addr). These values should be
    87    specified in IP format without a port (ex. `"0.0.0.0"`). To set the port,
    88    see the [`ports`](#ports) field. The values support [go-sockaddr/template
    89    format][go-sockaddr/template].
    90  
    91    - `http` - The address the HTTP server is bound to. This is the most
    92      common bind address to change. The `http` field accepts multiple
    93      values, separated by spaces, to bind to multiple addresses.
    94  
    95    - `rpc` - The address to bind the internal RPC interfaces to. Should be
    96      exposed only to other cluster members if possible.
    97  
    98    - `serf` - The address used to bind the gossip layer to. Both a TCP and UDP
    99      listener will be exposed on this address. Should be exposed only to other
   100      cluster members if possible.
   101  
   102  - `advertise` `(Advertise: see below)` - Specifies the advertise address for
   103    individual network services. This can be used to advertise a different address
   104    to the peers of a server or a client node to support more complex network
   105    configurations such as NAT. This configuration is optional, and defaults to
   106    the bind address of the specific network service if it is not provided. Any
   107    values configured in this stanza take precedence over the default
   108    [bind_addr](#bind_addr).
   109  
   110    If the bind address is `0.0.0.0` then the IP address of the default private
   111    network interface advertised. The `advertise` values may include an
   112    alternate port, but otherwise default to the port used by the bind address.
   113    The values support [go-sockaddr/template format][go-sockaddr/template].
   114  
   115    - `http` - The address to advertise for the HTTP interface. This should be
   116      reachable by all the nodes from which end users are going to use the Nomad
   117      CLI tools.
   118  
   119    - `rpc` - The address used to advertise to Nomad clients for connecting to Nomad
   120      servers for RPC. This allows Nomad clients to connect to Nomad servers from
   121      behind a NAT gateway. This address much be reachable by all Nomad client nodes.
   122      When set, the Nomad servers will use the `advertise.serf` address for RPC
   123      connections amongst themselves. Setting this value on a Nomad client has no
   124      effect.
   125  
   126    - `serf` - The address advertised for the gossip layer. This address must be
   127      reachable from all server nodes. It is not required that clients can reach
   128      this address. Nomad servers will communicate to each other over RPC using
   129      the advertised Serf IP and advertised RPC Port.
   130  
   131  - `audit` `(`[`Audit`]`: nil)` - Enterprise-only. Specifies audit logging
   132    configuration.
   133  
   134  - `bind_addr` `(string: "0.0.0.0")` - Specifies which address the Nomad
   135    agent should bind to for network services, including the HTTP interface as
   136    well as the internal gossip protocol and RPC mechanism. This should be
   137    specified in IP format, and can be used to easily bind all network services to
   138    the same address. It is also possible to bind the individual services to
   139    different addresses using the [addresses](#addresses) configuration option.
   140    Dev mode (`-dev`) defaults to localhost.
   141    The value supports [go-sockaddr/template format][go-sockaddr/template].
   142  
   143  - `client` `(`[`Client`]`: nil)` - Specifies configuration which is specific
   144    to the Nomad client.
   145  
   146  - `consul` `(`[`Consul`]`: nil)` - Specifies configuration for
   147    connecting to Consul.
   148  
   149  - `datacenter` `(string: "dc1")` - Specifies the data center of the local agent. A datacenter is an abstract grouping of clients within a region. Clients are not required to be in the same datacenter as the servers they are joined with, but do need to be in the same region.
   150  
   151  - `data_dir` `(string: required)` - Specifies a local directory used to store
   152    agent state. Client nodes use this directory by default to store temporary
   153    allocation data as well as cluster information. Server nodes use this
   154    directory to store cluster state, including the replicated log and snapshot
   155    data. This must be specified as an absolute path.
   156  
   157  - `disable_anonymous_signature` `(bool: false)` - Specifies if Nomad should
   158    provide an anonymous signature for de-duplication with the update check.
   159  
   160  - `disable_update_check` `(bool: false)` - Specifies if Nomad should not check
   161    for updates and security bulletins. _This defaults to `true` in Nomad Enterprise._
   162  
   163  - `enable_debug` `(bool: false)` - Specifies if the debugging HTTP endpoints
   164    should be enabled. These endpoints can be used with profiling tools to dump
   165    diagnostic information about Nomad's internals.
   166  
   167  - `enable_syslog` `(bool: false)` - Specifies if the agent should log to syslog.
   168    This option only works on Unix based systems.
   169  
   170  - `http_api_response_headers` `(map<string|string>: nil)` - Specifies
   171    user-defined headers to add to the HTTP API responses.
   172  
   173  - `leave_on_interrupt` `(bool: false)` - Specifies if the agent should
   174    gracefully leave when receiving the interrupt signal. By default, the agent
   175    will exit forcefully on any signal. This value should only be set to true on
   176    server agents if it is expected that a terminated server instance will never
   177    join the cluster again.
   178  
   179  - `leave_on_terminate` `(bool: false)` - Specifies if the agent should
   180    gracefully leave when receiving the terminate signal. By default, the agent
   181    will exit forcefully on any signal. This value should only be set to true on
   182    server agents if it is expected that a terminated server instance will never
   183    join the cluster again.
   184  
   185  - `limits` - Available in Nomad 0.10.3 and later, this is a nested object that
   186    configures limits that are enforced by the agent. The following parameters
   187    are available:
   188  
   189    - `https_handshake_timeout` `(string: "5s")` - Configures the limit for how
   190      long the HTTPS server in both client and server agents will wait for a
   191      client to complete a TLS handshake. This should be kept conservative as it
   192      limits how many connections an unauthenticated attacker can open if
   193      [`tls.http = true`][tls] is being used (strongly recommended in
   194      production). Default value is `5s`. `0` disables HTTP handshake timeouts.
   195  
   196    - `http_max_conns_per_client` `(int: 100)` - Configures a limit of how many
   197      concurrent TCP connections a single client IP address is allowed to open to
   198      the agent's HTTP server. This affects the HTTP servers in both client and
   199      server agents. Default value is `100`. `0` disables HTTP connection limits.
   200  
   201    - `rpc_handshake_timeout` `(string: "5s")` - Configures the limit for how
   202      long servers will wait after a client TCP connection is established before
   203      they complete the connection handshake. When TLS is used, the same timeout
   204      applies to the TLS handshake separately from the initial protocol
   205      negotiation. All Nomad clients should perform this immediately on
   206      establishing a new connection. This should be kept conservative as it
   207      limits how many connections an unauthenticated attacker can open if
   208      TLS is being using to authenticate clients (strongly recommended in
   209      production). When `tls.rpc` is true on servers, this limits how long the
   210      connection and associated goroutines will be held open before the client
   211      successfully authenticates. Default value is `5s`. `0` disables RPC handshake
   212      timeouts.
   213  
   214    - `rpc_max_conns_per_client` `(int: 100)` - Configures a limit of how
   215      many concurrent TCP connections a single source IP address is allowed
   216      to open to a single server. Client agents do not accept RPC TCP connections
   217      directly and therefore are not affected. It affects both clients connections
   218      and other server connections. Nomad clients multiplex many RPC calls over a
   219      single TCP connection, except for streaming endpoints such as [log
   220      streaming][log-api] which require their own connection when routed through
   221      servers. A server needs at least 2 TCP connections (1 Raft, 1 RPC) per peer
   222      server locally and in any federated region. Servers also need a TCP connection
   223      per routed streaming endpoint concurrently in use. Only operators use streaming
   224      endpoints; as of 0.10.3 Nomad client code does not. A reasonably low limit
   225      significantly reduces the ability of an unauthenticated attacker to consume
   226      unbounded resources by holding open many connections. You may need to
   227      increase this if WAN federated servers connect via proxies or NAT gateways
   228      or similar causing many legitimate connections from a single source IP.
   229      Default value is `100` which is designed to support the majority of users.
   230      `0` disables RPC connection limits. `26` is the minimum as `20` connections
   231      are always reserved for non-streaming connections (Raft and RPC) to ensure
   232      streaming RPCs do not prevent normal server operation. This minimum may be
   233      lowered in the future when streaming RPCs no longer require their own TCP
   234      connection.
   235  
   236  - `log_level` `(string: "INFO")` - Specifies the verbosity of logs the Nomad
   237    agent will output. Valid log levels include `WARN`, `INFO`, or `DEBUG` in
   238    increasing order of verbosity.
   239  
   240  - `log_json` `(bool: false)` - Output logs in a JSON format.
   241  
   242  - `log_file` `(string: "")` - Specifies the path for logging. If the path
   243    does not includes a filename, the filename defaults to `nomad.log`. This
   244    setting can be combined with `log_rotate_bytes` and `log_rotate_duration` for
   245    a fine-grained log rotation control.
   246  
   247  - `log_rotate_bytes` `(int: 0)` - Specifies the number of bytes that should be
   248    written to a log before it needs to be rotated. Unless specified, there is no
   249    limit to the number of bytes that can be written to a log file.
   250  
   251  - `log_rotate_duration` `(duration: "24h")` - Specifies the maximum duration a
   252    log should be written to before it needs to be rotated. Must be a duration
   253    value such as 30s.
   254  
   255  - `log_rotate_max_files` `(int: 0)` - Specifies the maximum number of older
   256    log file archives to keep, not including the log file currently being
   257    written. If set to 0 no files are ever deleted. Note that the total number
   258    of log files, for each of `stderr` and `stdout`, will be 1 greater than the
   259    `log_rotate_max_files` value.
   260  
   261  - `name` `(string: [hostname])` - Specifies the name of the local node. This
   262    value is used to identify individual agents. When specified on a server, the
   263    name must be unique within the region.
   264  
   265  - `plugin_dir` `(string: "[data_dir]/plugins")` - Specifies the directory to
   266    use for looking up plugins. By default, this is the top-level
   267    [data_dir](#data_dir) suffixed with "plugins", like `"/opt/nomad/plugins"`.
   268    This must be an absolute path.
   269  
   270  - `plugin` `(`[`Plugin`]`: nil)` - Specifies configuration for a
   271    specific plugin. The plugin stanza may be repeated, once for each plugin being
   272    configured. The key of the stanza is the plugin's executable name relative to
   273    the [plugin_dir](#plugin_dir).
   274  
   275  - `ports` `(Port: see below)` - Specifies the network ports used for different
   276    services required by the Nomad agent.
   277  
   278    - `http` - The port used to run the HTTP server.
   279  
   280    - `rpc` - The port used for internal RPC communication between
   281      agents and servers, and for inter-server traffic for the consensus algorithm
   282      (raft).
   283  
   284    - `serf` - The port used for the gossip protocol for cluster
   285      membership. Both TCP and UDP should be routable between the server nodes on
   286      this port.
   287  
   288      The default values are:
   289  
   290      ```hcl
   291      ports {
   292        http = 4646
   293        rpc  = 4647
   294        serf = 4648
   295      }
   296      ```
   297  
   298  - `region` `(string: "global")` - Specifies the region the Nomad agent is a
   299    member of. A region typically maps to a geographic region, for example `us`,
   300    with potentially multiple zones, which map to [datacenters](#datacenter) such
   301    as `us-west` and `us-east`.
   302  
   303    !> **Be Careful!** Changing the `region` of an agent with data stored in its
   304    `data_dir` may result in overwrite and data loss in the new region so avoid
   305    modifying this value after the agent starts. If you must change it, make sure
   306    no local state remains from the previous region before running the agent
   307    again.
   308  
   309  - `sentinel` `(`[`Sentinel`]`: nil)` - Specifies configuration for Sentinel
   310    policies.
   311  
   312  - `server` `(`[`Server`]`: nil)` - Specifies configuration which is specific
   313    to the Nomad server.
   314  
   315  - `syslog_facility` `(string: "LOCAL0")` - Specifies the syslog facility to
   316    write to. This has no effect unless `enable_syslog` is true.
   317  
   318  - `tls` `(`[`TLS`][tls]`: nil)` - Specifies configuration for TLS.
   319  
   320  - `vault` `(`[`Vault`]`: nil)` - Specifies configuration for
   321    connecting to Vault.
   322  
   323  ## Configuration Reload
   324  
   325  You can send the Nomad process a `SIGHUP` signal to reload a limited subset of
   326  its configuration. The fields that currently support reloading are:
   327  
   328  - [`log_level`](#log_level): the log level is reloaded but not any other
   329    logging configuration value.
   330  - [`tls`][tls-reload]: note this only reloads the TLS configuration between
   331    Nomad agents (servers and clients), and not the TLS configuration for
   332    communication with Consul or Vault.
   333  - [`vault`][vault-reload]: note this only reloads the TLS configuration
   334    between Nomad and Vault, but not other configuration values.
   335  
   336  In order to reload any other configuration values, you must restart the Nomad
   337  agent.
   338  
   339  <EnterpriseAlert>
   340  Nomad Enterprise requires a license. If the server.license_path
   341  configuration or NOMAD_LICENSE_PATH environment variable are set, the
   342  license will be reloaded from the file on a configuration reload.
   343  </EnterpriseAlert>
   344  
   345  If the Nomad agent receives a `SIGHUP` during initialization, it may crash
   346  (see [GH-3885]). Ensure that the Nomad agent is able to receive RPC traffic
   347  before attempting to reload its configuration.
   348  
   349  ## Examples
   350  
   351  ### Custom Region and Datacenter
   352  
   353  This example shows configuring a custom region and data center for the Nomad
   354  agent:
   355  
   356  ```hcl
   357  region     = "europe"
   358  datacenter = "ams"
   359  ```
   360  
   361  ### Enable CORS
   362  
   363  This example shows how to enable CORS on the HTTP API endpoints:
   364  
   365  ```hcl
   366  http_api_response_headers {
   367    "Access-Control-Allow-Origin" = "*"
   368  }
   369  ```
   370  
   371  [`acl`]: /docs/configuration/acl 'Nomad Agent ACL Configuration'
   372  [`audit`]: /docs/configuration/audit 'Nomad Agent Audit Logging Configuration'
   373  [`client`]: /docs/configuration/client 'Nomad Agent client Configuration'
   374  [`consul`]: /docs/configuration/consul 'Nomad Agent consul Configuration'
   375  [`plugin`]: /docs/configuration/plugin 'Nomad Agent Plugin Configuration'
   376  [`sentinel`]: /docs/configuration/sentinel 'Nomad Agent sentinel Configuration'
   377  [`server`]: /docs/configuration/server 'Nomad Agent server Configuration'
   378  [tls]: /docs/configuration/tls 'Nomad Agent tls Configuration'
   379  [`vault`]: /docs/configuration/vault 'Nomad Agent vault Configuration'
   380  [go-sockaddr/template]: https://godoc.org/github.com/hashicorp/go-sockaddr/template
   381  [log-api]: /api-docs/client#stream-logs
   382  [hcl]: https://github.com/hashicorp/hcl 'HashiCorp Configuration Language'
   383  [tls-reload]: /docs/configuration/tls#tls-configuration-reloads
   384  [vault-reload]: /docs/configuration/vault#vault-configuration-reloads
   385  [gh-3885]: https://github.com/hashicorp/nomad/issues/3885