DEV Community

Lucien Volmar for Aerospike

Posted on • Edited on

How do I get a 2 nodes Aerospike cluster running quickly in Docker without editing a single file?

Often we need to bring up a small Aerospike cluster for either functional testing or for development purposes.
There are zillion of tools available for deployment to production (helm+Kubernetes, docker swarm, docker-compose etc), but in some cases its not needed for a basic cluster running on an old mac book. Mine is a MacBook Pro (Retina, 15-inch, Late 2013, last one running in the office!)
To quickly bring up a 2 nodes cluster running the latest Aerospike CE server you can execute these commands at a terminal:

1. Generate aerospike.conf files:

docker run --rm -tid --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server

mkdir aero1
mkdir aero2

docker cp aerospike1:/etc/aerospike/aerospike.conf aero1/
docker cp aerospike1:/etc/aerospike/aerospike.conf aero2/

docker stop aerospike1

sed -i'' -e 's/local/eth0/g' aero1/aerospike.conf
sed -i'' -e 's/local/eth0/g' aero2/aerospike.conf
Enter fullscreen mode Exit fullscreen mode

2. Start 2 Aerospike containers

docker run -tid -v $(pwd)/aero1:/etc/aerospike/ --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server

docker run -tid -v $(pwd)/aero2:/etc/aerospike/ --name aerospike2 -p 6000:3000 -p 6001:3001 -p 6002:3002 -p 6003:3003 aerospike/aerospike-server

Enter fullscreen mode Exit fullscreen mode

3. Get IP address of each node:

docker exec -ti aerospike1 asinfo -v service
docker exec -ti aerospike2 asinfo -v service
Enter fullscreen mode Exit fullscreen mode

4. Run an asinfo -v tip command to form cluster:

docker exec -ti aerospike1 asinfo -v 'tip:host=<IP ADDRESS from aerospike2>;port=3002'
Enter fullscreen mode Exit fullscreen mode

(replace ' with double quotes on Windows environments!)

I guess we could get fancy and automate the last line:

docker exec -e "AEROSPIKE2=$(docker exec -ti aerospike2 asinfo -v service|cut -d ':' -f1)" -ti aerospike1 asinfo -v 'tip:host=$AEROSPIKE2;port=3002'
Enter fullscreen mode Exit fullscreen mode

Let's keep it simple for now!
Executing above command lines:

$ docker run --rm -tid --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server
0d595a1f6d1363ec61ddb987006c21634e27b7026e94fc91a3cb384b5e23f498

$ docker cp aerospike1:/etc/aerospike/aerospike.conf aero1/
$ docker cp aerospike1:/etc/aerospike/aerospike.conf aero2/
$ docker stop aerospike1
aerospike1
$ sed -i'' -e 's/local/eth0/g' aero1/aerospike.conf
$ sed -i'' -e 's/local/eth0/g' aero2/aerospike.conf
$ docker run -tid -v $(pwd)/aero1:/etc/aerospike/ --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server
3a7bf955ba7066205afae5dade547b99a20b29a507f51dc8aa24f9fcd8a6d981
$ docker run -tid -v $(pwd)/aero2:/etc/aerospike/ --name aerospike2 -p 6000:3000 -p 6001:3001 -p 6002:3002 -p 6003:3003 aerospike/aerospike-server
78a958a5143eda598caa45fd54cc8ba479af78cf92d4f6263c4e9a9b36e14457

Enter fullscreen mode Exit fullscreen mode

Let us verify that we have a cluster running using asadm:

~/Development/test.docker $ docker exec -ti aerospike1 asadm
Seed:        [('127.0.0.1', 3000, None)]
Config_file: /root/.aerospike/astools.conf, /etc/aerospike/astools.conf
Aerospike Interactive Shell, version 0.3.3
Found 2 nodes
Online:  172.17.0.3:3000, 172.17.0.2:3000
Enter fullscreen mode Exit fullscreen mode

Let us confirm containerized app connection using aerospike-tools container:

~/Development/test.docker $ docker run --rm -ti --name aerospike-tools aerospike/aerospike-tools aql -h 172.17.0.3
Seed:         172.17.0.3
User:         None
Config File:  /etc/aerospike/astools.conf /root/.aerospike/astools.conf 
Aerospike Query Client
Version 3.23.0
C Client Version 4.6.9
Copyright 2012-2019 Aerospike. All rights reserved.
aql> INSERT INTO test.demo (PK, foo, bar) VALUES ('key1', 123, 'abc')
OK, 1 record affected.
aql> select * from test.demo
+-----+-------+
| foo | bar   |
+-----+-------+
| 123 | "abc" |
+-----+-------+
1 row in set (0.147 secs)
OK
Enter fullscreen mode Exit fullscreen mode

And that is it! we have a 2 nodes cluster running and accessible by other docker containers running on that machine.


Top comments (0)