Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Installing Consul 1.11.1 on CentOS 8.2 for Service Discovery

Tech May 9 3

Consul Installation on CentOS

To install Consul on CentOS 8.2, first add the HashiCorp repository:

yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install consul

Service Cofniguration

Create or modify the systemd service file at /etc/systemd/system/consul.service:

[Unit]
Description="HashiCorp Consul Service Mesh"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/consul.hcl

[Service]
EnvironmentFile=/etc/consul.d/consul.env
User=root
Group=root
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

Consul Server Configuration

Create a JSON configuration file at /etc/consul.d/server_config.json:

{
  "datacenter": "primary-dc",
  "data_dir": "/var/lib/consul",
  "log_level": "INFO",
  "node_name": "server-node",
  "server": true,
  "ports": {
    "http": 8500,
    "dns": 8600,
    "serf_lan": 8001,
    "serf_wan": 8002,
    "server": 8003
  }
}

Modify /etc/consul.d/consul.hcl with these settings:

client_addr = "0.0.0.0"
ui_config {
  enabled = true
}
bind_addr = "0.0.0.0"
advertise_addr = "127.0.0.1"
bootstrap_expect = 1

Spring Boot Integration

For Spring Boot integration, add these dependencies to your pom.xml:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Configure bootstrap.yml:

spring:
  cloud:
    consul:
      host: YOUR_SERVER_IP
      port: 8500
      discovery:
        health-check-path: /actuator/health
        health-check-interval: 5s
        instance-id: ${spring.application.name}:${server.port}
Tags: Consulcentos

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.