Skip to main content

Setup ELK Stack & Apache Kafka from Docker Compose YAML File

This tutorial is to setup ELK stack and Apache Kafka environment using one docker-compose YAML file. Please note that for following tutorial you should have a docker agent and docker compose installed on your host machine. All the images are present on docker hub and only two commands are used to get the environment up and running. Following are the images deployed by this script :

1) Default official ElasticSearch Image from docker hub at port 9200 and the line 9200:9200 binds the port of docker image of ElasticSearch to the machine IP at 9200 port.

2)Default official Kibana Image from docker hub at port 5601 and the line 5601:5601 binds the port of docker image of Kibana to the machine IP at 5601 port. and links it to elasticsearch by using the line elasticsearch:elasticsearch.

3) Default official Zookeeper Image from docker hub at port 2181 and the line 2181:2181 binds the port of docker image of Zookeeper to the machine IP at 2181 port.

4)Kafka Image is ches/kafka image from docker hub. The docker image deployed at port 9092 and the line 9092:9092 binds the port of docker image of ches/kafka to the machine IP at 9092 port. Creates a default topic topictest and connects to zookeeper on 2181 port.

5) Default official Logstash Image from docker hub at port 12201 and the line 12201:12201 binds the port of docker image of ElasticSearch to the machine IP at 12201 port. It takes 2 inputs one from kafka topic (topictest)  and one from tcp on port. And output of logstash is sent to elasticsearch on port 9200.


Below is the code for docker-compose.yml file. In the file replace this text : ||Enter Your IP for machine here e.g 12.12.12.12|| with the IP for your machine or localhost if you want to run it on your local machine.

 elasticsearch:

  image: elasticsearch

  ports:

  - 9200:9200

kibana:

  image: kibana

  links:

  - elasticsearch:elasticsearch

  ports:

  - 5601:5601

  environment:

  - ELASTICSEARCH_URL=http://elasticsearch:9200

zookeeper:

    image: zookeeper

    ports:

      - "2181:2181"

kafka:

    image: ches/kafka

    links:

      - zookeeper:zookeeper

    ports:

      - "9092:9092"

    environment:

      KAFKA_ADVERTISED_HOST_NAME: "||Enter Your IP for machine here e.g 12.12.12.12||"

      KAFKA_ADVERTISED_PORT: "9092"

      KAFKA_CREATE_TOPICS: "topictest:1:1"

      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

logstash:

  image: logstash:latest

  links:

  - elasticsearch:elasticsearch

  ports:

  - 12201:12201

  command: logstash -e "input { kafka { bootstrap_servers => '||Enter Your IP for machine here e.g 12.12.12.12||:9092' client_id => 'logstash' topics => 'topictest' } tcp { port => 12602 codec => json } }  output { elasticsearch { hosts => '||Enter Your IP for machine here e.g 12.12.12.12||:9200' } }"

Then go to terminal for the root and run the following two commands :

sudo sysctl -w vm.max_map_count=262144
sudo docker-compose up

When the terminal shoes the following line logstash is up  :
Now open a new terminal and write sudo docker ps and following images should be visible :


Now in browser write ur hostname:9200 following page should show up. This means elasticsearch is up and running


Now in browser write ur hostname:5601 Kibana homepage will show up :


Please ask me any questions in the comments section below.

p.s Sometimes the kafka server doesnot start up on first time so run docker compose command again and you are good to go.

Comments

  1. Nice guide. How do you post messages on the topic created (topictest)?

    ReplyDelete
    Replies
    1. Thanks. There are multiple ways :
      1)If you are just want to test the topic you can open a producer on kafka by using CLI and send messages.
      2)You can also send messages to kafka from your code.
      3)In java you can do setting for logback to send logs to kafka.

      Delete
  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apache Kafka, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on in Apache Kafka. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/


    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle SOA BPEL Interview Questions

Following are some questions often asked in SOA BPEL Interviews What are the Major Elements in WSDL? Answer:  1) types 2) message 3) portType 4) binding Explain about SOAP Structure? Answer:  1)Envelope ->indentifies the xml doc as a SOAP message 2)Header   ->contains header information 3)Body Element ->contains call and response information 4)Fault Element ->containing errors and status information What are the BPEL activities? Answer:  1)Assign Activity 2)Transform Activity 3)Invoke Activity 4)Recieve Activity 5)Scope Activity 6)Wait Activity 7)Empty Activity Difference between Complex Type and Simple Type element? Answer:  Complex Type ->because it contains other elements Simple Type     ->these elements contain other elements Difference between synchronous and Asynchronous process? Answer:  Asynchronous refers to processes that do not depend on each other's outcome, and can therefore occur on                 different

Setup jenkins and build maven code in less than 15 minutes

This is a small tutorial to get you to setup Jenkins with git hub and build maven code in few minutes. First, we install git on our host machine using the following commands: sudo yum install git to verify that git is installed properly use the following command: git --version Second, we install Jenkins Add the Jenkins repository to the yum repo, and install Jenkins from here. Run the following commands on terminal: sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key sudo yum install jenkins I am using a Redhat distribution.If you are using any other OS go to the following link and run the commands as described respective to your OS: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins Jenkins requires Java in order to run.If it is not already present to install the Open Java Development Kit (OpenJDK) run the following: sudo yum install java To s