From 63a70253e7010793cfc32e03b42d192998b162d1 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 00:11:52 +0800 Subject: [PATCH 01/18] Add files via upload --- snap/BUILD.md | 30 ++++++++++++ snap/HOWTO.md | 129 ++++++++++++++++++++++++------------------------- snap/README.md | 49 +++++++++---------- 3 files changed, 118 insertions(+), 90 deletions(-) create mode 100644 snap/BUILD.md diff --git a/snap/BUILD.md b/snap/BUILD.md new file mode 100644 index 0000000..694b0af --- /dev/null +++ b/snap/BUILD.md @@ -0,0 +1,30 @@ +# Building snaps + +## Prerequisites + +CouchDB requires Ubuntu 16.04. If building on 18.04, then LXD might be useful. + +1. `lxc launch ubuntu:16.04 couchdb-pkg` +1. `lxc exec couchdb-pkg bash` +1. `sudo apt update` +1. `sudo apt install snapd snapcraft` + +1. `git clone https://github.com/couchdb/couchdb-pkg.git` +1. `cd couchdb-pkg` + +## How to do it + +1. Edit `snap/snapcraft.yaml` to point to the correct tag (e.g. `2.2.0`) +1. `snapcraft` + +## Instalation + +You may need to pull the LXD file to the host system. + + $ lxc file pull couchdb-pkg/root/couchdb-pkg/couchdb_2.2.0_amd64.snap /tmp/couchdb_2.2.0_amd64.snap + +The self crafted snap will need to be installed in devmode + + $ sudo snap install /tmp/couchdb_2.2.0_amd64.snap --devmode + + diff --git a/snap/HOWTO.md b/snap/HOWTO.md index 21124a5..4095a40 100644 --- a/snap/HOWTO.md +++ b/snap/HOWTO.md @@ -1,109 +1,108 @@ # HOW TO install a cluster using snap -# Create three machines +## Create three machines -In the instruction below, we are going to set up a three -- the miniumn number needed to gain performace improvement -- Couch cluster database. In this potted example we will be using LXD. +In the instruction below, we are going to set up a three clusters DB (Three is the miniumn number needed to improve performance) and a single machine for making backups. In this potted example we will be using LXD. -We launch a new container and install couchdb on one machine +We launch a (single) new container, install couchdb via snap from the store and enable interfaces. -1. localhost> `lxc launch ubuntu:18.04 couchdb-c1` -1. localhost> `lxc exec couchdb-c1 bash` -1. couchdb-c1> `apt update` -1. couchdb-c1> `snap install couchdb` -1. couchdb-c1> `logout` + 1. localhost> `lxc launch ubuntu:18.04 couchdb-c1` + 1. localhost> `lxc exec couchdb-c1 bash` + 1. couchdb-c1> `apt update` + 1. couchdb-c1> `snap install couchdb` + 1. couchdb-c1> `snap connect couchdb:mount-observe` + 1. couchdb-c1> `snap connect couchdb:process-control` + 1. couchdb-c1> `logout` -Here we use LXD copy function to speed up the test +Back on localhost, we can then use LXD copy function to speed up the installation ``` -lxc copy couchdb-c1 couchdb-c2 -lxc copy couchdb-c1 couchdb-c3 -lxc copy couchdb-c1 cdb-backup -lxc start couchdb-c2 -lxc start couchdb-c3 -lxc start cdb-backup + $ lxc copy couchdb-c1 couchdb-c2 + $ lxc copy couchdb-c1 couchdb-c3 + $ lxc copy couchdb-c1 cdb-backup + $ lxc start couchdb-c2 + $ lxc start couchdb-c3 + $ lxc start cdb-backup ``` - -# Configure CouchDB (using the snap tool) +## Configure CouchDB (using the snap tool) We are going to need the IP addresses. You can find them here. -``` -lxc list -``` -Now lets use the snap configuration tool to set the configuration files. -``` -lxc exec couchdb-c1 snap set couchdb name=couchdb@10.210.199.199 setcookie=monster admin=password bind-address=0.0.0.0 -lxc exec couchdb-c2 snap set couchdb name=couchdb@10.210.199.254 setcookie=monster admin=password bind-address=0.0.0.0 -lxc exec couchdb-c3 snap set couchdb name=couchdb@10.210.199.24 setcookie=monster admin=password bind-address=0.0.0.0 -``` -The backup machine we will leave as a single instance and no sharding. + `$ lxc list to find out IP addresses` + +Now, again from local host, and using lxc exec commond, we will use the snap configuration tool to set the various configuration files. ``` -lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=password bind-address=0.0.0.0 n=1 q=1 + $ lxc exec couchdb-c1 snap set couchdb name=couchdb@10.210.199.199 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 + $ lxc exec couchdb-c2 snap set couchdb name=couchdb@10.210.199.254 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 + $ lxc exec couchdb-c3 snap set couchdb name=couchdb@10.210.199.24 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 ``` +The backup machine we will leave as a single instance. + + $ `lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 n=1 q=1` -The snap must be restarted for the new configurations to take affect. +Each snap must be restarted for the new configurations to take affect. ``` -lxc exec couchdb-c1 snap restart couchdb -lxc exec couchdb-c2 snap restart couchdb -lxc exec couchdb-c3 snap restart couchdb -lxc exec cdb-backup snap restart couchdb + $ lxc exec couchdb-c1 snap restart couchdb + $ lxc exec couchdb-c2 snap restart couchdb + $ lxc exec couchdb-c3 snap restart couchdb + $ lxc exec cdb-backup snap restart couchdb ``` The configuration files are stored here. ``` -lxc exec cdb-backup cat /var/snap/couchdb/current/etc/vm.args -lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/* + $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/vm.args + $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/* ``` Any changes to couchdb from the http configutation tool are made here ``` -lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/local.ini + $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/local.ini ``` - -# Configure CouchDB Cluster (using the http interface) +## Configure CouchDB Cluster (using the http interface) Now we set up the cluster via the http front-end. This only needs to be run once on the first machine. The last command syncs with the other nodes and creates the standard databases. ``` -curl -X POST -H "Content-Type: application/json" http://admin:password@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.254", "port": "5984", "username": "admin", "password":"password"}' -curl -X POST -H "Content-Type: application/json" http://admin:password@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.24", "port": "5984", "username": "admin", "password":"password"}' -curl -X POST -H "Content-Type: application/json" http://admin:password@10.210.199.199:5984/_cluster_setup -d '{"action": "finish_cluster"}' + $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.254", "port": "5984", "username": "admin", "password":"Be1stDB"}' + $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.24", "port": "5984", "username": "admin", "password":"Be1stDB"}' + $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "finish_cluster"}' ``` Now we have a functioning three node cluster. -# An Example Database +## An Example Database Let's create an example database ... ``` -curl -X PUT http://admin:password@10.210.199.199:5984/example -curl -X PUT http://admin:password@10.210.199.199:5984/example/aaa -d '{"test":1}' -H "Content-Type: application/json" -curl -X PUT http://admin:password@10.210.199.199:5984/example/aab -d '{"test":2}' -H "Content-Type: application/json" -curl -X PUT http://admin:password@10.210.199.199:5984/example/aac -d '{"test":3}' -H "Content-Type: application/json" + $ curl -X PUT http://admin:password@10.210.199.199:5984/example + $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aaa -d '{"test":1}' -H "Content-Type: application/json" + $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aab -d '{"test":2}' -H "Content-Type: application/json" + $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aac -d '{"test":3}' -H "Content-Type: application/json" ``` ... And see that it is sync'd accross the three nodes. ``` -curl -X GET http://admin:password@10.210.199.199:5984/example/_all_docs -curl -X GET http://admin:password@10.210.199.254:5984/example/_all_docs -curl -X GET http://admin:password@10.210.199.24:5984/example/_all_docs + $ curl -X GET http://admin:password@10.210.199.199:5984/example/_all_docs + $ curl -X GET http://admin:password@10.210.199.254:5984/example/_all_docs + $ curl -X GET http://admin:password@10.210.199.24:5984/example/_all_docs ``` -# Backing Up CouchDB +## Backing Up CouchDB -Our back up server is on 10.210.199.242. We will manually replicate this from one (anyone) of the nodes. +Our back up server is on 10.210.199.242. We will manually replicate this from one (can be any one) of the nodes. ``` -curl -X POST http://admin:password@10.210.199.242:5984/_replicate -d '{"source":"http://10.210.199.199:5984/example", "target":"example", "continuous":false,"create_target":true}' -H "Content-Type: application/json" -curl -X GET http://admin:password@10.210.199.242:5984/example/_all_docs + $ curl -X POST http://admin:Be1stDB@10.210.199.242:5984/_replicate -d '{"source":"http://10.210.199.199:5984/example", "target":"example", "continuous":false,"create_target":true}' -H "Content-Type: application/json" + $ curl -X GET http://admin:Be1stDB@10.210.199.242:5984/example/_all_docs ``` The data store for the clusters nodes are sharded -``` -lxc exec couchdb-c1 ls /var/snap/couchdb/common/2.x/data/shards/ -``` + + `$ lxc exec couchdb-c1 ls /var/snap/couchdb/common/data/shards/` The backup database is a single file. -``` -lxc exec cdb-backup ls /var/snap/couchdb/common/2.x/data/shards/00000000-ffffffff/ -``` -# Monitoring CouchDB + `$ lxc exec cdb-backup ls /var/snap/couchdb/common/data/shards/00000000-ffffffff/` + +## Monitoring CouchDB + +The logs, by default, are captured by journald. First connect to the machine. + `$ lxc exec couchdb-c1 bash` +And show logs as usual. couchdb is likely prefixed with 'snap' + `$ journalctl -u snap.couchdb -f` + + + -The logs, by default, are captured by journald -``` -lxc exec couchdb-c1 bash -journalctl -u snap.couchdb -f -``` diff --git a/snap/README.md b/snap/README.md index 65ce54e..e302b69 100644 --- a/snap/README.md +++ b/snap/README.md @@ -1,33 +1,23 @@ -# Building snaps - -## Prerequisites - -CouchDB requires Ubuntu 16.04. If building on 18.04, then LXD might be useful. - -1. `lxc launch ubuntu:16.04 couchdb-pkg` -1. `lxc exec couchdb-pkg bash` -1. `sudo apt update` -1. `sudo apt install snapd snapcraft` - -1. `git clone https://github.com/couchdb/couchdb-pkg.git` -1. `cd couchdb-pkg` - -## How to do it +# Snap Instalation -1. Edit `snap/snapcraft.yaml` to point to the correct tag (e.g. `2.2.0`) -1. `snapcraft` +## Downloading from the snap store -# Snap Instalation +The snap can be installed from a file or directly from the snap store. -You may need to pull the LXD file to the host system. + $ sudo snap install couchdb + +## Enable snap permissions - $ lxc file pull couchdb-pkg/root/couchdb-pkg/couchdb_2.2.0_amd64.snap /tmp/couchdb_2.2.0_amd64.snap +The snap installation uses AppArmor to protect security. CouchDB request access to two interfaces: mount-observe, which +is used by the disk compactor to know when to initiate a cleanup; and, process-control, is used by the indexer to set +the priority of couchjs to 'nice'. These two interfaces are not required, but if they are not enabled, you will need to run the compactor manually and the couchjs can weigh a heavy load on the system. -The self crafted snap will need to be installed in devmode +To connect the interfaces type: - $ sudo snap install /tmp/couchdb_2.2.0_amd64.snap --devmode + $ sudo snap connect couchdb:mount-observe + $ sudo snap connect couchdb:process-control -# Snap Configuration +## Snap configuration There are two levels of erlang and couchdb configuration hierarchy. @@ -55,7 +45,16 @@ Snap Native Configuration changes only come into effect after a restart $ sudo snap restart couchdb -# Example Cluster +And RELAX. + +## Example Cluster + +See the [HOWTO][1] file to see an example of a three node cluster and further notes. + +## Building a Private Snap + +If you want to build your own snap file from souce see the [BUILD][2] for instructions. -See the HOWTO.md file to see an example of a three node cluster. +[1]: HOWTO.md +[2]: BUILD.md From 3cb2eef4c6b2e198c026b89090312d8492b11bf9 Mon Sep 17 00:00:00 2001 From: Joan Touzet Date: Mon, 5 Nov 2018 11:59:36 -0500 Subject: [PATCH 02/18] Update HOWTO.md Spelling and formatting improvements --- snap/HOWTO.md | 78 +++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/snap/HOWTO.md b/snap/HOWTO.md index 4095a40..979eb81 100644 --- a/snap/HOWTO.md +++ b/snap/HOWTO.md @@ -1,21 +1,23 @@ # HOW TO install a cluster using snap -## Create three machines +## Create three nodes -In the instruction below, we are going to set up a three clusters DB (Three is the miniumn number needed to improve performance) and a single machine for making backups. In this potted example we will be using LXD. +In the example below, we are going to set up a three node CouchDB cluster. (Three is the minimum number needed to support clustering features.) We'll also set up a separate, single machine for making backups. In this example we will be using LXD. We launch a (single) new container, install couchdb via snap from the store and enable interfaces. - 1. localhost> `lxc launch ubuntu:18.04 couchdb-c1` - 1. localhost> `lxc exec couchdb-c1 bash` - 1. couchdb-c1> `apt update` - 1. couchdb-c1> `snap install couchdb` - 1. couchdb-c1> `snap connect couchdb:mount-observe` - 1. couchdb-c1> `snap connect couchdb:process-control` - 1. couchdb-c1> `logout` - -Back on localhost, we can then use LXD copy function to speed up the installation +```bash + 1. localhost> lxc launch ubuntu:18.04 couchdb-c1 + 1. localhost> lxc exec couchdb-c1 bash + 1. couchdb-c1> apt update + 1. couchdb-c1> snap install couchdb + 1. couchdb-c1> snap connect couchdb:mount-observe + 1. couchdb-c1> snap connect couchdb:process-control + 1. couchdb-c1> logout ``` + +Back on localhost, we can then use the LXD copy function to speed up installation: +```bash $ lxc copy couchdb-c1 couchdb-c2 $ lxc copy couchdb-c1 couchdb-c3 $ lxc copy couchdb-c1 cdb-backup @@ -23,14 +25,16 @@ Back on localhost, we can then use LXD copy function to speed up the installatio $ lxc start couchdb-c3 $ lxc start cdb-backup ``` -## Configure CouchDB (using the snap tool) - -We are going to need the IP addresses. You can find them here. +## Configure CouchDB using the snap tool - `$ lxc list to find out IP addresses` +We are going to need the IP addresses: -Now, again from local host, and using lxc exec commond, we will use the snap configuration tool to set the various configuration files. +```bash + $ lxc list ``` + +Now, again from localhost, and using the `lxc exec` commond, we will use the snap configuration tool to set the various configuration files. +```bash $ lxc exec couchdb-c1 snap set couchdb name=couchdb@10.210.199.199 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 $ lxc exec couchdb-c2 snap set couchdb name=couchdb@10.210.199.254 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 $ lxc exec couchdb-c3 snap set couchdb name=couchdb@10.210.199.24 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 @@ -40,25 +44,25 @@ The backup machine we will leave as a single instance. $ `lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 n=1 q=1` Each snap must be restarted for the new configurations to take affect. -``` +```bash $ lxc exec couchdb-c1 snap restart couchdb $ lxc exec couchdb-c2 snap restart couchdb $ lxc exec couchdb-c3 snap restart couchdb $ lxc exec cdb-backup snap restart couchdb ``` The configuration files are stored here. -``` +```bash $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/vm.args $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/* ``` Any changes to couchdb from the http configutation tool are made here -``` +```bash $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/local.ini ``` ## Configure CouchDB Cluster (using the http interface) Now we set up the cluster via the http front-end. This only needs to be run once on the first machine. The last command syncs with the other nodes and creates the standard databases. -``` +```bash $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.254", "port": "5984", "username": "admin", "password":"Be1stDB"}' $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.24", "port": "5984", "username": "admin", "password":"Be1stDB"}' $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "finish_cluster"}' @@ -68,41 +72,37 @@ Now we have a functioning three node cluster. ## An Example Database Let's create an example database ... -``` +```bash $ curl -X PUT http://admin:password@10.210.199.199:5984/example $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aaa -d '{"test":1}' -H "Content-Type: application/json" $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aab -d '{"test":2}' -H "Content-Type: application/json" $ curl -X PUT http://admin:password@10.210.199.199:5984/example/aac -d '{"test":3}' -H "Content-Type: application/json" ``` -... And see that it is sync'd accross the three nodes. -``` +... And see that it is created on all three nodes. +```bash $ curl -X GET http://admin:password@10.210.199.199:5984/example/_all_docs $ curl -X GET http://admin:password@10.210.199.254:5984/example/_all_docs $ curl -X GET http://admin:password@10.210.199.24:5984/example/_all_docs ``` ## Backing Up CouchDB -Our back up server is on 10.210.199.242. We will manually replicate this from one (can be any one) of the nodes. -``` +Our backup server is on 10.210.199.242. We will manually replicate to this from one (can be any one) of the nodes. +```bash $ curl -X POST http://admin:Be1stDB@10.210.199.242:5984/_replicate -d '{"source":"http://10.210.199.199:5984/example", "target":"example", "continuous":false,"create_target":true}' -H "Content-Type: application/json" $ curl -X GET http://admin:Be1stDB@10.210.199.242:5984/example/_all_docs ``` -The data store for the clusters nodes are sharded - - `$ lxc exec couchdb-c1 ls /var/snap/couchdb/common/data/shards/` - -The backup database is a single file. - - `$ lxc exec cdb-backup ls /var/snap/couchdb/common/data/shards/00000000-ffffffff/` +Whereas the data store for the clusters nodes is sharded: +```bash + $ lxc exec couchdb-c1 ls /var/snap/couchdb/common/data/shards/ +``` +The backup database is a single file: +```bash + $ lxc exec cdb-backup ls /var/snap/couchdb/common/data/shards/00000000-ffffffff/ +``` ## Monitoring CouchDB -The logs, by default, are captured by journald. First connect to the machine. +The logs, by default, are captured by journald. First connect to the node in question: `$ lxc exec couchdb-c1 bash` -And show logs as usual. couchdb is likely prefixed with 'snap' +Then, show logs as usual. couchdb is likely prefixed with 'snap' `$ journalctl -u snap.couchdb -f` - - - - - From 12e4bf9cadece60d6ab4b95b075ad7c0c8d2c782 Mon Sep 17 00:00:00 2001 From: Joan Touzet Date: Mon, 5 Nov 2018 12:02:29 -0500 Subject: [PATCH 03/18] Update README.md Correct spelling mistake --- snap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/README.md b/snap/README.md index e302b69..821979d 100644 --- a/snap/README.md +++ b/snap/README.md @@ -53,7 +53,7 @@ See the [HOWTO][1] file to see an example of a three node cluster and further no ## Building a Private Snap -If you want to build your own snap file from souce see the [BUILD][2] for instructions. +If you want to build your own snap file from source see the [BUILD][2] for instructions. [1]: HOWTO.md [2]: BUILD.md From 35ac4ad17e2d7b1755569178a648b39046d58450 Mon Sep 17 00:00:00 2001 From: Joan Touzet Date: Mon, 5 Nov 2018 12:03:49 -0500 Subject: [PATCH 04/18] Update README.md More spelling errors --- snap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/README.md b/snap/README.md index 821979d..6dec37e 100644 --- a/snap/README.md +++ b/snap/README.md @@ -37,7 +37,7 @@ made at the same time. $ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0 Snap set variable can not contain underscore character, but any dashes are converted to underscore when -writing to file. Wrap double quotes around any bracets and avoid spaces. +writing to file. Wrap double quotes around any brackets or spaces. $ sudo snap set couchdb delayed-commits=true erlang="{couch_native_process,start_link,[]}" From c6f4903521b6206f0c413fb2d17a925ab8a78672 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 03:29:22 +0800 Subject: [PATCH 05/18] Typo: was /etc/default.d/local.ini should just be /etc/local.ini; added --edge to install --- snap/HOWTO.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snap/HOWTO.md b/snap/HOWTO.md index 979eb81..0c0e8bf 100644 --- a/snap/HOWTO.md +++ b/snap/HOWTO.md @@ -10,7 +10,7 @@ We launch a (single) new container, install couchdb via snap from the store and 1. localhost> lxc launch ubuntu:18.04 couchdb-c1 1. localhost> lxc exec couchdb-c1 bash 1. couchdb-c1> apt update - 1. couchdb-c1> snap install couchdb + 1. couchdb-c1> snap install couchdb --edge 1. couchdb-c1> snap connect couchdb:mount-observe 1. couchdb-c1> snap connect couchdb:process-control 1. couchdb-c1> logout @@ -57,7 +57,7 @@ The configuration files are stored here. ``` Any changes to couchdb from the http configutation tool are made here ```bash - $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.d/local.ini + $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.ini ``` ## Configure CouchDB Cluster (using the http interface) From cd61d05fde5206f163f0a6260124cbaaf676e442 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 03:31:34 +0800 Subject: [PATCH 06/18] Added --edge to installation --- snap/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snap/README.md b/snap/README.md index 6dec37e..9fd71e4 100644 --- a/snap/README.md +++ b/snap/README.md @@ -2,9 +2,9 @@ ## Downloading from the snap store -The snap can be installed from a file or directly from the snap store. +The snap can be installed from a file or directly from the snap store. It is, for the moment, list in the edge channel. - $ sudo snap install couchdb + $ sudo snap install couchdb --edge ## Enable snap permissions From ca7877765036d99e1eede84a53ec4feae7423b6f Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 04:20:26 +0800 Subject: [PATCH 07/18] Changed couchdb.ini from local.d to default.d --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 8dd7dea..1eadf03 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -58,7 +58,7 @@ parts: plugin: dump source: ./snap/ organize: - couchdb.ini: rel/couchdb/etc/local.d/couchdb.ini + couchdb.ini: rel/couchdb/etc/default.d/couchdb.ini snap_run: rel/couchdb/bin/snap_run packages: From aee12ce1d3ef2fe41537300851d9d0e25ec8ed23 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 04:22:35 +0800 Subject: [PATCH 08/18] Switched config order to standard: default.ini, default.d, local.ini, local.d --- snap/snap_run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snap_run b/snap/snap_run index 5fa783a..f41b75e 100755 --- a/snap/snap_run +++ b/snap/snap_run @@ -16,7 +16,7 @@ export HOME=$SNAP_DATA export COUCHDB_ARGS_FILE=${SNAP_DATA}/etc/vm.args -export ERL_FLAGS="-couch_ini ${SNAP}/rel/couchdb/etc/default.ini ${SNAP_DATA}/etc/local.d ${SNAP_DATA}/etc/local.ini" +export ERL_FLAGS="-couch_ini ${SNAP}/rel/couchdb/etc/default.ini ${SNAP}/rel/couchdb/etc/default.d ${SNAP_DATA}/etc/local.ini ${SNAP_DATA}/etc/local.d" mkdir -p ${SNAP_DATA}/etc From 33ea336ce115718ebc9a542d25297e0b7bfc4edb Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 04:23:35 +0800 Subject: [PATCH 09/18] couchdb.ini has been moved from local.d to default.d --- snap/snap_run | 1 - 1 file changed, 1 deletion(-) diff --git a/snap/snap_run b/snap/snap_run index f41b75e..e608086 100755 --- a/snap/snap_run +++ b/snap/snap_run @@ -26,7 +26,6 @@ fi if [ ! -d ${SNAP_DATA}/etc/local.d ]; then mkdir ${SNAP_DATA}/etc/local.d - cp ${SNAP}/rel/couchdb/etc/local.d/*.ini ${SNAP_DATA}/etc/local.d fi if [ ! -e ${SNAP_DATA}/etc/local.ini ]; then From c32bc00ea3cacefbede415fe2dc54205e29ce7bb Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Tue, 6 Nov 2018 04:40:40 +0800 Subject: [PATCH 10/18] Re-wrote configuration section to reflect standard order. --- snap/README.md | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/snap/README.md b/snap/README.md index 9fd71e4..3b239c2 100644 --- a/snap/README.md +++ b/snap/README.md @@ -19,25 +19,28 @@ To connect the interfaces type: ## Snap configuration -There are two levels of erlang and couchdb configuration hierarchy. +There are two levels of hierarchy within couchdb configuration. -The default layer is stored in /snap/couchdb/current/rel/couchdb/etc/ and is read only. -The user override layer, is stored in /var/snap/couchdb/current/etc/ and is writable. -Within this second layer, configurations are set with the local.d directory (one file -per section) or the local.ini (co-mingled). The "snap set" command works with the -former (local.d) and couchdb http configuration overwrites the latter (local.ini). -Entries in local.ini supersede those in the local.d directory. +The default layer is stored in /snap/couchdb/current/rel/couchdb/etc/ with in the +directory default.d or the file default.ini and is read only. + +The local override layer is stored in /var/snap/couchdb/current/etc/ and is writable. +Within this second layer, configurations are set local.ini (single file co-mingled sections) or +the local.d directory (one file per section). The "snap set" command works with the +latter (local.d) and couchdb http configuration overwrites the former (local.ini). +Entries in local.d supersede those in the local.ini directory. The name of the erlang process and the security cookie used is set in vm.args file. -This can be set through the snap native configuration. For example, when setting up +This should be set through the snap native configuration. For example, when setting up a cluster over several machines the convention is to set the erlang -name to couchdb@your.ip.address. Both erlang and couchdb configuration changes can be -made at the same time. +name to couchdb@your.ip.address. + +Both erlang and couchdb configuration changes can be made at the same time. $ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0 Snap set variable can not contain underscore character, but any dashes are converted to underscore when -writing to file. Wrap double quotes around any brackets or spaces. +writing to file. Wrap double quotes around any brackets or spaces. $ sudo snap set couchdb delayed-commits=true erlang="{couch_native_process,start_link,[]}" @@ -45,7 +48,13 @@ Snap Native Configuration changes only come into effect after a restart $ sudo snap restart couchdb -And RELAX. +Snap Native Configuration have only been enable for a select few variables. Generally those essential to inital +installation or items that are not white-listed for configuration over HTTP. An example of configuration over HTTP is below. + + `$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/ssl/port -d '"6984"'` + +This has the advantage of not requiring restarting the application. You can aslo edit the /var/couchdb/current/etc files +by hand. Or using a configuration management tool (puppet, chef, ansible, salt) is also common. ## Example Cluster From 1d1c4f6d58b3de5e1ea673ae74365ea79f7523a9 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Nov 2018 06:21:22 +0000 Subject: [PATCH 11/18] Added a 90-override.ini file to ensure HTTP changes go in the last file --- snap/meta/hooks/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/meta/hooks/install b/snap/meta/hooks/install index eb7a541..f8ddc16 100755 --- a/snap/meta/hooks/install +++ b/snap/meta/hooks/install @@ -4,6 +4,6 @@ mkdir -p ${SNAP_DATA}/etc/local.d cp ${SNAP}/rel/couchdb/etc/vm.args ${SNAP_DATA}/etc/vm.args -cp ${SNAP}/rel/couchdb/etc/local.d/*.ini ${SNAP_DATA}/etc/local.d +touch ${SNAP_DATA}/etc/local.d/90-override.ini From 3af3924b70b1994e5fb6de320e2180c9b08c8fff Mon Sep 17 00:00:00 2001 From: sklassen Date: Tue, 6 Nov 2018 06:23:17 +0000 Subject: [PATCH 12/18] Pared back the list of settable options to bare min --- snap/meta/hooks/configure | 99 +++++++-------------------------------- 1 file changed, 17 insertions(+), 82 deletions(-) diff --git a/snap/meta/hooks/configure b/snap/meta/hooks/configure index 8c2b1aa..4b29008 100755 --- a/snap/meta/hooks/configure +++ b/snap/meta/hooks/configure @@ -20,10 +20,11 @@ _modify_vm_args() { } _modify_ini_file() { - section=$1 - opt=`echo $2 | tr "-" "_"` - value="$3" - config_file=${LOCAL_DIR}/${section}.ini + filename=$1 + section=$2 + opt=`echo $3 | tr "-" "_"` + value="$4" + config_file=${LOCAL_DIR}/${filename}.ini if [ ! -e ${config_file} ]; then echo "[${section}]" > $config_file fi @@ -56,123 +57,57 @@ done # Special Cases -# local.d/admins.ini +# local.d/10-admins.ini passwd=$(snapctl get admin) if [ ! -z "$passwd" ]; then - _modify_ini_file admins admin $passwd - chmod 600 $SNAP_DATA/etc/local.d/admins.ini - sleep 0.125 -fi - -# local.d/ssl.ini -port=$(snapctl get ssl-port) -if [ ! -z "$port" ]; then - _modify_ini_file ssl port $port - sleep 0.125 -fi - -# local.d/httpd.ini -port=$(snapctl get httpd-port) -if [ ! -z "$port" ]; then - _modify_ini_file httpd port $port - sleep 0.125 -fi - -# local.d/chttpd.ini -port=$(snapctl get chttpd-port) -if [ ! -z "$port" ]; then - _modify_ini_file chttpd port $port + _modify_ini_file 10-admins admins admin $passwd + chmod 600 $SNAP_DATA/etc/local.d/10-admins.ini sleep 0.125 fi # Generic Cases -# local.d/chttpd.ini -CHTTPD_OPTIONS="port bind-address require-valid-user" +# local.d/20-chttpd.ini +CHTTPD_OPTIONS="port bind-address" for key in $CHTTPD_OPTIONS do val=$(snapctl get $key) if [ ! -z "$val" ]; then - _modify_ini_file chttpd $key $val + _modify_ini_file 20-chttpd chttpd $key $val sleep 0.125 fi done -# local.d/cluster.ini +# local.d/30-cluster.ini CLUSTER_OPTIONS="n q" for key in $CLUSTER_OPTIONS do val=$(snapctl get $key) if [ ! -z "$val" ]; then - _modify_ini_file cluster $key $val - sleep 0.125 - fi -done - -# local.d/compaction_daemon.ini -COMPACTION_DAEMON_OPTIONS="check-interval" -for key in $COMPACTION_DAEMON_OPTIONS -do - val=$(snapctl get $key) - if [ ! -z "$val" ]; then - _modify_ini_file compaction_daemon $key $val - sleep 0.125 - fi -done - -# local.d/couchdb.ini -COUCHDB_OPTIONS="database-dir view-index-dir delayed-commits" -for key in $COUCHDB_OPTIONS -do - val=$(snapctl get $key) - if [ ! -z "$val" ]; then - _modify_ini_file couchdb $key $val + _modify_ini_file 30-cluster cluster $key $val sleep 0.125 fi done -# local.d/log.ini +# local.d/40-log.ini LOG_OPTIONS="writer file level" for key in $LOG_OPTIONS do val=$(snapctl get $key) if [ ! -z "$val" ]; then - _modify_ini_file log $key $val + _modify_ini_file 40-log log $key $val sleep 0.125 fi done -# local.d/native_query_servers.ini +# local.d/50-native_query_servers.ini NATIVE_QUERY_SERVERS_OPTIONS="query erlang" for key in $NATIVE_QUERY_SERVERS_OPTIONS do val=$(snapctl get $key) if [ ! -z "$val" ]; then - _modify_ini_file native_query_servers $key $val + _modify_ini_file 50-native_query_servers native_query_servers $key $val sleep 0.125 fi done -# local.d/couch_peruser.ini -COUCH_PERUSER_OPTIONS="database-prefix delete-dbs enable" -for key in $COUCH_PERUSER_OPTIONS -do - val=$(snapctl get $key) - if [ ! -z "$val" ]; then - _modify_ini_file couch_peruser $key $val - sleep 0.125 - fi -done - -# local.d/uuids.ini -UUIDS_OPTIONS="algorithm max-count" -for key in $UUIDS_OPTIONS -do - val=$(snapctl get $key) - if [ ! -z "$val" ]; then - _modify_ini_file uuids $key $val - sleep 0.125 - fi -done - - From 36cd4ba3e012b3bb31b8f0f01e7bbea05b9a2033 Mon Sep 17 00:00:00 2001 From: sklassen Date: Tue, 6 Nov 2018 06:24:05 +0000 Subject: [PATCH 13/18] Rewrote README and HOWTO to reflect new order of configuration --- snap/HOWTO.md | 17 ++++++++--------- snap/README.md | 50 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/snap/HOWTO.md b/snap/HOWTO.md index 0c0e8bf..d155c79 100644 --- a/snap/HOWTO.md +++ b/snap/HOWTO.md @@ -5,7 +5,6 @@ In the example below, we are going to set up a three node CouchDB cluster. (Three is the minimum number needed to support clustering features.) We'll also set up a separate, single machine for making backups. In this example we will be using LXD. We launch a (single) new container, install couchdb via snap from the store and enable interfaces. - ```bash 1. localhost> lxc launch ubuntu:18.04 couchdb-c1 1. localhost> lxc exec couchdb-c1 bash @@ -15,7 +14,6 @@ We launch a (single) new container, install couchdb via snap from the store and 1. couchdb-c1> snap connect couchdb:process-control 1. couchdb-c1> logout ``` - Back on localhost, we can then use the LXD copy function to speed up installation: ```bash $ lxc copy couchdb-c1 couchdb-c2 @@ -28,21 +26,20 @@ Back on localhost, we can then use the LXD copy function to speed up installatio ## Configure CouchDB using the snap tool We are going to need the IP addresses: - ```bash $ lxc list ``` - -Now, again from localhost, and using the `lxc exec` commond, we will use the snap configuration tool to set the various configuration files. +Now, again from localhost, and using the `lxc exec` commond, we will use the snap configuration tool to set the +various configuration files. ```bash $ lxc exec couchdb-c1 snap set couchdb name=couchdb@10.210.199.199 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 $ lxc exec couchdb-c2 snap set couchdb name=couchdb@10.210.199.254 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 $ lxc exec couchdb-c3 snap set couchdb name=couchdb@10.210.199.24 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 ``` The backup machine we will leave as a single instance. - - $ `lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 n=1 q=1` - +```bash + $ lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 n=1 q=1 +``` Each snap must be restarted for the new configurations to take affect. ```bash $ lxc exec couchdb-c1 snap restart couchdb @@ -59,9 +56,11 @@ Any changes to couchdb from the http configutation tool are made here ```bash $ lxc exec cdb-backup cat /var/snap/couchdb/current/etc/local.ini ``` + ## Configure CouchDB Cluster (using the http interface) -Now we set up the cluster via the http front-end. This only needs to be run once on the first machine. The last command syncs with the other nodes and creates the standard databases. +Now we set up the cluster via the http front-end. This only needs to be run once on the first machine. The last command +syncs with the other nodes and creates the standard databases. ```bash $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.254", "port": "5984", "username": "admin", "password":"Be1stDB"}' $ curl -X POST -H "Content-Type: application/json" http://admin:Be1stDB@10.210.199.199:5984/_cluster_setup -d '{"action": "add_node", "host":"10.210.199.24", "port": "5984", "username": "admin", "password":"Be1stDB"}' diff --git a/snap/README.md b/snap/README.md index 3b239c2..9240ccd 100644 --- a/snap/README.md +++ b/snap/README.md @@ -4,31 +4,34 @@ The snap can be installed from a file or directly from the snap store. It is, for the moment, list in the edge channel. - $ sudo snap install couchdb --edge + `$ sudo snap install couchdb --edge` ## Enable snap permissions -The snap installation uses AppArmor to protect security. CouchDB request access to two interfaces: mount-observe, which -is used by the disk compactor to know when to initiate a cleanup; and, process-control, is used by the indexer to set -the priority of couchjs to 'nice'. These two interfaces are not required, but if they are not enabled, you will need to run the compactor manually and the couchjs can weigh a heavy load on the system. +The snap installation uses AppArmor to protect your system. CouchDB request access to two interfaces: mount-observe, which +is used by the disk compactor to know when to initiate a cleanup; and, process-control, which is used by the indexer to set +the priority of couchjs to 'nice'. These two interfaces are not required, but if they are not enabled, you will need to run +the compactor manually and the couchjs may weigh a heavy load on the system. To connect the interfaces type: - $ sudo snap connect couchdb:mount-observe - $ sudo snap connect couchdb:process-control + `$ sudo snap connect couchdb:mount-observe` + `$ sudo snap connect couchdb:process-control` ## Snap configuration There are two levels of hierarchy within couchdb configuration. -The default layer is stored in /snap/couchdb/current/rel/couchdb/etc/ with in the -directory default.d or the file default.ini and is read only. +The default layer is stored in /snap/couchdb/current/rel/couchdb/etc/ and the default.ini is +referred to before the default.d directory. In the snap installation this is mounted read-only. -The local override layer is stored in /var/snap/couchdb/current/etc/ and is writable. +The local layer is stored in /var/snap/couchdb/current/etc/ on the writable /var mount. Within this second layer, configurations are set local.ini (single file co-mingled sections) or -the local.d directory (one file per section). The "snap set" command works with the -latter (local.d) and couchdb http configuration overwrites the former (local.ini). -Entries in local.d supersede those in the local.ini directory. +the local.d directory (one file per section). Configuration management tools (like puppet, chef, +ansible, salt) often use the former (local.ini). The "snap set" command works within the +latter (local.d). Entries in local.d supersede those in the local.ini directory. + +Changes made via the http configuration will write into local.d/90-override.ini. The name of the erlang process and the security cookie used is set in vm.args file. This should be set through the snap native configuration. For example, when setting up @@ -37,24 +40,31 @@ name to couchdb@your.ip.address. Both erlang and couchdb configuration changes can be made at the same time. - $ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0 + `$ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0` Snap set variable can not contain underscore character, but any dashes are converted to underscore when writing to file. Wrap double quotes around any brackets or spaces. - $ sudo snap set couchdb delayed-commits=true erlang="{couch_native_process,start_link,[]}" + `$ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}"` Snap Native Configuration changes only come into effect after a restart - $ sudo snap restart couchdb + `$ sudo snap restart couchdb` + +Snap Native Configuration has only been enabled for a few options essential to inital installation or items +that are not white-listed for configuration over HTTP. Other options that can be set via snap are: CHTTPD's "port"; +Cluster options: "n", "q"; the log options "writer","file","level". And the Native Query Servers +Options "query" and "erlang". -Snap Native Configuration have only been enable for a select few variables. Generally those essential to inital -installation or items that are not white-listed for configuration over HTTP. An example of configuration over HTTP is below. +Other options can be set via configuration over HTTP, as below. - `$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/ssl/port -d '"6984"'` + `$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"'` -This has the advantage of not requiring restarting the application. You can aslo edit the /var/couchdb/current/etc files -by hand. Or using a configuration management tool (puppet, chef, ansible, salt) is also common. +Which has the advantage of not requiring restarting the application. + +For anything not covered by snap set or the configuration over http, you can edit +the /var/snap/couchdb/current/etc files by hand. + ## Example Cluster From 4b9b5e72f23fd06ea0713e62b73e70daac0f3fcd Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Wed, 7 Nov 2018 14:47:35 +0800 Subject: [PATCH 14/18] md formating changes --- snap/README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/snap/README.md b/snap/README.md index 9240ccd..ce770e6 100644 --- a/snap/README.md +++ b/snap/README.md @@ -2,21 +2,22 @@ ## Downloading from the snap store -The snap can be installed from a file or directly from the snap store. It is, for the moment, list in the edge channel. +The snap can be installed from a file or directly from the snap store. It is, for the moment, listed in the edge channel. - `$ sudo snap install couchdb --edge` + ```$ sudo snap install couchdb --edge``` ## Enable snap permissions -The snap installation uses AppArmor to protect your system. CouchDB request access to two interfaces: mount-observe, which -is used by the disk compactor to know when to initiate a cleanup; and, process-control, which is used by the indexer to set -the priority of couchjs to 'nice'. These two interfaces are not required, but if they are not enabled, you will need to run -the compactor manually and the couchjs may weigh a heavy load on the system. +The snap installation uses AppArmor to protect your system. CouchDB requests access to two interfaces: mount-observe, which +is used by the disk compactor to know when to initiate a cleanup; and process-control, which is used by the indexer to set +the priority of couchjs to 'nice'. These two interfaces, while not required, are useful. If they are not enabled, CouchDB will +still run, but you will need to run the compactor manually and couchjs may put a heavy load on the system when indexing. To connect the interfaces type: - - `$ sudo snap connect couchdb:mount-observe` - `$ sudo snap connect couchdb:process-control` + ``` + $ sudo snap connect couchdb:mount-observe + $ sudo snap connect couchdb:process-control + ``` ## Snap configuration @@ -40,16 +41,16 @@ name to couchdb@your.ip.address. Both erlang and couchdb configuration changes can be made at the same time. - `$ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0` + ```$ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0``` Snap set variable can not contain underscore character, but any dashes are converted to underscore when writing to file. Wrap double quotes around any brackets or spaces. - `$ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}"` + ```$ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}"``` Snap Native Configuration changes only come into effect after a restart - `$ sudo snap restart couchdb` + ```$ sudo snap restart couchdb``` Snap Native Configuration has only been enabled for a few options essential to inital installation or items that are not white-listed for configuration over HTTP. Other options that can be set via snap are: CHTTPD's "port"; @@ -58,7 +59,7 @@ Options "query" and "erlang". Other options can be set via configuration over HTTP, as below. - `$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"'` + ```$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"'``` Which has the advantage of not requiring restarting the application. From 327eb2523374a79eadcd7d12d3e8ca1bc7ab0398 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Wed, 7 Nov 2018 14:49:12 +0800 Subject: [PATCH 15/18] Corrected white spacing --- snap/README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/snap/README.md b/snap/README.md index ce770e6..bb3a55c 100644 --- a/snap/README.md +++ b/snap/README.md @@ -3,9 +3,9 @@ ## Downloading from the snap store The snap can be installed from a file or directly from the snap store. It is, for the moment, listed in the edge channel. - - ```$ sudo snap install couchdb --edge``` - + ``` + $ sudo snap install couchdb --edge + ``` ## Enable snap permissions The snap installation uses AppArmor to protect your system. CouchDB requests access to two interfaces: mount-observe, which @@ -18,7 +18,6 @@ To connect the interfaces type: $ sudo snap connect couchdb:mount-observe $ sudo snap connect couchdb:process-control ``` - ## Snap configuration There are two levels of hierarchy within couchdb configuration. @@ -40,33 +39,33 @@ a cluster over several machines the convention is to set the erlang name to couchdb@your.ip.address. Both erlang and couchdb configuration changes can be made at the same time. - - ```$ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0``` + ``` + $ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0 + ``` Snap set variable can not contain underscore character, but any dashes are converted to underscore when writing to file. Wrap double quotes around any brackets or spaces. - - ```$ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}"``` - + ``` + $ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}" + ``` Snap Native Configuration changes only come into effect after a restart - - ```$ sudo snap restart couchdb``` - + ``` + $ sudo snap restart couchdb + ``` Snap Native Configuration has only been enabled for a few options essential to inital installation or items that are not white-listed for configuration over HTTP. Other options that can be set via snap are: CHTTPD's "port"; Cluster options: "n", "q"; the log options "writer","file","level". And the Native Query Servers Options "query" and "erlang". Other options can be set via configuration over HTTP, as below. - - ```$ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"'``` - + ``` + $ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"' + ``` Which has the advantage of not requiring restarting the application. For anything not covered by snap set or the configuration over http, you can edit the /var/snap/couchdb/current/etc files by hand. - ## Example Cluster See the [HOWTO][1] file to see an example of a three node cluster and further notes. From 618f8c144e16236992916a67f1adb70595d01b41 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Wed, 7 Nov 2018 14:51:24 +0800 Subject: [PATCH 16/18] white spacing --- snap/README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/snap/README.md b/snap/README.md index bb3a55c..9f32fb4 100644 --- a/snap/README.md +++ b/snap/README.md @@ -3,9 +3,10 @@ ## Downloading from the snap store The snap can be installed from a file or directly from the snap store. It is, for the moment, listed in the edge channel. - ``` + +``` $ sudo snap install couchdb --edge - ``` +``` ## Enable snap permissions The snap installation uses AppArmor to protect your system. CouchDB requests access to two interfaces: mount-observe, which @@ -39,28 +40,32 @@ a cluster over several machines the convention is to set the erlang name to couchdb@your.ip.address. Both erlang and couchdb configuration changes can be made at the same time. - ``` + +``` $ sudo snap set couchdb name=couchdb@216.3.128.12 setcookie=cutter admin=Be1stDB bind-address=0.0.0.0 - ``` +``` Snap set variable can not contain underscore character, but any dashes are converted to underscore when writing to file. Wrap double quotes around any brackets or spaces. - ``` + +``` $ sudo snap set couchdb erlang="{couch_native_process,start_link,[]}" - ``` +``` Snap Native Configuration changes only come into effect after a restart - ``` + +``` $ sudo snap restart couchdb - ``` +``` Snap Native Configuration has only been enabled for a few options essential to inital installation or items that are not white-listed for configuration over HTTP. Other options that can be set via snap are: CHTTPD's "port"; Cluster options: "n", "q"; the log options "writer","file","level". And the Native Query Servers Options "query" and "erlang". Other options can be set via configuration over HTTP, as below. - ``` + +``` $ curl -X PUT http://admin:Be1stDB@216.3.128.12:5984/_node/_local/_config/couchdb/delayed-commits -d '"true"' - ``` +``` Which has the advantage of not requiring restarting the application. For anything not covered by snap set or the configuration over http, you can edit From c1393c127b7ad51f24d6c6f8ca465f76ccaae593 Mon Sep 17 00:00:00 2001 From: Simon Klassen <6997477+sklassen@users.noreply.github.com> Date: Thu, 8 Nov 2018 01:42:45 +0800 Subject: [PATCH 17/18] Emphasized the q=1 parameter --- snap/HOWTO.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snap/HOWTO.md b/snap/HOWTO.md index d155c79..62a9831 100644 --- a/snap/HOWTO.md +++ b/snap/HOWTO.md @@ -36,7 +36,7 @@ various configuration files. $ lxc exec couchdb-c2 snap set couchdb name=couchdb@10.210.199.254 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 $ lxc exec couchdb-c3 snap set couchdb name=couchdb@10.210.199.24 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 ``` -The backup machine we will leave as a single instance. +The backup machine we will configure as a single instance (n=1) and a single shard (q=1). ```bash $ lxc exec cdb-backup snap set couchdb name=couchdb@127.0.0.1 setcookie=monster admin=Be1stDB bind-address=0.0.0.0 n=1 q=1 ``` @@ -94,9 +94,9 @@ Whereas the data store for the clusters nodes is sharded: ```bash $ lxc exec couchdb-c1 ls /var/snap/couchdb/common/data/shards/ ``` -The backup database is a single file: +The backup database is a single directory: ```bash - $ lxc exec cdb-backup ls /var/snap/couchdb/common/data/shards/00000000-ffffffff/ + $ lxc exec cdb-backup ls /var/snap/couchdb/common/data/shards/ ``` ## Monitoring CouchDB From dd32cf0d80ba02635b01ac48c9a3c27389893073 Mon Sep 17 00:00:00 2001 From: Simon Klassen Date: Wed, 7 Nov 2018 17:51:35 +0000 Subject: [PATCH 18/18] On fresh installation, copy the local.ini from the rel directory --- snap/meta/hooks/install | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snap/meta/hooks/install b/snap/meta/hooks/install index f8ddc16..28a5f64 100755 --- a/snap/meta/hooks/install +++ b/snap/meta/hooks/install @@ -2,7 +2,13 @@ mkdir -p ${SNAP_DATA}/etc/local.d -cp ${SNAP}/rel/couchdb/etc/vm.args ${SNAP_DATA}/etc/vm.args +if [ ! -f ${SNAP_DATA}/etc/vm.args ]; then + cp ${SNAP}/rel/couchdb/etc/vm.args ${SNAP_DATA}/etc/vm.args +fi + +if [ ! -f ${SNAP_DATA}/etc/local.ini ]; then + cp ${SNAP}/rel/couchdb/etc/local.ini ${SNAP_DATA}/etc/local.ini +fi touch ${SNAP_DATA}/etc/local.d/90-override.ini