Skip to content

Building Consul

aborkar-ibm edited this page Nov 18, 2020 · 63 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 20.10 has 1.7.4

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

  • RHEL (7.7, 7.8, 7.9, 8.1, 8.2)
  • SLES (12 SP5, 15 SP1, 15 SP2)
  • Ubuntu (18.04, 20.04, 20.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.8.5/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.7, 7.8, 7.9, 8.1, 8.2)

    sudo yum install -y curl gcc git make wget
  • SLES (12 SP5, 15 SP1, 15 SP2)

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

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

    export GO_INSTALL_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Go/1.15.3/build_go.sh"
    cd $SOURCE_ROOT
    wget -O build_go.sh $GO_INSTALL_URL
    bash build_go.sh -v 1.14.9
    export GOPATH=$SOURCE_ROOT
    export PATH=$GOPATH/bin:$PATH

1.3) Get the source code and build Consul

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.8.5
make tools
make dev

1.4) Verifying the installation

$GOPATH/bin/consul -v

You will get a similar output to this:

Consul v1.8.5
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)

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
cd $GOPATH/src/github.com/hashicorp/consul/
make test

The make test command will run the tests.

Note: In case of unexpected test failures try running the test individually using command:

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

Note: On RHEL 7.* distributions, The tests TestTestCAAndLeaf_xc/TestTestCAAndLeaf_xc-ec-224 and TestTestCAAndLeaf_xc/TestTestCAAndLeaf-ec-224 are known to fail. These tests also fail on x86_64 so the failures are not specific to s390x.

Step 3: Verification

3.1) Run Consul Agent

  • Start the Consul agent in development mode

    cd $GOPATH/bin
    nohup consul agent -dev &
  • Check the members of the Consul cluster

    cd $GOPATH/bin
    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:

    cd $GOPATH/bin
    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

    cd $GOPATH/bin
    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": "deb934e4-30b8-78dd-729b-b2997babd1b8",
           "Node": "nodename",
           "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": [
               "rails"
           ],
           "ServiceAddress": "",
           "ServiceWeights": {
               "Passing": 1,
               "Warning": 1
           },
           "ServiceMeta": {},
           "ServicePort": 80,
           "ServiceEnableTagOverride": false,
           "ServiceProxy": {
               "MeshGateway": {},
               "Expose": {}
           },
           "ServiceConnect": {},
           "CreateIndex": 12,
           "ModifyIndex": 12
        }
     ]

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

References:

Consul Source Code
Consul Website
Consul Getting Started

Clone this wiki locally