Skip to content

Building Consul

linuxonz edited this page Mar 14, 2024 · 59 revisions

Building Consul

The following version of Consul are available in the respective distribution at the time of creation of these build instructions:

  • Ubuntu 20.04 has 1.5.2
  • Ubuntu 22.04 has 1.8.7
  • Ubuntu 23.10 has 1.10.12

The instructions provided below specify the steps to build Consul v1.18.0 on Linux on IBM Z for following distributions:

  • RHEL (7.8, 7.9, 8.6, 8.8, 8.9, 9.0, 9.2, 9.3)
  • SLES (12 SP5, 15 SP5)
  • Ubuntu (20.04, 22.04, 23.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Step 1: Build and Install Consul

1.1) Build using script

If you want to build consul using manual steps, go to STEP 1.2.

Use the following commands to build consul using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Consul/1.18.0/build_consul.sh

# Build consul
bash build_consul.sh   [Provide -t option for executing build with tests]

If the build completes successfully, go to STEP 3. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps.

1.2) Install dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (7.8, 7.9)

    sudo yum install -y curl gcc rh-git227-git.s390x make wget diffutils procps-ng unzip python3 python3-pip
    
    #Enable git 2.27
    source /opt/rh/rh-git227/enable
  • RHEL (8.6, 8.8, 8.9, 9.0, 9.2, 9.3)

    sudo yum install -y curl gcc git make wget diffutils procps-ng tar python3 python3-pip
  • SLES (12 SP5, 15 SP5)

    sudo zypper install -y which curl gcc git-core make wget awk unzip tar python3 python3-pip
  • Ubuntu (20.04, 22.04, 23.10)

    sudo apt-get update
    sudo apt-get install -y curl gcc git make wget unzip
  • Add symlink to gcc(Only for SLES and RHEL distros)

sudo ln -sf /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc
  • Add user binary path(Only for SLES SP5)
export PATH="${SOURCE_ROOT}/.local/bin:${PATH}"
  • Install Go
cd $SOURCE_ROOT
wget https://go.dev/dl/go1.21.7.linux-s390x.tar.gz
tar -xzf go1.21.7.linux-s390x.tar.gz
    
sudo rm -rf /usr/local/go /usr/bin/go
sudo ln -sf $SOURCE_ROOT/go/bin/go /usr/bin/ 
sudo ln -sf $SOURCE_ROOT/go/bin/gofmt /usr/bin/

1.3) Get the source code and build Consul

export GOPATH=$SOURCE_ROOT
mkdir -p $GOPATH/src/github.com/hashicorp
cd $GOPATH/src/github.com/hashicorp

git clone https://github.com/hashicorp/consul.git
cd consul
git checkout v1.18.0
make tools
make dev

sudo ln -sf $GOPATH/bin/consul /usr/bin/consul

1.4) Verifying the installation

consul -v

You will get a similar output to this:

Consul v1.18.0
Revision 349cec1+CHANGES
Build Date 2024-02-26T22:05:50Z
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)

Step 2: Testing

2.1) Run test cases (Optional)

cd $GOPATH/src/github.com/hashicorp/consul/
make test

The make test command will run the tests.

Note: 1. If you encounter a failure in TestTakeReturn under github.com/hashicorp/consul/sdk/freeport, changing ulimit to a larger number could make the test pass. For example:

ulimit -n 2048

2. If you encounter a failure in TestDebugCommand under github.com/hashicorp/consul/command/debug, setting umask value to 0022 could make the test pass. For example:

umask 0022

3. Some tests might fail. Re-run these tests individually and they should pass. In case of unexpected test failures, try running the test individually using command:

go test -v <package_name> -run <failed_test_name>

Step 3: Verification

3.1) Run Consul Agent

  • Start the Consul agent in development mode

    nohup consul agent -dev &
  • Check the members of the Consul cluster

    consul members

3.2) Defining and querying the service through Consul

  • Define a service named "web" running on port 80. Additionally, we'll give it a tag we can use as an additional way to query the service:

    sudo mkdir /etc/consul.d
    echo '{"service": {"name": "web", "tags": ["web_service"], "port": 80}}' | sudo tee /etc/consul.d/web.json
  • Restart the agent, providing the configuration directory

    nohup consul agent -dev -config-dir=/etc/consul.d &
  • Use HTTP API to query services

    curl http://localhost:8500/v1/catalog/service/web
  • You will get output similar to this:

    [
      {
          "ID": "53a08b97-45fb-2508-db3a-494218c126bb",
          "Node": "d3ab68ea0388",
          "Address": "127.0.0.1",
          "Datacenter": "dc1",
          "TaggedAddresses": {
              "lan": "127.0.0.1",
              "lan_ipv4": "127.0.0.1",
              "wan": "127.0.0.1",
              "wan_ipv4": "127.0.0.1"
          },
          "NodeMeta": {
              "consul-network-segment": "",
              "consul-version": "1.18.0"
          },
          "ServiceKind": "",
          "ServiceID": "web",
          "ServiceName": "web",
          "ServiceTags": [
              "web_service"
          ],
          "ServiceAddress": "",
          "ServiceWeights": {
              "Passing": 1,
              "Warning": 1
          },
          "ServiceMeta": {},
          "ServicePort": 80,
          "ServiceSocketPath": "",
          "ServiceEnableTagOverride": false,
          "ServiceProxy": {
              "Mode": "",
              "MeshGateway": {},
              "Expose": {}
          },
          "ServiceConnect": {},
          "ServiceLocality": null,
          "CreateIndex": 17,
          "ModifyIndex": 17
      }
    ]
    

Note: To start a Consul cluster, please refer to Getting Started guide here.

References:

Clone this wiki locally