Skip to main content
  1. Posts/

Register Service ke Consul

2 mins
consul consul
Table of Contents

Setelah melakukan instalasi Consul Server dan Consul Client, Selanjutnya Anda dapat menambahkan atau mendaftarkan service untuk keperluan monitoring.

Agar mudah dipahami. Simulasi kali ini akan mencoba menambahkan service nginx dengan port 80 ke Consul Client.

Setup nginx.
#

docker run -dit --name web-1 nginx

Register service
#

Buat file web-1.hcl lalu edit seperti berikut.

service {
  name = "webserver"
  id = "web-1"
  tags = ["v1", "v2"]
  port = 80
 
  check {
    id =  "web-1",
    name = "check web-1",
    service_id = "web-1",
    tcp  = "ip-web-1:80",
    interval = "1s",
    timeout = "1s"
  }
}

Define multiple checks

service {
  name = "check-mk"
  id = "svc"
  tags = ["share"]
  port = 80

checks = [
  {
    id       = "svc-80"
    name     = "check http"
    tcp  = "127.0.0.1:80",
    interval = "1s",
    timeout = "1s"
  },
  {
    id       = "svc-21"
    name     = "check ftp"
    tcp  = "127.0.0.1:21",
    interval = "1s",
    timeout = "1s"
  },
  {
    id       = "svc-53"
    name     = "check dns"
    tcp  = "127.0.0.1:53",
    interval = "1s",
    timeout = "1s"
  }
]
}

Define initial health check status

check = {
  id = "mem"
  args = ["/bin/check_mem", "-limit", "256MB"]
  interval = "10s"
  status = "passing"
}

enable-script-checks dan enable-local-script-checks perlu disetting saat setup agent {: .prompt-info }

Register dengan perintah

consul services register web-1.hcl

Reload consul

consul reload

Cek service melalui WebUI Consul ![](/assets/img/Screen Shot 2023-05-19 at 14.47.22.png)

Related

Modifying Headers Consul
1 min
consul consul
Monitor Consul menggunakan Prometheus dan Grafana
2 mins
consul prometheus grafana consul
Setup Multi Datacenter menggunakan Consul
2 mins
consul consul
Membangun Koneksi Peering Antar Cluster Consul
2 mins
consul consul
Install Consul dengan Docker
2 mins
consul docker consul