{"id":3380,"date":"2024-09-25T02:47:48","date_gmt":"2023-08-12T14:44:16","guid":{"rendered":""},"modified":"2025-02-02T00:46:20","modified_gmt":"2025-02-01T23:46:20","slug":"how-to-install-consul-server-on-almalinux-9-using-docker-and-ansible","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-consul-server-on-almalinux-9-using-docker-and-ansible\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 Consul Server on AlmaLinux 9 using Docker and Ansible"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<p>A Comprehensive Step-by-Step Guide<\/p>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>Consul is a distributed, highly available, and data center-aware tool for service discovery, configuration, and segmentation. It is widely used in modern microservices architectures to manage and secure service-to-service communication.<\/p>\n<p>In this guide, we will walk you through the process of installing Consul Server on AlmaLinux 9 using Docker and Ansible. By the end of this article, you will have a fully functional Consul Server running in a Dockerized environment, managed by Ansible.<\/p>\n<\/section>\n<section>\n<h2>Prerequisites<\/h2>\n<p>Before we begin, ensure that you have the following prerequisites:<\/p>\n<ul>\n<li><strong>AlmaLinux 9:<\/strong> A server running AlmaLinux 9 with root or sudo access.<\/li>\n<li><strong>Docker:<\/strong> Docker installed on your AlmaLinux 9 server. You can follow the <a href=\"https:\/\/docs.docker.com\/engine\/install\/\" target=\"_blank\" rel=\"follow\">official Docker installation guide<\/a>.<\/li>\n<li><strong>Docker Compose:<\/strong> Docker Compose installed. Follow the <a href=\"https:\/\/docs.docker.com\/compose\/install\/\" target=\"_blank\" rel=\"follow\">official Docker Compose installation guide<\/a>.<\/li>\n<li><strong>Ansible:<\/strong> Ansible installed on your local machine or control node. Follow the <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/installation_guide\/intro_installation.html\" target=\"_blank\" rel=\"follow\">official Ansible installation guide<\/a>.<\/li>\n<li><strong>Basic Knowledge:<\/strong> Familiarity with Docker, Ansible, and Linux command-line operations.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>Step 1: Set Up Docker and Docker Compose<\/h2>\n<p>First, ensure that Docker and Docker Compose are installed and running on your AlmaLinux 9 server.<\/p>\n<h3>Install Docker<\/h3>\n<pre><code>sudo dnf config-manager --add-repo=https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo\r\nsudo dnf install docker-ce docker-ce-cli containerd.io\r\nsudo systemctl start docker\r\nsudo systemctl enable docker<\/code><\/pre>\n<h3>Install Docker Compose<\/h3>\n<pre><code>sudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/v2.20.0\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose\r\nsudo chmod +x \/usr\/local\/bin\/docker-compose<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 2: Create a Docker Compose File for Consul Server<\/h2>\n<p>Create a directory for your Consul setup and navigate into it:<\/p>\n<pre><code>mkdir consul-setup\r\ncd consul-setup<\/code><\/pre>\n<p>Create a <code>docker-compose.yml<\/code> file:<\/p>\n<pre><code>version: '3.8'\r\n\r\nservices:\r\n  consul:\r\n    image: consul:latest\r\n    container_name: consul\r\n    restart: always\r\n    ports:\r\n      - \"8500:8500\"\r\n      - \"8600:8600\/udp\"\r\n    command: \"agent -server -bootstrap-expect=1 -ui -client=0.0.0.0\"\r\n    volumes:\r\n      - consul_data:\/consul\/data\r\n    networks:\r\n      - consul_network\r\n\r\nvolumes:\r\n  consul_data:\r\n\r\nnetworks:\r\n  consul_network:<\/code><\/pre>\n<p>This Docker Compose file defines a Consul Server service. It exposes ports 8500 (HTTP API and UI) and 8600 (DNS). The <code>-bootstrap-expect=1<\/code> flag indicates that this is a single-node Consul cluster.<\/p>\n<\/section>\n<section>\n<h2>Step 3: Deploy with Docker Compose<\/h2>\n<p>Run the following command to start the Consul Server container:<\/p>\n<pre><code>docker-compose up -d<\/code><\/pre>\n<p>This command will pull the Consul Docker image and start the container in detached mode.<\/p>\n<\/section>\n<section>\n<h2>Step 4: Automate with Ansible<\/h2>\n<p>To automate the deployment process, create an Ansible playbook named <code>deploy_consul.yml<\/code>:<\/p>\n<pre><code>---\r\n- hosts: all\r\n  become: yes\r\n  tasks:\r\n    - name: Ensure Docker is installed\r\n      dnf:\r\n        name: docker-ce\r\n        state: present\r\n\r\n    - name: Ensure Docker Compose is installed\r\n      get_url:\r\n        url: https:\/\/github.com\/docker\/compose\/releases\/download\/v2.20.0\/docker-compose-$(uname -s)-$(uname -m)\r\n        dest: \/usr\/local\/bin\/docker-compose\r\n        mode: '0755'\r\n\r\n    - name: Start and enable Docker service\r\n      service:\r\n        name: docker\r\n        state: started\r\n        enabled: yes\r\n\r\n    - name: Create Consul setup directory\r\n      file:\r\n        path: \/opt\/consul-setup\r\n        state: directory\r\n\r\n    - name: Copy Docker Compose file\r\n      copy:\r\n        src: docker-compose.yml\r\n        dest: \/opt\/consul-setup\/docker-compose.yml\r\n\r\n    - name: Deploy Consul with Docker Compose\r\n      command: docker-compose up -d\r\n      args:\r\n        chdir: \/opt\/consul-setup<\/code><\/pre>\n<p>Run the playbook using the following command:<\/p>\n<pre><code>ansible-playbook -i your_inventory_file deploy_consul.yml<\/code><\/pre>\n<p>Replace <code>your_inventory_file<\/code> with the path to your Ansible inventory file.<\/p>\n<\/section>\n<section>\n<h2>Step 5: Access Consul Web UI<\/h2>\n<p>Once the deployment is complete, open your web browser and navigate to <code>http:\/\/your_server_ip:8500<\/code>. You should see the Consul Web UI, where you can manage and monitor your Consul Server.<\/p>\n<\/section>\n<section>\n<h2>Step 6: Verify Consul Server<\/h2>\n<p>To verify that the Consul Server is running correctly, you can use the Consul CLI or HTTP API.<\/p>\n<h3>Using Consul CLI<\/h3>\n<p>Access the Consul container and run the following command:<\/p>\n<pre><code>docker exec -it consul consul members<\/code><\/pre>\n<p>This command lists the members of the Consul cluster. Since this is a single-node cluster, you should see only one member.<\/p>\n<h3>Using HTTP API<\/h3>\n<p>You can also use the HTTP API to check the status of the Consul Server:<\/p>\n<pre><code>curl http:\/\/localhost:8500\/v1\/status\/leader<\/code><\/pre>\n<p>This command should return the address of the Consul leader.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>In this guide, we walked you through the process of installing Consul Server on AlmaLinux 9 using Docker and Ansible. By following these steps, you can easily set up a Consul Server for service discovery, configuration, and segmentation in your infrastructure.<\/p>\n<p>Docker and Ansible make it easy to manage and automate your deployments, ensuring a smooth and consistent setup process. Whether you&#8217;re running a small cluster or a large-scale distributed system, this setup provides a robust foundation for your needs.<\/p>\n<\/section>\n<footer>\n<p>\u00a0<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 A Comprehensive Step-by-Step Guide Introduction Consul is a distributed, highly available, and data center-aware tool for service discovery, configuration, and segmentation. It is widely used in\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-3380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=3380"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3380\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=3380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=3380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=3380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}