github.com/dkerwin/nomad@v0.3.3-0.20160525181927-74554135514b/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 19 the file from the [repository here](https://github.com/hashicorp/nomad/tree/master/demo/vagrant), 20 or paste this into a file called `server.hcl`: 21 22 ``` 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 ``` 47 $ sudo nomad agent -config server.hcl 48 ==> WARNING: Bootstrap mode enabled! Potentially unsafe operation. 49 ==> Starting Nomad agent... 50 ==> Nomad agent configuration: 51 52 Atlas: <disabled> 53 Client: false 54 Log Level: DEBUG 55 Region: global (DC: dc1) 56 Server: true 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 ``` 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 ``` 116 $ sudo nomad agent -config client1.hcl 117 ==> Starting Nomad agent... 118 ==> Nomad agent configuration: 119 120 Atlas: <disabled> 121 Client: true 122 Log Level: DEBUG 123 Region: global (DC: dc1) 124 Server: false 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 ``` 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 ``` 161 $ nomad run example.nomad 162 ==> Monitoring evaluation "8e0a7cf9" 163 Evaluation triggered by job "example" 164 Allocation "501154ac" created: node "c887deef", group "cache" 165 Allocation "7e2b3900" created: node "fca62612", group "cache" 166 Allocation "9c66fcaf" created: node "c887deef", group "cache" 167 Evaluation status changed: "pending" -> "complete" 168 ==> Evaluation "8e0a7cf9" finished with status "complete" 169 ``` 170 171 We can see in the output that the scheduler assigned two of the 172 tasks for one of the client nodes and the remaining task to the 173 second client. 174 175 We can again use the [`status` command](/docs/commands/status.html) to verify: 176 177 ``` 178 $ nomad status example 179 ID = example 180 Name = example 181 Type = service 182 Priority = 50 183 Datacenters = dc1 184 Status = running 185 Periodic = false 186 187 ==> Evaluations 188 ID Priority Triggered By Status 189 54dd2ae3 50 job-register complete 190 191 ==> Allocations 192 ID Eval ID Node ID Task Group Desired Status 193 102225ab 54dd2ae3 56b590e6 cache run running 194 f327d2b1 54dd2ae3 e4235508 cache run running 195 f91137f8 54dd2ae3 56b590e6 cache run running 196 197 ``` 198 199 We can see that all our tasks have been allocated and are running. 200 Once we are satisfied that our job is happily running, we can tear 201 it down with `nomad stop`. 202 203 ## Next Steps 204 205 We've now concluded the getting started guide, however there are a number 206 of [next steps](next-steps.html) to get started with Nomad. 207