-
Notifications
You must be signed in to change notification settings - Fork 56
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
The instructions provided below specify the steps to build Consul v1.20.1 on Linux on IBM Z for following distributions:
- RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
- SLES 15 SP6
- Ubuntu (20.04, 22.04, 24.04, 24.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.
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.20.1/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.
export SOURCE_ROOT=/<source_root>/
-
RHEL (8.8, 8.10, 9.2, 9.4, 9.5)
sudo yum install -y curl gcc git make wget diffutils procps-ng tar python3 python3-pip
Note: Add the '--allowerasing' option if any dependency conflicts are faced for RHEL 9.2.
-
SLES 15 SP6
sudo zypper install -y which curl gzip gcc git-core make wget awk unzip tar python3 python3-pip
-
Ubuntu (20.04, 22.04, 24.04, 24.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)
export PATH="${SOURCE_ROOT}/.local/bin:${PATH}"
-
Install Go version
1.22.7
cd $SOURCE_ROOT export GO_VERSION="1.22.7" wget -q https://storage.googleapis.com/golang/go"$GO_VERSION".linux-s390x.tar.gz chmod ugo+r go"$GO_VERSION".linux-s390x.tar.gz sudo tar -C /usr/local -xzf go"$GO_VERSION".linux-s390x.tar.gz sudo ln -sf /usr/local/go/bin/go /usr/bin/ sudo ln -sf /usr/local/go/bin/gofmt /usr/bin/ sudo ln -sf /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc # (Only on RHEL and SLES) go version
export GOPATH=$SOURCE_ROOT
mkdir -p $GOPATH/src/github.com/hashicorp
cd $GOPATH/src/github.com/hashicorp
git clone -b v1.20.1 https://github.com/hashicorp/consul.git
cd consul
make tools
make dev
sudo ln -sf $GOPATH/bin/consul /usr/bin/consul
consul -v
You will get a similar output to this:
Consul v1.20.1
Revision 920cc7c+CHANGES
Build Date 2024-10-29T19:04:05Z
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
cd $GOPATH/src/github.com/hashicorp/consul/
make test
The make test
command will run the tests.
Notes:
- If you encounter a failure in
TestTakeReturn
undergithub.com/hashicorp/consul/sdk/freeport
, changing ulimit to a larger number could make the test pass. For example:
ulimit -n 2048
- If you encounter a failure in
TestDebugCommand
undergithub.com/hashicorp/consul/command/debug
, setting umask value to 0022 could make the test pass. For example:
umask 0022
- 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>
For example: TestHealthServiceNodes_NodeMetaFilter
go test -v github.com/hashicorp/consul/agent -run TestHealthServiceNodes_NodeMetaFilter
-
Start the Consul agent in development mode
nohup consul agent -dev &
-
Check the members of the Consul cluster
consul members
-
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": "4dd4ff54-6164-2198-f2ca-46fff9f9d807", "Node": "4b0ba9944e06", "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.20.1" }, "ServiceKind": "", "ServiceID": "web", "ServiceName": "web", "ServiceTags": [ "rails" ], "ServiceAddress": "", "ServiceWeights": { "Passing": 1, "Warning": 1 }, "ServiceMeta": {}, "ServicePort": 80, "ServiceSocketPath": "", "ServiceEnableTagOverride": false, "ServiceProxy": { "Mode": "", "MeshGateway": {}, "Expose": {} }, "ServiceConnect": {}, "ServiceLocality": null, "CreateIndex": 15, "ModifyIndex": 15 }
Note: To start a Consul cluster, please refer to Getting Started guide here.
The information provided in this article is accurate at the time of writing, but on-going development in the open-source projects involved may make the information incorrect or obsolete. Please open issue or contact us on IBM Z Community if you have any questions or feedback.