Module 4 - Initialize, Provision, Add Nodes, Remove Nodes, List Nodes, Failover Nodes, Recover Nodes, Manage Groups (using REST API & CLI)

  Initializing a Node with CLI: 

/opt/couchbase/bin/couchbase-cli node-init -c 35.239.237.169 \
-u Administrator -p password \
--node-init-data-path /opt/couchbase/var/lib/couchbase/data \
--node-init-index-path /opt/couchbase/var/lib/couchbase/data \
--node-init-analytics-path /opt/couchbase/var/lib/couchbase/data \
--ipv4

 Provision a Node with the CLI: 

/opt/couchbase/bin/couchbase-cli cluster-init -c 35.239.237.169 \
--cluster-username Administrator \
--cluster-password password \
--services data,index,query \
--cluster-ramsize 512 \
--cluster-index-ramsize 256

 Initializing a Node with REST API: 

curl -u Administrator:password -v -X POST \
http://35.239.237.169:8091/nodes/self/controller/settings \
-d 'path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&' \
-d 'index_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fidata&' \
-d 'cbas_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fadata&' \
-d 'eventing_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fedata&'

 Provision a Node with the REST API: 

curl -v -X POST http://35.239.237.169:8091/node/controller/setupServices \
-d 'services=kv%2Cn1ql%2Cindex'

curl -v -X POST http://35.239.237.169:8091/pools/default \
-d 'memoryQuota=256' \
-d 'indexMemoryQuota=256'

curl -u Administrator:password -v -X POST http://10.128.0.13:8091/settings/web \
-d 'password=password&username=Administrator&port=SAME'

 Add a Node and Rebalance with the CLI: 

/opt/couchbase/bin/couchbase-cli server-add -c 10.128.0.13 \
--username Administrator --password password \
--server-add 10.128.0.14 \
--server-add-username Administrator \
--server-add-password password \
--services data

/opt/couchbase/bin/couchbase-cli rebalance -c 10.128.0.13:8091 \
--username Administrator \
--password password

 Add a Node and Rebalance with the REST API: 

#Adding node 10.128.0.14 to the cluster
curl -u Administrator:password -v -X POST \
10.128.0.13:8091/controller/addNode \
-d 'hostname=10.128.0.14&user=Administrator&password=password&services=kv'

curl -u Administrator:password -v -X POST \
10.128.0.14:8091/controller/rebalance \
-d 'knownNodes=ns_1@10.128.0.13,ns_1@10.128.0.14'

 Join a Cluster with the REST API: 

#Adding node 10.128.0.14 to the cluster
curl -u Administrator:password -v -X POST \
http://10.128.0.14:8091/node/controller/doJoinCluster \
-d 'hostname=10.128.0.13&user=Administrator&password=password&services=kv'

curl -u Administrator:password -v -X POST \
10.128.0.13:8091/controller/rebalance \
-d 'knownNodes=ns_1@10.128.0.14,ns_1@10.128.0.13'

 List the Nodes with CLI: 

/opt/couchbase/bin/couchbase-cli server-list -c 10.128.0.13:8091 \
--username Administrator \
--password password

 List the Nodes with REST API: 

curl -u Administrator:password -v -X GET \
http://10.128.0.13:8091/pools/default |python -m json.tool| grep hostname
[OR]
curl -u Administrator:password -v -X GET \
http://10.128.0.13:8091/pools/default | jq '.' | grep hostname

 Remove a Node with the CLI: 

/opt/couchbase/bin/couchbase-cli rebalance -c 10.128.0.13:8091 \
--username Administrator \
--password password --server-remove 10.128.0.14:8091

 Remove a Node with the REST API: 

curl -u Administrator:password -v -X POST \http://192.168.0.100:8091/controller/rebalance \
-d 'ejectedNodes=ns_1%40192.168.0.101' \
-d 'knownNodes=ns_1%40192.168.0.100%2Cns_1%40192.168.0.101'

 Graceful Failover with the CLI: 

/opt/couchbase/bin/couchbase-cli failover -c 192.168.0.100:8091 \
--username Administrator \
--password password \
--server-failover 192.168.0.101:8091

/opt/couchbase/bin/couchbase-cli rebalance -c 192.168.0.100:8091 \
--username Administrator \
--password password \
--server-remove 192.168.0.101:8091

 Hard Failover with the REST API: 

curl -v -X POST -u Administrator:password \
http://192.168.0.100:8091/controller/failover \
-d 'otpNode=ns_1@192.168.0.101'

curl -u Administrator:password -v -X POST \
http://192.168.0.100:8091/controller/rebalance \
-d 'knownNodes=ns_1@192.168.0.100,ns_1@192.168.0.101&ejectedNodes=ns_1@192.168.0.101'

 Auto Failover with the CLI: 

Enable auto-failover,  with a 30 second auto-failover timeout

/opt/couchbase/bin/couchbase-cli setting-autofailover -c 192.168.0.100 --username Administrator \
--password password --enable-auto-failover 1 --auto-failover-timeout 30

 Disable auto failover with the CLI: 

/opt/couchbase/bin/couchbase-cli setting-autofailover -c 192.168.0.100 --username Administrator \
--password password --enable-auto-failover 0

 Auto Failover with the REST API: 

curl -u Administrator:password http://192.168.0.100:8091/settings/autoFailover

curl -i -X POST -u Administrator:password http://192.168.0.100:8091/settings/autoFailover \
-d 'enabled=true&timeout=60' \
-d 'failoverServerGroup=true&maxCount=2' \
-d 'failoverOnDataDiskIssues[enabled]=true&failoverOnDataDiskIssues[timePeriod]=60'

  Reset the counter: 

curl -X POST -i -u Administrator:password \
http://10.5.2.54:8091/settings/autoFailover/resetCount

 Recovery with the CLI: 

Full recovery

    /opt/couchbase/bin/couchbase-cli recovery -c 192.168.0.100:8091 \
    --username Administrator \
    --password password \
    --server-recovery 192.168.0.101:8091 \
    --recovery-type full

Delta recovery

    /opt/couchbase/bin/couchbase-cli recovery -c 192.168.0.100:8091 \
    --username Administrator \
    --password password \
    --server-recovery 192.168.0.101:8091 \
    --recovery-type delta

Rebalance

    /opt/couchbase/bin/couchbase-cli rebalance -c 192.168.0.100:8091 \
    --username Administrator \
    --password password

 Recovery with the REST API: 

Full recovery

curl -u Administrator:password -v -X POST \
http://192.168.0.100:8091/controller/setRecoveryType \
-d 'otpNode=ns_1@192.168.0.101' \

Delta recovery

curl -u Administrator:password -v -X POST \
http://192.168.0.100:8091/controller/setRecoveryType \
-d 'otpNode=ns_1@192.168.0.101' \

Rebalance

curl -u Administrator:password -v -X POST \
192.168.0.100:8091/controller/rebalance \
-d 'knownNodes=ns_1@192.168.0.100,ns_1@192.168.0.101'

 Manage Groups with the CLI: 

Add a new, empty group,named Group 2

/opt/couchbase/bin/couchbase-cli group-manage -c 10.128.0.4:8091 \
-u Administrator \
-p couchbase \
--create \
--group-name 'Group 2'

Delete a Group

/opt/couchbase/bin/couchbase-cli group-manage -c 10.128.0.4:8091 \
-u Administrator \
-p couchbase \
--delete \
--group-name 'Group 2'

Assign a group when adding a server

/opt/couchbase/bin/couchbase-cli server-add -c 10.128.0.4:8091 \
--username Administrator \
--password couchbase \
--server-add 192.168.0.104:8091 \
--server-add-username Administrator \
--server-add-password couchbase \
--group-name 'Group 2' \
--services data,index,query

Move a server between groups

/opt/couchbase/bin/couchbase-cli group-manage -c 10.128.0.2:8091 \
-u Administrator \
-p couchbase \
--move-servers 10.128.0.4,10.142.0.2,10.142.0.4 \
--from-group 'Group 1' \
--to-group 'Group 2'

 List files (refresh every second): 

watch -n 1 ls -lrth /opt/couchbase/var/lib/couchbase/data

 To alter index replicas(works in Couchbase version 6.5): 

ALTER INDEX `REST`.`#primary` WITH {"action": "replica_count", "num_replica": 1};
ALTER INDEX `REST-TMP`.`#primary` WITH {"action": "replica_count", "num_replica": 1};
ALTER INDEX `travel-sample`.`#primary` WITH {"action": "replica_count", "num_replica": 1};

CREATE PRIMARY INDEX `#primary` ON `REST`
CREATE PRIMARY INDEX `#primary` ON `REST-TMP`
CREATE PRIMARY INDEX `#primary` ON `travel-sample`

Note: Above are the commands used in Module 4 of the Couchbase Database Administration Course. 
 
 

DISCLAIMER

Use the content of this website at your own risk.

The purpose of sharing the content on this website is to Educate. The author/owner of the content do not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions.The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website.

This content has been shared under Educational And Non-Profit Purposes Only. No Copyright Infringement Intended, All Rights Reserved to the Actual Owner.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com

Post a Comment

Previous Post Next Post