반응형
consul 서비스 등록
consul agent 환경 설정(consul.hcl)
vim /etc/consul.d/consul.hcl
datacenter = "my-dc-1"
data_dir = "/opt/consul"
bind_addr = "0.0.0.0" # Listen on all IPv4
advertise_addr = "192.168.0.63"
retry_join = ["control1", "node1", "node2"]
/etc/consul.d
/opt/consul/services/
web-service.hcl 편집
cd /etc/consul.d
$ ls
consul.env consul.hcl web-service.hcl
vim web-service.hcl
service {
name = "web check G"
tags = ["web","http"]
port = 80
checks = [{
name = "web index page check"
http = "http://127.0.0.1/index.htm"
interval = "3s"
timeout = "1s"
},
{
name = "web 80 port check"
tcp = "127.0.0.1:80"
interval = "6s"
timeout = "3s"
}
]
}
$ ls
consul.env consul.hcl web-service.hcl
consul validate /etc/consul.d/consul.hcl
$ consul validate /etc/consul.d/consul.hcl
bootstrap_expect > 0: expecting 3 servers
Configuration is valid!
consul validate /etc/consul.d
$ consul validate /etc/consul.d
skipping file /etc/consul.d/consul.env, extension must be .hcl or .json, or config format must be set
skipping file /etc/consul.d/consul.hcl.bk, extension must be .hcl or .json, or config format must be set
Configuration is valid!
consul reload
$ consul reload
Configuration reload triggered
HTTP API
consul agent service 등록
- http://localhost:8500/v1/agent/service/register
curl -X PUT http://localhost:8500/v1/agent/service/register -d '{ "Name": "Service G", "ID": "site-1", "Address": "sangchul.kr", "Meta": {"path":"/", "ssl":"true" }, "Port": 443}'
curl -X PUT http://localhost:8500/v1/agent/service/register -d '{ "Name": "Service G", "ID": "site-2", "Address": "scbyun.com", "Meta": {"path":"/", "ssl":"true" }, "Port": 443}'
consul agent service 등록 취소
- http://localhost:8500/v1/agent/service/deregister/{ID}
curl -X PUT http://localhost:8500/v1/agent/service/deregister/site-1
cd /opt/consul
$ tree
.
├── checkpoint-signature
├── node-id
├── serf
│ └── local.snapshot
└── services
├── 3b4f681c2c755cc086d3ff38779432b5f9dd0bfc4703570c0c9c492512060651
└── f505dccd1d9094dbc62328daa123f757f798383017083a95df22cd993c74fb35
2 directories, 5 files
3b4f681c2c755cc086d3ff38779432b5f9dd0bfc4703570c0c9c492512060651 파일 확인
$ cat services/3b4f681c2c755cc086d3ff38779432b5f9dd0bfc4703570c0c9c492512060651 | jq
{
"Token": "",
"Service": {
"ID": "site-2",
"Service": "Service G",
"Tags": null,
"Address": "scbyun.com",
"Meta": {
"path": "/",
"ssl": "true"
},
"Port": 443,
"Weights": {
"Passing": 1,
"Warning": 1
},
"EnableTagOverride": false,
"Proxy": {
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"Connect": {},
"PeerName": "",
"CreateIndex": 0,
"ModifyIndex": 0
},
"Source": "remote"
}
참고URL
- Consul Commands (CLI) : https://developer.hashicorp.com/consul/commands
- Consul Agent Service Registration : https://developer.hashicorp.com/consul/commands/services/register
- Consul Agent Service Deregistration : https://developer.hashicorp.com/consul/commands/services/deregister
728x90
반응형
'리눅스' 카테고리의 다른 글
[리눅스] nomad cluster 구성(install nomad cluster) (0) | 2023.01.27 |
---|---|
[리눅스] nomad 설치(install nomad) (0) | 2023.01.27 |
systemctl status 명령어 (0) | 2023.01.27 |
Consul 클러스터를 구성하는 방법 (0) | 2023.01.27 |
우분투에 Consul을 설치하고 설정하는 방법 (0) | 2023.01.26 |