Skip to content

Instantly share code, notes, and snippets.

@redgeoff
Created September 22, 2018 20:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save redgeoff/5099f46ae63acbd8da1137e2ed436a7c to your computer and use it in GitHub Desktop.
Save redgeoff/5099f46ae63acbd8da1137e2ed436a7c to your computer and use it in GitHub Desktop.
Create CouchDB Cluster
#!/bin/bash
# Usage: create-cluster.sh user password port local-port space-separated-ips
user=$1
password=$2
port=$3
localPort=$4
ips=$5
firstIp=1
for ip in $ips; do
if [ "$firstIp" == "1" ]; then
echo "First IP=$ip"
firstIp=$ip
else
echo "Registering membership for $ip"
curl -X PUT http://$user:$password@$firstIp:$localPort/_nodes/couchdb@$ip -d {}
fi
done
# Create system DBs
echo "Creating _users"
curl -X PUT http://$user:$password@$firstIp:$port/_users
echo "Creating _replicator"
curl -X PUT http://$user:$password@$firstIp:$port/_replicator
echo "Creating _global_changes"
curl -X PUT http://$user:$password@$firstIp:$port/_global_changes
@redgeoff
Copy link
Author

@digglesby
Copy link

Hey thanks for this and your article on CouchDB clusters!

I found a slight bug with this script where if you provide a password with an @ character is confuses curl, but if you use curl -X PUT --user $user:$password http://$firstIp:$localPort/_nodes/couchdb@$ip -d {} it fixes the issue.

@Chenjing-Yu
Copy link

Chenjing-Yu commented May 9, 2019

This article helped me a lot!
One more question:
Do we have any tutorial about adding another CouchDB container in the docker, mounting on another volume, and then adding it into the cluster created above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment