User Tools

Site Tools


hashicorp_consul

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hashicorp_consul [2026/11/01 11:03]
val
hashicorp_consul [2026/11/01 13:42] (current)
val [Пример с node-exporter]
Line 1: Line 1:
 ====== Hashicorp Consul ====== ====== Hashicorp Consul ======
 +
 +==== Запуск ====
 <​code>​ <​code>​
 server# docker run -d --name consul-dev -p 8500:8500 hashicorp/​consul:​2.1.0 agent -dev -client=0.0.0.0 server# docker run -d --name consul-dev -p 8500:8500 hashicorp/​consul:​2.1.0 agent -dev -client=0.0.0.0
-  ​+</​code>​ 
 +==== Добавление и мониторинг web сервисов ==== 
 +  * [[Язык программирования Python#​Доступ к каталогу по http]] 
 +<​code>​
 server$ curl --request PUT \ server$ curl --request PUT \
   --url http://​localhost:​8500/​v1/​agent/​service/​register \   --url http://​localhost:​8500/​v1/​agent/​service/​register \
   --header '​Content-Type:​ application/​json'​ \   --header '​Content-Type:​ application/​json'​ \
   --data '{   --data '{
-    "​ID":​ "​web-app-1",+    "​ID":​ "​web-app-N",
     "​Name":​ "​web-service",​     "​Name":​ "​web-service",​
-    "​Address":​ "​192.168.13.10",​ +    "​Address":​ "​192.168.X.10",​ 
-    "​Port": ​80,+    "​Port": ​8N,
     "​Check":​ {     "​Check":​ {
       "​Name":​ "Web App HTTP Check",​       "​Name":​ "Web App HTTP Check",​
-      "​HTTP":​ "​http://​192.168.13.10:80/",+      "​HTTP":​ "​http://​192.168.X.10:8N/",
       "​Interval":​ "​10s",​       "​Interval":​ "​10s",​
       "​Timeout":​ "​1s"​       "​Timeout":​ "​1s"​
     }     }
   }'   }'
-   +...
-server$ curl --request PUT http://​localhost:​8500/​v1/​agent/​service/​deregister/​web-app-1+
  
 +server$ curl -s "​http://​localhost:​8500/​v1/​health/​service/​web-service"​
 +
 +server$ curl -s "​http://​localhost:​8500/​v1/​health/​service/​web-service?​passing=1"​
 +</​code>​
 +  * [[Сервис Prometheus]]
 +<​code>​
 +server$ curl -s "​http://​localhost:​8500/​v1/​health/​service/​web-service?​passing=1"​ | \
 +jq '[{ "​targets":​ [ .[] | "​\(.Service.Address):​\(.Service.Port)"​ ], "​labels":​ { "​job":​ "​web-service"​ } }]' \
 +| tee /​etc/​prometheus/​targets.json
 +</​code>​
 +
 +==== Удаление сервиса ====
 +<​code>​
 +server$ ID=web-app-N
 +
 +server$ curl --request PUT http://​localhost:​8500/​v1/​agent/​service/​deregister/​$ID
 +</​code>​
 +==== Пример с node-exporter ====
 +
 +  * Prometheus [[Сервис Prometheus#​Service Discovery]]
 +
 +<​code>​
 server$ curl --request PUT \ server$ curl --request PUT \
   --data '{   --data '{
     "​ID":​ "​node-exporter-gate",​     "​ID":​ "​node-exporter-gate",​
     "​Name":​ "​node-exporter",​     "​Name":​ "​node-exporter",​
-    "​Address":​ "​192.168.13.1",+    "​Address":​ "​192.168.X.1",
     "​Port":​ 9100     "​Port":​ 9100
   }' \   }' \
   http://​server:​8500/​v1/​agent/​service/​register   http://​server:​8500/​v1/​agent/​service/​register
   ​   ​
-client1:~# cat register.sh+clientN:~# crontab -l 
 +</​code><​code>​ 
 +@reboot sleep 10; /​usr/​local/​bin/​register-in-consul.sh 
 +</​code><​code>​
 #!/bin/bash #!/bin/bash
  
hashicorp_consul.1793520183.txt.gz · Last modified: 2026/11/01 11:03 by val · Currently locked by: val