consul 서비스 설치 및 TIP

SYSTEM/TECH / /
반응형

Hashicorp 에서 제공하는 devops 툴중 하나 consul 


- service discovery 기능

- key / value 저장소

- 오류(장애) 감지



 Terraform, nomad, Vagrant 등과 잘 조합하여 사용하면 devops 구현이 가능...



서버 설치


# consul keygen


   zWxxxxxxxxxxxxxxxxxxxxxx  (키생성)



# cat /etc/consul.d/server/config.json

{

  "bootstrap": true,

  "server": true,

  "datacenter": "test",

  "ui_dir": "/data/consul-ui",

  "data_dir": "/data/consul",

  "encrypt": "key 값",

  "addresses": {

      "http": "x.x.x.x"

  }

}




Consul 임시 실행 및 확인


nohup consul agent --server -config-dir=/etc/consul.d/server -bind=x.x.x.x &




Consul server Service 스크립트 만들기 (ubuntu 기준)


vi /etc/init/consul.conf


description "Consul server process"


start on local-filesystems and net-device-up IFACE=eth0

stop on runlevel [!12345]


respawn


setuid ubuntu

setgid ubuntu


exec consul agent --server -config-dir=/etc/consul.d/server -bind=[Consul 서버 IP]


# start consul

# tail -f /var/log/upstart/consul.log

# stop consul


----------------------------------------------------------------------------------------------------------------------------------------


에이전트 설치


config.json


{

  "server": false,

  "datacenter": "DZHOST",

  "data_dir": "c:\\consul\\data\\",

  "encrypt": "key 값",

  "start_join": ["consul server IP"]

}



에이전트 (클라이언트) 실행 및 확인


# nohup consul agent -config-dir /etc/consul.d/agent -bind=[Consul agent IP] &

예: consul.exe agent -config-dir "C:\consul\config" -data-dir "C:\Consul\data" -config-file="c:\consul\config\config.json" -bind=:: 



특정 서버만 (list file로) 일괄 등록하기 (saltstack 사용) 윈도우 버전 (리눅스 가능)


# salt -L `awk -vORS=, '{ print $1 }' minions.list | sed 's/,$/\n/'` cp.get_dir salt://windows/consul 'C:\'


# salt -L `awk -vORS=, '{ print $1 }' minions.list | sed 's/,$/\n/'` cmd.run 'cmd /c c:\consul\consul-service-up.bat'



consul-service-up.bat


@ECHO OFF


set IP="netsh interface ip show addresses | findstr 10.20.x. | findstr IP"   (agent IP binding 하기 위함)


FOR /f "tokens=3" %%I IN ('%IP%') DO SET ipAddress=%%I


cmd /c "c:\consul\nssm install consul consul.exe agent -config-dir "C:\consul\config" -data-dir "C:\Consul\data" -config-file="c:\consul\config\config.json" -bind=%ipAddress%"






###  기타 config sample ###


##ping 체크

# ping.json


{

  "check": 

  {

   "name": "ping",

   "script": "ping -c 1 x.x.x.x", 

   "interval": "30s"

  }

}




##윈도우 특정 서비스 check

# service.json


{

  "check": 

    {

        "id": "W32Time",

        "name": "w32time", 

        "script": "PowerShell -ExecutionPolicy Bypass -NoProfile -File c:\\Temp\\consul\\conf\\ServiceCheck.ps1", 

        "interval": "30s"

    }

}



# ServiceCheck.ps1 


$Service = Get-Service w32Time

if ($Service.Status -ne 'Running') 

    {

        $Service | Write-Output

        exit 2

    } 

else 

    {

        $Service | Write-Output

        exit 0

    }



Consul WEB UI 화면 (UI 설치는 구글링 ...)


http://1x.x.x.x:8500/




반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기