| 명령어 | 설명 |
|---|
consul version | Consul 버전 표시 |
consul agent -dev | 개발 에이전트 시작 |
consul agent -config-dir=/etc/consul.d | 구성으로 시작하기 |
consul members | 클러스터 멤버 나열 |
consul info | 에이전트 정보 표시 |
| 명령어 | 설명 |
|---|
consul agent -server -bootstrap-expect=3 | 서버 에이전트 시작 |
consul agent -client=0.0.0.0 | 클라이언트 에이전트 시작 |
consul join 192.168.1.100 | 클러스터 조인 |
consul leave | 클러스터에서 우아하게 나가기 |
consul reload | 구성 다시 로드 |
| 명령어 | 설명 |
|---|
consul validate /etc/consul.d | 구성 확인 |
consul configtest | 테스트 구성 |
기본 에이전트 작업
| 명령어 | 설명 |
|---|
consul services register service.json | 파일에서 서비스 등록 |
consul services deregister service-id | 서비스 등록 취소 |
consul catalog services | 모든 서비스 나열하기 |
consul catalog nodes | 모든 노드 나열 |
| 명령어 | 설명 |
|---|
consul catalog service web | 서비스 인스턴스 목록 |
consul catalog service web -tag production | 태그로 필터링 |
consul health service web | 건강 검진 상태 |
consul health node node1 | 노드 상태 |
서비스 등록
| 명령어 | 설명 |
|---|
dig @127.0.0.1 -p 8600 web.service.consul | DNS를 통해 서비스 쿼리 |
dig @127.0.0.1 -p 8600 web.service.dc1.consul | 특정 데이터센터 쿼리 |
dig @127.0.0.1 -p 8600 node1.node.consul | DNS를 통해 노드 쿼리하기 |
| 명령어 | 설명 |
|---|
consul kv put config/database/url "postgresql://..." | 키-값 저장소 |
consul kv get config/database/url | 값 검색 |
consul kv get -recurse config/ | 접두사 아래의 모든 키 가져오기 |
consul kv delete config/database/url | 삭제 키 |
consul kv delete -recurse config/ | 접두사 아래의 모든 키 삭제 |
| 명령어 | 설명 |
|---|
consul kv put -cas -modify-index=123 config/app/version "2.0" | 조건부 업데이트 |
consul kv get -detailed config/app/version | 메타데이터와 함께 가져오기 |
consul kv export config/ | 키 내보내기 |
consul kv import @backup.json | 키 가져오기 |
KV 작업
| 명령어 | 설명 |
|---|
consul health checks | 모든 상태 검사 나열하기 |
consul health checks web | 서비스에 대한 목록 확인 |
consul health state critical | 중요한 검사 목록 |
consul health state passing | 통과한 검사 목록 |
| 명령어 | 설명 |
|---|
consul acl bootstrap | Bootstrap ACL 시스템 |
consul acl token create -description="Web service token" | 토큰 생성 |
consul acl token list | 토큰 목록 |
consul acl token delete TOKEN_ID | 토큰 삭제 |
상태 검사 관리
| 명령어 | 설명 |
|---|
consul acl policy create -name web-policy -rules @policy.hcl | 정책 생성 |
consul acl policy list | 정책 목록 |
consul acl policy read web-policy | 정책 읽기 |
consul acl policy update -id POLICY_ID -rules @new-policy.hcl | 정책 업데이트 |
ACL 관리
| 명령어 | 설명 |
|---|
consul connect ca get-config | CA 구성 가져오기 |
consul connect ca set-config -config-file ca.json | CA 구성 설정 |
consul connect proxy -service web | Start Connect 프록시 |
| 명령어 | 설명 |
|---|
consul intention create web db | 웹이 데이터베이스에 연결하도록 허용 |
consul intention create -deny web cache | 웹 캐싱 거부 |
consul intention list | 모든 의도 나열하기 |
consul intention delete web db | 삭제 의도 |
Connect 구성
| 명령어 | 설명 |
|---|
consul config write service-defaults.hcl | 서비스 기본값 작성 |
consul config write proxy-defaults.hcl | 프록시 기본값 작성 |
consul config list -kind service-defaults | 구성 목록 |
consul config read -kind service-defaults -name web | 구성 읽기 |
consul config delete -kind service-defaults -name web | 구성 삭제 |
| 명령어 | 설명 |
|---|
consul snapshot save backup.snap | 스냅샷 생성 |
consul snapshot restore backup.snap | 스냅샷 복원 |
consul snapshot inspect backup.snap | 스냅샷 검사 |
서비스 구성
| 명령어 | 설명 |
|---|
consul monitor | 스트림 로그 |
consul monitor -log-level=DEBUG | 디버그 레벨 로그 |
consul debug | 디버그 정보 수집 |
consul operator raft list-peers | Raft 피어 목록 |
스냅샷 작업
| 명령어 | 설명 |
|---|
consul operator autopilot get-config | 오토파일럿 구성 가져오기 |
consul operator autopilot set-config -cleanup-dead-servers=true | 오토파일럿 구성 설정 |
모니터링 명령어
datacenter = "dc1"
data_dir = "/opt/consul"
log_level = "INFO"
node_name = "consul-server-1"
server = true
bootstrap_expect = 3
retry_join = ["10.0.1.10", "10.0.1.11"]
bind_addr = "10.0.1.10"
client_addr = "0.0.0.0"
ui_config \\\\{
enabled = true
\\\\}
connect \\\\{
enabled = true
\\\\}
acl = \\\\{
enabled = true
default_policy = "deny"
enable_token_persistence = true
\\\\}
```### 성능
```hcl
datacenter = "dc1"
data_dir = "/opt/consul"
log_level = "INFO"
node_name = "consul-client-1"
retry_join = ["10.0.1.10", "10.0.1.11", "10.0.1.12"]
bind_addr = "10.0.1.20"
client_addr = "127.0.0.1"
services \\\\{
name = "web"
port = 80
tags = ["production", "v1.0"]
check \\\\{
http = "http://localhost:80/health"
interval = "10s"
\\\\}
\\\\}
서비스 정의
\\\\{
"service": \\\\{
"name": "web",
"port": 80,
"tags": ["production"],
"check": \\\\{
"http": "http://localhost:80/health",
"interval": "10s"
\\\\},
"connect": \\\\{
"sidecar_service": \\\\{\\\\}
\\\\}
\\\\}
\\\\}
ACL 정책
node_prefix "" \\\\{
policy = "read"
\\\\}
service_prefix "" \\\\{
policy = "read"
\\\\}
service "web" \\\\{
policy = "write"
\\\\}
key_prefix "config/web/" \\\\{
policy = "write"
\\\\}
session_prefix "" \\\\{
policy = "read"
\\\\}
서비스 메시 구성
프록시 기본 설정
Kind = "proxy-defaults"
Name = "global"
Config \\\\{
protocol = "http"
\\\\}
MeshGateway \\\\{
Mode = "local"
\\\\}
서비스 기본 설정
Kind = "service-defaults"
Name = "web"
Protocol = "http"
MeshGateway \\\\{
Mode = "local"
\\\\}
Expose \\\\{
Checks = true
Paths = [
\\\\{
Path = "/health"
LocalPathPort = 8080
ListenerPort = 21500
\\\\}
]
\\\\}
멀티 데이터센터 설정
WAN 페더레이션
| 명령어 | 설명 |
|---|
consul join -wan 192.168.2.10 | WAN에 가입하기 |
consul members -wan | WAN 구성원 목록 |
consul catalog datacenters | 데이터센터 목록 |
크로스 DC 쿼리
| 명령어 | 설명 |
|---|
consul catalog service web -datacenter dc2 | DC2의 쿼리 서비스 |
dig @127.0.0.1 -p 8600 web.service.dc2.consul | DC2에 대한 DNS 쿼리 |
문제 해결
일반적인 문제
| 명령어 | 설명 |
|---|
consul operator raft list-peers | Raft 클러스터 상태 확인 |
consul debug -duration=30s | 디버그 정보 수집 |
consul validate /etc/consul.d | 구성 확인 |
consul members -detailed | 상세 회원 정보 |
로그 분석
| 명령어 | 설명 |
|---|
consul monitor -log-level=TRACE | 추적 수준 로깅 |
journalctl -u consul -f | systemd 로그 따라가기 |
모범 사례
보안