반응형
consul kv
consul 사용법
$ consul kv
Usage: consul kv <subcommand> [options] [args]
This command has subcommands for interacting with Consul's key-value
store. Here are some simple examples, and more detailed examples are
available in the subcommands or the documentation.
Create or update the key named "redis/config/connections" with the value "5":
$ consul kv put redis/config/connections 5
Read this value back:
$ consul kv get redis/config/connections
Or get detailed key information:
$ consul kv get -detailed redis/config/connections
Finally, delete the key:
$ consul kv delete redis/config/connections
For more examples, ask for subcommand help or view the documentation.
Subcommands:
delete Removes data from the KV store
export Exports a tree from the KV store as JSON
get Retrieves or lists data from the KV store
import Imports a tree stored as JSON to the KV store
put Sets or updates data in the KV store
데이터 추가(키 생성)
consul kv put web/server/config/webserv1-hostname webserv1
$ consul kv put web/server/config/webserv1-hostname webserv1
Success! Data written to: web/server/config/webserv1-hostname
consul kv put web/server/config/webserv1-ip 1.1.1.1
$ consul kv put web/server/config/webserv1-ip 1.1.1.1
Success! Data written to: web/server/config/webserv1-ip
쿼리 데이터(키 읽기)
consul kv get web/server/config/webserv1-hostname
$ consul kv get web/server/config/webserv1-hostname
webserv1
consul kv get web/server/config/webserv1-ip
$ consul kv get web/server/config/webserv1-ip
1.1.1.1
데이터 삭제(키 삭제)
consul kv delete web/server/config/webserv1-hostname
$ consul kv delete web/server/config/webserv1-hostname
Success! Deleted key: web/server/config/webserv1-hostname
consul kv delete web/server/config/webserv1-ip
$ consul kv delete web/server/config/webserv1-ip
Success! Deleted key: web/server/config/webserv1-ip
consul REST API
export CONSUL_CLIENT_ADDRESS=`ip route get 1.2.3.4 | awk '{ print $7 }' | egrep -v '^$'`
echo $CONSUL_CLIENT_ADDRESS
데이터 저장
curl --request PUT --data 'active' http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state
$ curl --request PUT --data 'active' http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state
true
데이터 호출
curl -s http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state | jq
$ curl -s http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state | jq
[
{
"LockIndex": 0,
"Key": "redis/state",
"Flags": 0,
"Value": "YWN0aXZl",
"CreateIndex": 74042,
"ModifyIndex": 74042
}
]
데이터 삭제
curl -XDELETE http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state
$ curl -XDELETE http://${CONSUL_CLIENT_ADDRESS}:8500/v1/kv/redis/state
true
in.tpl 파일 생성
vim in.tpl
{{ key "foo" }}
consul-template 실행
consul-template -template "in.tpl:out.txt" -once
터미널 하나를 더 띄워 아래 명령을 실행합니다.
consul kv put foo bar
$ consul kv put foo bar
Success! Data written to: foo
out.txt 파일이 생성됩니다.
$ cat out.txt
bar
728x90
반응형
'리눅스' 카테고리의 다른 글
HAProxy 컴파일을 통해 설치하는 방법(source compile) (0) | 2023.02.14 |
---|---|
[리눅스] consul-template 파일 생성 (0) | 2023.02.14 |
[리눅스] 리눅스에서 CPU 사용률을 계산하고, 소수점 2자리까지 출력하는 쉘 스크립트 예제 - by ChatGPT (0) | 2023.02.13 |
[리눅스] consul 서비스 등록 - 2 (0) | 2023.02.10 |
java(jdk) 설치 및 java 환경 설정 (0) | 2023.02.07 |