github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/website/source/intro/getting-started/cluster.html.md (about)

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