콘텐츠로 이동

Consul

명령어설명
consul versionConsul 버전 표시
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.consulDNS를 통해 서비스 쿼리
dig @127.0.0.1 -p 8600 web.service.dc1.consul특정 데이터센터 쿼리
dig @127.0.0.1 -p 8600 node1.node.consulDNS를 통해 노드 쿼리하기
명령어설명
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 bootstrapBootstrap 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-configCA 구성 가져오기
consul connect ca set-config -config-file ca.jsonCA 구성 설정
consul connect proxy -service webStart 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-peersRaft 피어 목록

스냅샷 작업

명령어설명
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.10WAN에 가입하기
consul members -wanWAN 구성원 목록
consul catalog datacenters데이터센터 목록

크로스 DC 쿼리

명령어설명
consul catalog service web -datacenter dc2DC2의 쿼리 서비스
dig @127.0.0.1 -p 8600 web.service.dc2.consulDC2에 대한 DNS 쿼리

문제 해결

일반적인 문제

명령어설명
consul operator raft list-peersRaft 클러스터 상태 확인
consul debug -duration=30s디버그 정보 수집
consul validate /etc/consul.d구성 확인
consul members -detailed상세 회원 정보

로그 분석

명령어설명
consul monitor -log-level=TRACE추적 수준 로깅
journalctl -u consul -fsystemd 로그 따라가기

모범 사례

보안