(coming soon)
the automatic detection of devices and services offered by these devices on a computer network
{
"service": {
"checks": [
{
"http": "http://solr-210.soma.plos.org:8983/solr",
"interval": "10s",
"timeout": "5s"
}
],
"name": "solr",
"port": 8983,
"tags": [
"dev",
"cluster=solr-mini"
]
}
}
solr-advertise:
file.serialize:
- name: /etc/consul.d/solr.json
- formatter: json
- dataset:
service:
name: solr
port: {{ solr_port }}
checks:
- http: 'http://{{ hostname }}:8983/solr'
interval: 10s
timeout: 5s
tags:
- {{ environment }}
- cluster={{ cluster }}
chaumes@ops-admin-201:~$ consul catalog nodes -service=solr
Node ID Address DC
solr-110 b53e5afd 10.5.3.64 soma
solr-111 5a1dc5a2 10.5.3.68 soma
solr-120 e1058eb7 10.5.2.2 soma
solr-121 b17a2d57 10.5.2.3 soma
solr-122 34074129 10.5.2.4 soma
solr-123 6944d721 10.5.2.5 soma
solr-124 88245dec 10.5.2.6 soma
solr-125 4dca2a93 10.5.2.7 soma
solr-126 9584d894 10.5.2.8 soma
solr-127 de640708 10.5.2.9 soma
solr-210 b94b9aa0 10.5.4.88 soma
solr-211 bbb9c4c9 10.5.4.89 soma
solr-220 2818b2af 10.5.4.2 soma
solr-221 42359f86 10.5.4.3 soma
solr-222 51322276 10.5.4.4 soma
solr-223 3bbabeb3 10.5.4.5 soma
solr-224 9351dc84 10.5.4.6 soma
solr-225 028c8e97 10.5.4.7 soma
solr-226 a74090ac 10.5.4.8 soma
solr-227 e91b0761 10.5.4.9 soma
chaumes@ops-admin-201:~$ curl -sS 'http://localhost:8500/v1/catalog/service/solr?tag=prod' | jq .
[
{
"Address": "10.5.3.64",
"CreateIndex": 6348285,
"Datacenter": "soma",
"ID": "b53e5afd-1b9d-8a3a-a012-060a2429c08d",
"ModifyIndex": 6348285,
"Node": "solr-110",
"NodeMeta": {
"consul-network-segment": ""
},
"ServiceAddress": "",
"ServiceEnableTagOverride": false,
"ServiceID": "solr",
"ServiceName": "solr",
"ServicePort": 8983,
"ServiceTags": [
"prod",
"cluster=solr-mini"
],
"TaggedAddresses": {
"lan": "10.5.3.64",
"wan": "10.5.3.64"
}
},
{ ... }
]
chaumes@ops-admin-201:~$ dig @localhost -p 8600 prod.solr.service.consul
; <<>> DiG 9.9.5-3ubuntu0.17-Ubuntu <<>> @localhost -p 8600 prod.solr.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32640
;; flags: qr aa rd; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;prod.solr.service.consul. IN A
;; ANSWER SECTION:
prod.solr.service.consul. 0 IN A 10.5.2.3
prod.solr.service.consul. 0 IN A 10.5.3.64
prod.solr.service.consul. 0 IN A 10.5.2.9
prod.solr.service.consul. 0 IN A 10.5.2.7
prod.solr.service.consul. 0 IN A 10.5.2.4
prod.solr.service.consul. 0 IN A 10.5.2.6
prod.solr.service.consul. 0 IN A 10.5.2.5
prod.solr.service.consul. 0 IN A 10.5.3.68
prod.solr.service.consul. 0 IN A 10.5.2.8
prod.solr.service.consul. 0 IN A 10.5.2.2
;; Query time: 14 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Fri Sep 21 15:47:31 PDT 2018
;; MSG SIZE rcvd: 213
chaumes@ops-admin-201:~$ cat prep.json
{
"Name": "solr-mega-dev",
"Service": {
"Service": "solr",
"Tags": ["dev", "cluster=solr-mega"],
}
}
chaumes@ops-admin-201:~$ curl -X POST -d @prep.json localhost:8500/v1/query
{"ID":"3cab98ae-529a-6f2e-04a5-a88c347c6444"}
chaumes@ops-admin-201:~$ curl -sS localhost:8500/v1/query | jq .[].ID
"3cab98ae-529a-6f2e-04a5-a88c347c6444"
chaumes@ops-admin-201:~$ curl -sS \
> 'http://localhost:8500/v1/query/3cab98ae-529a-6f2e-04a5-a88c347c6444/execute' \
> | jq .Nodes[]?.Node.Node
"solr-226"
"solr-222"
"solr-220"
"solr-221"
"solr-223"
"solr-225"
"solr-224"
"solr-227"
chaumes@ops-admin-201:~$ curl -sS \
> 'http://localhost:8500/v1/query/3cab98ae-529a-6f2e-04a5-a88c347c6444/execute' \
> | jq .Nodes[]?.Node.Address
"10.5.4.5"
"10.5.4.6"
"10.5.4.8"
"10.5.4.3"
"10.5.4.4"
"10.5.4.7"
"10.5.4.9"
"10.5.4.2"
chaumes@ops-admin-201:~$ dig @localhost -p 8600 solr-mega-dev.query.consul SRV
; <<>> DiG 9.9.5-3ubuntu0.17-Ubuntu <<>> @localhost -p 8600 solr-mega-dev.query.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22472
;; flags: qr aa rd; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 17
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;solr-mega-dev.query.consul. IN SRV
;; ANSWER SECTION:
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-220.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-221.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-224.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-226.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-227.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-223.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-222.node.soma.consul.
solr-mega-dev.query.consul. 0 IN SRV 1 1 8983 solr-225.node.soma.consul.
chaumes@ops-admin-201:~$ consul kv put foo/bar baz
Success! Data written to: foo/bar
chaumes@ops-admin-201:~$ consul kv put foo/xyz 123
Success! Data written to: foo/xyz
chaumes@ops-admin-201:~$ consul kv put bar/foo bat
Success! Data written to: bar/foo
chaumes@ops-admin-201:~$ consul kv get -recurse
bar/foo:bat
foo/bar:baz
foo/xyz:123
chaumes@ops-admin-201:~$ consul kv get bar/foo
bat
chaumes@ops-admin-201:~$ consul kv get -recurse foo
foo/bar:baz
foo/xyz:123
chaumes@ops-admin-201:~$ consul kv delete bar/foo
Success! Deleted key: bar/foo
chaumes@ops-admin-201:~$ consul kv delete -recurse foo
Success! Deleted keys with prefix: foo
chaumes@ops-admin-201:~$ consul kv get
chaumes@ops-admin-201:~$ consul kv get -recurse
chaumes@ops-admin-201:~$
chaumes@ops-admin-201:~$ curl -X PUT localhost:8500/v1/kv/foo/bar -d '{"value": "bat"}'
true
chaumes@ops-admin-201:~$ curl -sS localhost:8500/v1/kv/foo/bar | jq .
[
{
"LockIndex": 0,
"Key": "foo/bar",
"Flags": 0,
"Value": "eyJ2YWx1ZSI6ICJiYXQifQ==",
"CreateIndex": 8434456,
"ModifyIndex": 8434456
}
]
chaumes@ops-admin-201:~$ curl -sS localhost:8500/v1/kv/foo/bar | jq -r .[].Value | base64 -d
{"value": "bat"}
chaumes@ops-admin-201:~$ curl -X DELETE localhost:8500/v1/kv/foo/bar
true
chaumes@ops-admin-201:~$ curl -sS localhost:8500/v1/kv/foo/bar | jq .
chaumes@ops-admin-201:~$