github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/intro/getting-started/cluster.mdx (about)

     1  ---
     2  layout: intro
     3  page_title: Clustering
     4  sidebar_title: Clustering
     5  description: Join another Nomad client to create your first cluster.
     6  ---
     7  
     8  # Clustering
     9  
    10  We have started our first agent and run a job against it in development mode.
    11  This demonstrates the ease of use and the workflow of Nomad, but did not show how
    12  this could be extended to a scalable, production-grade configuration. In this step,
    13  we will create our first real cluster with multiple nodes.
    14  
    15  ## Starting the Server
    16  
    17  The first step is to create the config file for the server. Either download the
    18  [file from the repository][server.hcl], or paste this into a file called
    19  `server.hcl`:
    20  
    21  ```hcl
    22  # Increase log verbosity
    23  log_level = "DEBUG"
    24  
    25  # Setup data dir
    26  data_dir = "/tmp/server1"
    27  
    28  # Enable the server
    29  server {
    30      enabled = true
    31  
    32      # Self-elect, should be 3 or 5 for production
    33      bootstrap_expect = 1
    34  }
    35  ```
    36  
    37  This is a fairly minimal server configuration file, but it
    38  is enough to start an agent in server only mode and have it
    39  elected as a leader. The major change that should be made for
    40  production is to run more than one server, and to change the
    41  corresponding `bootstrap_expect` value.
    42  
    43  Once the file is created, start the agent in a new tab:
    44  
    45  ```shell-sessionnomad agent -config server.hcl
    46  ==> WARNING: Bootstrap mode enabled! Potentially unsafe operation.
    47  ==> Starting Nomad agent...
    48  ==> Nomad agent configuration:
    49  
    50                  Client: false
    51               Log Level: DEBUG
    52                  Region: global (DC: dc1)
    53                  Server: true
    54                 Version: 0.7.0
    55  
    56  ==> Nomad agent started! Log data will stream in below:
    57  
    58      [INFO] serf: EventMemberJoin: nomad.global 127.0.0.1
    59      [INFO] nomad: starting 4 scheduling worker(s) for [service batch _core]
    60      [INFO] raft: Node at 127.0.0.1:4647 [Follower] entering Follower state
    61      [INFO] nomad: adding server nomad.global (Addr: 127.0.0.1:4647) (DC: dc1)
    62      [WARN] raft: Heartbeat timeout reached, starting election
    63      [INFO] raft: Node at 127.0.0.1:4647 [Candidate] entering Candidate state
    64      [DEBUG] raft: Votes needed: 1
    65      [DEBUG] raft: Vote granted. Tally: 1
    66      [INFO] raft: Election won. Tally: 1
    67      [INFO] raft: Node at 127.0.0.1:4647 [Leader] entering Leader state
    68      [INFO] nomad: cluster leadership acquired
    69      [INFO] raft: Disabling EnableSingleNode (bootstrap)
    70      [DEBUG] raft: Node 127.0.0.1:4647 updated peer set (2): [127.0.0.1:4647]
    71  ```
    72  
    73  We can see above that client mode is disabled, and that we are
    74  only running as the server. This means that this server will manage
    75  state and make scheduling decisions but will not run any tasks.
    76  Now we need some agents to run tasks!
    77  
    78  ## Starting the Clients
    79  
    80  Similar to the server, we must first configure the clients. Either download
    81  the configuration for `client1` and `client2` from the
    82  [repository here](https://github.com/hashicorp/nomad/tree/master/demo/vagrant), or
    83  paste the following into `client1.hcl`:
    84  
    85  ```hcl
    86  # Increase log verbosity
    87  log_level = "DEBUG"
    88  
    89  # Setup data dir
    90  data_dir = "/tmp/client1"
    91  
    92  # Give the agent a unique name. Defaults to hostname
    93  name = "client1"
    94  
    95  # Enable the client
    96  client {
    97      enabled = true
    98  
    99      # For demo assume we are talking to server1. For production,
   100      # this should be like "nomad.service.consul:4647" and a system
   101      # like Consul used for service discovery.
   102      servers = ["127.0.0.1:4647"]
   103  }
   104  
   105  # Modify our port to avoid a collision with server1
   106  ports {
   107      http = 5656
   108  }
   109  ```
   110  
   111  Copy that file to `client2.hcl`. Change the `data_dir` to be `/tmp/client2`,
   112  the `name` to `client2`, and the `http` port to 5657. Once you have created
   113  both `client1.hcl` and `client2.hcl`, open a tab for each and start the agents:
   114  
   115  ```shell-sessionsudo nomad agent -config client1.hcl
   116  ==> Starting Nomad agent...
   117  ==> Nomad agent configuration:
   118  
   119                  Client: true
   120               Log Level: DEBUG
   121                  Region: global (DC: dc1)
   122                  Server: false
   123                 Version: 0.7.0
   124  
   125  ==> Nomad agent started! Log data will stream in below:
   126  
   127      [DEBUG] client: applied fingerprints [host memory storage arch cpu]
   128      [DEBUG] client: available drivers [docker exec]
   129      [DEBUG] client: node registration complete
   130      ...
   131  ```
   132  
   133  In the output we can see the agent is running in client mode only.
   134  This agent will be available to run tasks but will not participate
   135  in managing the cluster or making scheduling decisions.
   136  
   137  Using the [`node status` command](/docs/commands/node/status)
   138  we should see both nodes in the `ready` state:
   139  
   140  ```shell-sessionnomad node status
   141  ID        DC   Name     Class   Drain  Eligibility  Status
   142  fca62612  dc1  client1  <none>  false  eligible     ready
   143  c887deef  dc1  client2  <none>  false  eligible     ready
   144  ```
   145  
   146  We now have a simple three node cluster running. The only difference
   147  between a demo and full production cluster is that we are running a
   148  single server instead of three or five.
   149  
   150  ## Submit a Job
   151  
   152  Now that we have a simple cluster, we can use it to schedule a job.
   153  We should still have the `example.nomad` job file from before, but
   154  verify that the `count` is still set to 3.
   155  
   156  Then, use the [`job run` command](/docs/commands/job/run) to submit the job:
   157  
   158  ```shell-sessionnomad job run example.nomad
   159  ==> Monitoring evaluation "8e0a7cf9"
   160      Evaluation triggered by job "example"
   161      Evaluation within deployment: "0917b771"
   162      Allocation "501154ac" created: node "c887deef", group "cache"
   163      Allocation "7e2b3900" created: node "fca62612", group "cache"
   164      Allocation "9c66fcaf" created: node "c887deef", group "cache"
   165      Evaluation status changed: "pending" -> "complete"
   166  ==> Evaluation "8e0a7cf9" finished with status "complete"
   167  ```
   168  
   169  We can see in the output that the scheduler assigned two of the
   170  tasks for one of the client nodes and the remaining task to the
   171  second client.
   172  
   173  We can again use the [`status` command](/docs/commands/status) to verify:
   174  
   175  ```shell-sessionnomad status example
   176  ID          = example
   177  Name        = example
   178  Submit Date   = 07/26/17 16:34:58 UTC
   179  Type        = service
   180  Priority    = 50
   181  Datacenters = dc1
   182  Status      = running
   183  Periodic    = false
   184  Parameterized = false
   185  
   186  Summary
   187  Task Group  Queued  Starting  Running  Failed  Complete  Lost
   188  cache       0       0         3        0       0         0
   189  
   190  Latest Deployment
   191  ID          = fc49bd6c
   192  Status      = running
   193  Description = Deployment is running
   194  
   195  Deployed
   196  Task Group  Desired  Placed  Healthy  Unhealthy
   197  cache       3        3       0        0
   198  
   199  Allocations
   200  ID        Eval ID   Node ID   Task Group  Desired  Status   Created At
   201  501154ac  8e0a7cf9  c887deef  cache       run      running  08/08/16 21:03:19 CDT
   202  7e2b3900  8e0a7cf9  fca62612  cache       run      running  08/08/16 21:03:19 CDT
   203  9c66fcaf  8e0a7cf9  c887deef  cache       run      running  08/08/16 21:03:19 CDT
   204  ```
   205  
   206  We can see that all our tasks have been allocated and are running.
   207  Once we are satisfied that our job is happily running, we can tear
   208  it down with `nomad job stop`.
   209  
   210  ## Next Steps
   211  
   212  Nomad is now up and running. The cluster can be entirely managed from the command line,
   213  but Nomad also comes with a web interface that is hosted alongside the HTTP API.
   214  Next, we'll [visit the UI in the browser](/intro/getting-started/ui).
   215  
   216  [server.hcl]: https://raw.githubusercontent.com/hashicorp/nomad/master/demo/vagrant/server.hcl