CouchDB Clustering : Impossible to set it up - couchdb

I'm following this documentation :
http://docs.couchdb.org/en/latest/cluster/setup.html#the-cluster-setup-api
The 11.1 part: The Cluster Setup API
I have 3 ubuntu machines with CouchDB and Curl installed, with the following ips :
192.168.219.138
192.168.219.139
192.168.219.140
First step, as the doc says, i'm entering the following commands on each of the 3 machines (admin password have been set.) :
> curl -X POST -H "Content-Type: application/json"
> http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action":
> "enable_cluster", "bind_address":"0.0.0.0", "username": "admin",
> "password":"password", "node_count":"3"}'
it says this on each machines :
{"ok":true}
Second step, i go on the 192.168.219.139 (setup coordination node) and try adding the nodes, so I'm entering theses commands, just like the doc is mentionning :
curl -X POST -H "Content-Type: application/json" http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"password", "port": 15984, "node_count": "3", "remote_node": "192.168.219.138", "remote_current_user": "admin", "remote_current_password": "password" }'
curl -X POST -H "Content-Type: application/json" http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action": "add_node", "host":"192.168.219.138", "port": 5684, "username": "admin", "password":"password"}'
curl -X POST -H "Content-Type: application/json" http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"password", "port": 15984, "node_count": "3", "remote_node": "192.168.219.140", "remote_current_user": "admin", "remote_current_password": "password" }'
curl -X POST -H "Content-Type: application/json" http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action": "add_node", "host":"192.168.219.140", "port": 5684, "username": "admin", "password":"password"}'
Then, i do this command to check if my cluster is ok :
curl http://admin:password#127.0.0.1:5984/_membership
And this is the answer, all the nodes are missing :
{
"all_nodes": [
"couchdb#localhost"
],
"cluster_nodes": [
"couchdb#192.168.219.138",
"couchdb#192.168.219.140",
"couchdb#locahost"
]
}
Please notice, the doc says I'm supposed to get this :
{
"all_nodes": [
"couchdb#couch1",
"couchdb#couch2",
"couchdb#couch3"
],
"cluster_nodes": [
"couchdb#couch1",
"couchdb#couch2",
"couchdb#couch3"
]
}
I guess my cluster is not functional, could you please tell me what am I doing wrong?
Thank you .
For example, then I go to the 192.168.219.139, add a new database called 'establishments' and nothing happens on both 2 others nodes !!

Not sure if this was a typo, but under second step, you have:
curl -X POST -H "Content-Type: application/json" http://admin:password#127.0.0.1:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"password", "port": 15984, "node_count": "3", "remote_node": "192.168.219.138", "remote_current_user": "admin", "remote_current_password": "password" }'
Notice "port": 15984
But if that's not the issue, there could be a host of issues. The clustering operations happen over the erlang ports, so the different nodes will also have to speak over the EPMD port (4396) as well as a range of other ports, which you can restrict. Each node should have a configuration (e.g. in the vm.args file) with this erlang flag, -name couchdb#${node-ip-address|FQDN} as well as a cookie that the couch nodes use to speak with each other. Of course, depending on factors outside of what you shared, there could be other considerations as well.

Related

Bash script for creating multiple projects in harbor

I wanted to create multiple projects in harbor with the API. so i have 5 projects to create in the text file
projects.txt
projects: abcd
efgh
ijkl
mnop
qrst
create_projects.sh
#!/bin/bash
DIR=$( cd "$( dirname "$BASH_SOURCE[0]}" )" && pwd )
while read p
do
curl --location --request POST 'https://harbor.rl.com/api/v2.0/projects' --header 'Content-Type: application/json' --header 'X-Resource-Name-In-Location: true' --header 'Authorization: Basic jhgkyyktfkghfgfhfgh=' --data-raw '{
"project_name": $p,
"public": true,
"metadata": {
"public": "true",
"prevent_vul": "true",
"auto_scan": "true"
},
"storage_limit": -1
}'
done < "$DIR/../assets/projects.txt"
i created bash script like this. please suggest how we gonna create these five projects in the harbor repo through the script

How to store only one response of curl command [duplicate]

This question already has answers here:
Difference between single and double quotes in Bash
(7 answers)
Closed 1 year ago.
i want to store the output of curl command in a variable but not whole response only one value of that response
i have this curl command
curl -H "Authorization: Bearer $TOKEN" -X POST -H "content-type:application/json" \
-d '{
"name":"'"$ORG_NAME"'",
"displayName":"'"$ORG_DISPLAY_NAME"'",
"description":"'"$ORGANIZATION_DESCRIPTION"'",
"runtimeType":"'"$RUNTIMETYPE"'",
"analyticsRegion":"'"$ANALYTICS_REGION"'"
}' \
"https://apigee.googleapis.com/v1/organizations?parent=projects/$PROJECT_ID"
when i hit this command then it will show the response look like this
{
"name": "organizations/heloo/operations/keijfiejwfefekd",
"metadata": {
"#type": "type.googleapis.com/google.cloud.apigee.v1.OperationMetadata",
"operationType": "INSERT",
"targetResourceName": "organizations/heloo",
"state": "IN_PROGRESS"
}
}
so in the response i want to store this state value in a variable
test=$(curl -H "Authorization: Bearer $TOKEN" -X POST -H "content-type:application/json" \
-d '{
"name":"'"$ORG_NAME"'",
"displayName":"'"$ORG_DISPLAY_NAME"'",
"description":"'"$ORGANIZATION_DESCRIPTION"'",
"runtimeType":"'"$RUNTIMETYPE"'",
"analyticsRegion":"'"$ANALYTICS_REGION"'"
}' \
"https://apigee.googleapis.com/v1/organizations?parent=projects/$PROJECT_ID" | jq '.metadata.state')
it will work

How change or delete A record by PowerDNS API?

I have pdns server 4.2.3. I want to change name of A record by api. Example:
test1 A ttl 60 192.168.1.2 -> test2 A ttl 60 192.168.1.2
From the powerdns host:
To delete record:
curl -X PATCH --data '{"rrsets": [{"changetype": "DELETE", "type": "A", "name": "test1.fqdn."}]}' -H 'X-API-Key: TURBOSECRET' http://127.0.0.1:8081/api/v1/servers/localhost/zones/zonename. -s | jq .
To add record:
curl -X PATCH --data '{"rrsets": [{"changetype": "REPLACE", "type": "A", "name": "test2.fqdn.", "ttl": "60", "records": [{"content": "test2.fqdn.", "disabled": false}]}]}' -H 'X-API-Key: TURBOSECRET' http://127.0.0.1:8081/api/v1/servers/localhost/zones/zonename. -s | jq .
Please adjust accordingly TURBOSECRET, fqdn and zonename.

Using Curl with Json (Node.js)

I am having trouble getting curl and Json (Node.js) to work when I in curl omit the "[ and ]" part of the JSON-RPC request params. I am using named parameters (i.e. an object, not an array).
This works:
curl -v -i POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method":"registerPerson", "params": ["{\"username\":\"morten10\",\"password\":\"mypass\"}"], "id":1 }' \
http://localhost:3000
However, when I omit the [" and ]" from the params it doesn't work:
curl -v -i POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method":"registerPerson", "params": {\"username\":\"morten10\",\"password\":\"mypass\"}, "id":1 }' \
http://localhost:3000
and Jayson gives this error message:
TypeError: First argument must be a string or Buffer
However, according to the JSON-RPC 2.0 specification and its examples, I should be able to exclude the "[ and ]" part from params when I use named parameters, as in this example:
--> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}
<-- {"jsonrpc": "2.0", "result": 19, "id": 4}
What am I not getting?
Thanks!
I think your object needs to be a string as suggested by the error.
Try:
curl -v -i POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method":"registerPerson", "params": "{\"username\":\"morten10\",\"password\":\"mypass\"}", "id":1 }' \
http://localhost:3000

How to read headers from file using cURL?

I found this.
And I wrote this variant:
#!/bin/bash
while read line ; do
headers="$headers -H '$line'"
done < public/headers.txt
echo $headers
curl -X PUT \
$headers \
-d #'public/example.json' \
echo.httpkit.com
In headers.txt I have:
X-PAYPAL-SECURITY-USERID:123
X-PAYPAL-SECURITY-PASSWORD:123
But when I run ./public/curl.sh I am not getting the headers I am sending.
I isolated the issue with an env var:
$ x='-H some:asd'
$ curl $x echo.httpkit.com
=> header was NOT present
$ curl -H 'some:asd' echo.httpkit.com
=> header was present
$ curl -H some:asd echo.httpkit.com
=> header was present
How can I correctly insert a variable in the header section?
Let's ask shellcheck:
In yourscript line 3:
headers="$headers -H '$line'"
^-- SC2089: Quotes/backslashes will be treated literally.
Use an array.
Ok, then let's do that:
#!/bin/bash
while read line ; do
headers=("${headers[#]}" -H "$line")
done < public/headers.txt
echo "${headers[#]}"
curl -X PUT \
"${headers[#]}" \
-d #'public/example.json' \
echo.httpkit.com
Result:
{
"method": "PUT",
"uri": "/",
"path": {
"name": "/",
"query": "",
"params": {}
},
"headers": {
"host": "echo.httpkit.com",
"user-agent": "curl/7.35.0",
"accept": "*/*",
"x-paypal-security-userid": "123", // <----- Yay!!
"x-paypal-security-password": "123",
"content-length": "32",
"content-type": "application/x-www-form-urlencoded"
},
"body": "\"This is text from example.json\"",
"ip": "127.0.0.1",
"powered-by": "http://httpkit.com",
"docs": "http://httpkit.com/echo"
}
If you don't want to put the HTTP headers on a command line (perhaps for security reasons), you can still have curl read them directly from a file.
curl -H #headerfile.txt https://www.google.com/ # requires curl >=7.55.0
If your curl is older than 7.55.0:
Use the option -K/--config <config file>, and put several -H/--header <header> lines in the text file.
For more details, please see my answer in the original article:
https://stackoverflow.com/a/48762561/5201675

Resources