Skip to content

Building Consul

aborkar-ibm edited this page Apr 27, 2022 · 68 revisions

Building Consul

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

  • Ubuntu 18.04 has 0.6.4
  • Ubuntu 20.04 has 1.5.2
  • Ubuntu 21.10 has 1.7.4

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

  • RHEL (7.8, 7.9, 8.2, 8.4, 8.5)
  • SLES (12 SP5, 15 SP3)
  • Ubuntu (18.04, 20.04, 21.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.11.4/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, 8.2, 8.4, 8.5)

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

    sudo zypper install -y curl gcc git-core make wget awk
  • Ubuntu (18.04, 20.04, 21.10)

    sudo apt-get update
    sudo apt-get install -y curl gcc git make wget
  • Install Go

cd $SOURCE_ROOT
wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Go/1.17.7/build_go.sh
bash build_go.sh 

1.3) Get the source code and build Consul

export GOPATH=$SOURCE_ROOT
export PATH=$GOPATH/bin:$PATH
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.11.4
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.11.4
Revision 944e8ce+CHANGES
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. Following test is failing on s390x and x86 under the module github.com/hashicorp/consul/agent/consul:

TestCheckTCPPassing

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 under github.com/hashicorp/consul/agent/consul 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": "7b9dc35c-64f7-72e6-d9f3-3e9c6169f4e3",
          "Node": "7d2671295c95",
          "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": ""
          },
          "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": {},
          "CreateIndex": 15,
          "ModifyIndex": 15
      }
    ]
    

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

References:

Clone this wiki locally