An auto-installer of cockroachDB binary and nodes as SystemD services in linux systems.
Note
If upgrading from v < 2.0
make sure you
log in to the SQL
console
cockroach sql --certs-dir=/etc/cockroachdb/certs
...and run the below command as documented here:
SET CLUSTER SETTING version = '1.1';
First download the cockroachdb tarball from https://www.cockroachlabs.com
Then run the following commands.
git clone https://github.com/tomogoma/cockroach-installer
cd cockroach-installer
Options can be found by running:
./systemdInstaller --help
There are two approaches for setting up a cluster:
Assume your username in the linux server is bart
and the binary has been saved at ~/Downloads/cockroach.linux-amd64.tgz
(change these values appropriately)
-
Install cockroachDB and the unit file for the root node:
sudo ./systemdInstaller.sh -u bart ~/Downloads/cockroach-v2.0.2.linux-amd64.tgz sudo systemctl start cockroach.root.service
You now have a fully functional CockroachDB listening at
localhost:26257
-
Install a unit file for the second node:
sudo ./systemdInstaller.sh --name node2 --store /var/data/cockroach/node2 --port 26258 --http-port 7006 --join localhost:26257
- We specify the
name
of the node so that the unit file has a separate namespace fromroot
. - We instruct
cockroach
to listen on a differentport
,http-port
and to use a differentstore
dir since two nodes are sharing a server (we would use defaults if we were on different servers). - We use the
join
config to make cockroach join theroot
node's cluster.
Start the second node:
sudo systemctl start cockroach.node2.service
notice
node2
incockroach.node2.service
similar to what we passed under--name
config before. - We specify the
-
Repeat the step above for subsequent nodes using different values for
name
,store
,port
andhttp-port
.
Assume the root node is to be hosted at my.server.url
,
your username in the linux server is bart
and the CockroachDB binary is saved at ~/Downloads/cockroach.linux-amd64.tgz
(change these values appropriately):
-
Install the root node at
my.server.url
-
Log in to
my.server.url
-
Install cockroach db and create a SystemD service for the root node using this command:
sudo ./systemdInstaller.sh --user bart --host my.server.url ~/Downloads/cockroach.linux-amd64.tgz
-
Run the following command to start the node:
sudo systemctl start cockroach.root.service
You now have a fully functional CockroachDB listening at
my.server.url:26257
-
-
Join other nodes to the cluster
-
Log in to the second server
-
Copy the certificates dir in my.server.url into server2 (This step is still manual unfortunately)
sudo su mkdir -p /etc/cockroachdb cd /etc/cockroachdb sftp [email protected] get -R /etc/cockroachdb/certs exit # from sftp exit # from sudo
-
Install CockroachDB and a Systemd service for the node by running this:
sudo ./systemdInstaller.sh --name node2 --join my.server.url:26257 ~/Downloads/cockroach.linux-amd64.tgz
Note the following:
--name node2
- this forms the unit namecockroach.node2.service
--join my.server.url:26257
- letting cockroach know which cluster to join. All othercockroach start
configurations can be appended in a similar manner. -
Start the node by running this:
sudo systemctl start cockroach.node2.service
-
-
Repeat the step above for every subsequent node.
The script below stops all nodes in the current server, uninstalls all cockroach SystemD unit files and uninstalls the cockroach binary.
store
directories and certs
directories are left untouched.
These have to be deleted manually.
sudo ./systemdUninstall