DevOps

Setting Up Ansible and Zookeeper on Ubuntu – Part 1

In this guide, we will walk through setting up Ansible, Java, and Zookeeper on an Ubuntu system using various command-line instructions. This tutorial is designed for IT professionals and will include explanations of each command and its purpose.

Step 1: Update Package List

First, update the package list to ensure you have the latest information about the newest versions of packages and their dependencies:

sudo apt-get update
  • sudo: Executes the command as a superuser.
  • apt-get: A package handling utility in Ubuntu.
  • update: Fetches the latest list of available packages from the repositories.

Step 2: Install Essential Packages

Next, install some essential packages that will be needed for our setup:

sudo apt install software-properties-common
  • install: Installs the specified package.
  • software-properties-common: Provides an abstraction of the used apt repositories.

Step 3: Install Ansible and Other Tools

Install Ansible along with some other necessary tools:

sudo apt-get install ansible git curl sshpass telnet -y
  • ansible: An automation tool for configuration management.
  • git: A version control system.
  • curl: A tool for transferring data with URLs.
  • sshpass: A non-interactive ssh password provider.
  • telnet: A user interface to communicate with another host using the Telnet protocol.
  • -y: Automatically answers ‘yes’ to all prompts.

Step 4: Set Up Directory Structure

Create the necessary directory structure for Zookeeper:

pwd 
> /vagrant/master/ansible
mkdir data1 data2 files
mkdir files/etc files/opt
mkdir files/opt/zookeeper
mkdir data1/zookeeper
mkdir files/opt/zookeeper/conf/
  • pwd: Prints the current working directory.
  • mkdir: Creates directories. The structure includes directories for data, configuration files, and Zookeeper-specific directories.

Step 5: Install Java

Install Java Runtime Environment (JRE) and Java Development Kit (JDK):

sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo apt install openjdk-8-jdk
  • default-jre: Installs the default JRE.
  • default-jdk: Installs the default JDK.
  • openjdk-8-jdk: Installs OpenJDK version 8.

Step 6: Download and Set Up Zookeeper

Download and extract Zookeeper, then copy configuration files to the appropriate directories:

wget http://www-us.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5.6.tar.gz
tar xzf apache-zookeeper-3.5.6.tar.gz
cp apache-zookeeper-3.5.6/conf/zoo_sample.cfg files/opt/zookeeper/conf/zoo.cfg
cp apache-zookeeper-3.5.6/conf/log4j.properties files/opt/zookeeper/conf/
  • wget: Downloads files from the web.
  • tar xzf: Extracts the gzipped tar file.
  • cp: Copies files to the specified location.

Step 7: Configure Vagrant for Multiple Nodes

Finally, set up a Vagrantfile to create multiple virtual machines for the Zookeeper cluster:

config.vm.define "master" do |master|
    master.vm.hostname = "master"
    master.vm.box = "bento/ubuntu-18.04"    
    master.vm.network "private_network", ip: "192.168.33.100"

    master.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.cpus = 2
    end
  end

  config.vm.define "node1" do |node1|
    node1.vm.hostname = "node1"      
    node1.vm.box = "bento/ubuntu-18.04"
    node1.vm.network "private_network", ip: "192.168.33.10"

    node1.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.cpus = 2
    end
  end

  config.vm.define "node2" do |node2|
    node2.vm.hostname = "node2"      
    node2.vm.box = "bento/ubuntu-18.04"
    node2.vm.network "private_network", ip: "192.168.33.20"

    node2.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.cpus = 2
    end
  end

  # Repeat similar blocks for node3 to node7
  • config.vm.define: Defines a new virtual machine.
  • vm.hostname: Sets the hostname of the VM.
  • vm.box: Specifies the Vagrant box to use.
  • vm.network: Configures network settings.
  • vm.provider: Configures provider-specific settings like memory and CPU allocation.

Ali Imran
Over the past 20+ years, I have been working as a software engineer, architect, and programmer, creating, designing, and programming various applications. My main focus has always been to achieve business goals and transform business ideas into digital reality. I have successfully solved numerous business problems and increased productivity for small businesses as well as enterprise corporations through the solutions that I created. My strong technical background and ability to work effectively in team environments make me a valuable asset to any organization.
https://ITsAli.com

Leave a Reply