Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 614fa91

Browse files
authored
Merge pull request #1313 from yuce/v0.10-docker-tutorial
Added Docker tutorial (v0.10)
2 parents 00f5a15 + d115375 commit 614fa91

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

docs/tutorials.md

+156
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title = "Tutorials"
33
weight = 4
44
nav = [
55
"Setting Up a Secure Cluster",
6+
"Setting Up a Docker Cluster",
67
"Using Integer Field Values",
78
"Storing Row and Column Attributes",
89
]
@@ -238,6 +239,161 @@ curl -k --ipv4 https://02.pilosa.local:10502/index/sample-index/query -d 'Bitmap
238239

239240
Check out our [Administration Guide](https://www.pilosa.com/docs/latest/administration/) to learn more about making the most of your Pilosa cluster and [Configuration Documentation](https://www.pilosa.com/docs/latest/configuration/) to see the available options to configure Pilosa.
240241

242+
### Setting Up a Docker Cluster
243+
244+
In this tutorial, we will be setting up a 2-node Pilosa cluster using Docker containers.
245+
246+
#### Running a Docker Cluster on a Single Server
247+
248+
The instructions below require Docker 1.13 or better.
249+
250+
Let's first be sure that the Pilosa image is up to date:
251+
```
252+
docker pull pilosa/pilosa:latest
253+
```
254+
255+
Then, create a virtual network to attach our containers. We are going to name our network `pilosanet`:
256+
257+
```
258+
docker network create pilosanet
259+
```
260+
261+
Let's run the first Pilosa node and attach it to that virtual network. We set the first node as the cluster coordinator and use its address as the gossip seed. And also set the server address to `pilosa1`:
262+
```
263+
docker run -it --rm --name pilosa1 -p 10101:10101 --network=pilosanet pilosa/pilosa:latest server --bind pilosa1 --cluster.coordinator=true --gossip.seeds=pilosa1:14000
264+
```
265+
266+
Let's run the second Pilosa node and attach it to the virtual network as well. Note that we set the address of the gossip seed to the address of the first node:
267+
```
268+
docker run -it --rm --name pilosa2 --network=pilosanet pilosa/pilosa:latest server --bind pilosa2 --gossip.seeds=pilosa1:14000
269+
```
270+
271+
Let's test that the nodes in the cluster connected with each other:
272+
``` request
273+
curl localhost:10101/status
274+
```
275+
``` response
276+
{"state":"NORMAL","nodes":[{"id":"2e8332d0-1fee-44dd-a359-e0d6ecbcefc1","uri":{"scheme":"http","host":"pilosa1","port":10101},"isCoordinator":true},{"id":"8c0dbcdc-9503-4265-8ad2-ba85a4bb10fa","uri":{"scheme":"http","host":"pilosa2","port":10101},"isCoordinator":false}]}
277+
```
278+
279+
And similarly for the second node:
280+
``` request
281+
curl localhost:10102/status
282+
```
283+
``` response
284+
{"state":"NORMAL","nodes":[{"id":"2e8332d0-1fee-44dd-a359-e0d6ecbcefc1","uri":{"scheme":"http","host":"pilosa1","port":10101},"isCoordinator":true},{"id":"8c0dbcdc-9503-4265-8ad2-ba85a4bb10fa","uri":{"scheme":"http","host":"pilosa2","port":10101},"isCoordinator":false}]}
285+
```
286+
The corresponding [Docker Compose](https://docs.docker.com/compose/) file is below:
287+
288+
```yaml
289+
version: '2'
290+
services:
291+
pilosa1:
292+
image: pilosa/pilosa:latest
293+
ports:
294+
- "10101:10101"
295+
environment:
296+
- PILOSA_CLUSTER_COORDINATOR=true
297+
- PILOSA_GOSSIP_SEEDS=pilosa1:14000
298+
networks:
299+
- pilosanet
300+
entrypoint:
301+
- /pilosa
302+
- server
303+
- --bind
304+
- "pilosa1:10101"
305+
pilosa2:
306+
image: pilosa/pilosa:latest
307+
environment:
308+
- PILOSA_GOSSIP_SEEDS=pilosa1:14000
309+
networks:
310+
- pilosanet
311+
entrypoint:
312+
- /pilosa
313+
- server
314+
- --bind
315+
- "pilosa2:10101"
316+
networks:
317+
pilosanet:
318+
```
319+
320+
#### Running a Docker Swarm
321+
322+
It is very easy to run a Pilosa Cluster on different servers using [Docker Swarm mode](https://docs.docker.com/engine/swarm/). All we have to do is creating an overlay network instead of the bridge network.
323+
324+
The instructions in this section require Docker 17.06 and better. Although it is possible to run a Docker swarm on MacOS or Windows, it is easiest to run it on Linux. So we assume you are trying these instructions on Linux, probably on the cloud.
325+
326+
We are going to use two servers: the manager node runs in the first server and a worker node in the second server.
327+
328+
Docker nodes require some ports to be accesible from outside. Before carrying on, make sure the following ports are open on all nodes: TCP/2377, TCP/7946, UDP/7946, UDP/4789.
329+
330+
Let's initialize the swarm first. Run the following on the manager:
331+
```
332+
docker swarm init --advertise-addr=IP-ADDRESS
333+
```
334+
335+
Virtual machines running on the cloud usually have at least two network interfaces: the external interface and the internal interface. Use the IP of the external interface.
336+
337+
The output of the command above should be similar to:
338+
```
339+
To add a manager to this swarm, run the following command:
340+
341+
docker swarm join --token SOME-TOKEN MANAGER-IP-ADDRESS:2377
342+
```
343+
344+
Let's make the worker node join the manager. Copy/paste the command above in a shell on the worker, replacing the token and IP address with the correct values. You may neeed to add `--advertise-addr=WORKER-EXTERNAL-IP-ADDRESS` parameter if the worker has more than one network interface:
345+
```
346+
docker swarm join --token SOME-TOKEN MANAGER-IP-ADDRESS:2377
347+
```
348+
349+
Run the following on the manager to check that the worker joined to the swarm:
350+
```
351+
docker node ls
352+
```
353+
354+
Which should output:
355+
356+
ID|HOSTNAME|STATUS|AVAILABILITY|MANAGER STATUS|ENGINE VERSION
357+
---|--------|------|------------|--------------|-------------
358+
MANAGER-ID *|swarm1|Ready|Active|Leader|18.05.0-ce|
359+
WORKER-ID|swarm2|Ready|Active||18.05.0-ce|
360+
361+
If you have created the `pilosanet` network before, delete it before carrying on, otherwise skip to the next step:
362+
```
363+
docker network rm pilosanet
364+
```
365+
366+
Let's create the `pilosanet` network, but with `overlay` type this time. We should also make this network attachable in order to be able to attach containers to it. Run the following on the manager:
367+
```
368+
docker network create -d overlay pilosanet --attachable
369+
```
370+
371+
We can now create the Pilosa containers. Let's start the coordinator node first. Run the following on one of the servers:
372+
```
373+
docker run -it --rm --name pilosa1 --network=pilosanet pilosa/pilosa:latest server --bind pilosa1 --cluster.coordinator=true --gossip.seeds=pilosa1:14000
374+
```
375+
376+
And the following on the other server:
377+
```
378+
docker run -it --rm --name pilosa2 --network=pilosanet pilosa/pilosa:latest server --bind pilosa2 --gossip.seeds=pilosa1:14000
379+
```
380+
381+
These were the same commands we used in the previous section except the port mapping! Let's run another container on the same virtual network to read the status from the coordinator:
382+
``` request
383+
docker run -it --rm --network=pilosanet --name shell alpine wget -q -O- pilosa1:10101/status
384+
```
385+
``` response
386+
{"state":"NORMAL","nodes":[{"id":"3e3b0abd-1945-441a-a01f-5a28272972f5","uri":{"scheme":"http","host":"pilosa1","port":10101},"isCoordinator":true},{"id":"71ed27cc-9443-4f41-88fb-1c22f92bf695","uri":{"scheme":"http","host":"pilosa2","port":10101},"isCoordinator":false}]}
387+
```
388+
389+
You can add as many as worker nodes to both the swarm and the Pilosa cluster using the steps above.
390+
391+
#### What's Next?
392+
393+
Check out our [Administration Guide](https://www.pilosa.com/docs/latest/administration/) to learn more about making the most of your Pilosa cluster and [Configuration Documentation](https://www.pilosa.com/docs/latest/configuration/) to see the available options to configure Pilosa.
394+
395+
Refer to the [Docker documentation](https://docs.docker.com) to see your options about running Docker containers. The [Networking with overlay networks](https://docs.docker.com/network/network-tutorial-overlay/) is a detailed overview of the Docket swarm mode and overlay networks.
396+
241397

242398
### Using Integer Field Values
243399

0 commit comments

Comments
 (0)