Elasticsearch is a search engine that can store data, analyze data, search data very fast and accurate, it is distributed and restful, and very easy to scale. Kibana is an open-source graphical user interface that can corporate with Elasticsearch, it can provide visualization of Elasticsearch data, it can also help you to navigate the Elastic Stack. This article will tell you how to install Elasticsearch Kibana in a docker container.
1. Setup Elasticsearch.
- Open a terminal and create a new elasticsearch directory to store elasticsearch data.
mkdir /var/elasticsearch-7.10.1
- Create the below files in the above folder.
./ ├── dockerfile ├── elasticsearch-7.10.1-amd64.deb ├── run.sh └── sources.list
- Content of dockerfile.
FROM ubuntu:16.04 # Edit the sources list. ADD sources.list /etc/apt/sources.list ADD elasticsearch-7.10.1-amd64.deb ./ # Install jdk and elasticsearch. RUN apt-get update && apt-get install -y openjdk-8-jdk --allow-unauthenticated && apt-get clean all && dpkg -i elasticsearch-7.10.1-amd64.deb && rm -rf elasticsearch-7.1.1-amd64.deb EXPOSE 9200 # Add startup script. ADD run.sh . RUN chmod 755 run.sh ENTRYPOINT [ "/run.sh"]
- Content of sources.list.
deb https://download.docker.com/linux/ubuntu xenial main restricted deb https://download.docker.com/linux/ubuntu xenial-updates main restricted deb https://download.docker.com/linux/ubuntu xenial universe deb https://download.docker.com/linux/ubuntu xenial-updates universe deb https://download.docker.com/linux/ubuntu xenial multiverse deb https://download.docker.com/linux/ubuntu xenial-updates multiverse deb https://download.docker.com/linux/ubuntu xenial-backports main restricted universe multiverse deb https://download.docker.com/linux/ubuntu xenial-security main restricted deb https://download.docker.com/linux/ubuntu xenial-security universe deb https://download.docker.com/linux/ubuntu xenial-security multiverse
- Content of startup script run.sh.
#!/bin/bash set -e # Add time zone. TZ=Asia/Shanghai ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Override configurtion file. cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak echo "transport.host: localhost transport.tcp.port: 9300 http.port: 9200 network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml # Modify the startup file and remove the -d parameter to avoid running in the background. sed -i 72'[email protected] -p [email protected] [email protected]' /etc/init.d/elasticsearch # Start elasticsearch. /etc/init.d/elasticsearch start
- Generate the elasticserch image.
docker build -t elasticsearch-7.10.1 .
- Start the docker container.
docker run -d -it --restart=always -p 9200:9200 elasticsearch-7.10.1
2. Setup Kibana.
- Open a terminal and run the command
mkdir /var/kibana-7.10.1
to create a new directory for kibana.mkdir /var/kibana-7.10.1
- Create the below files in the above kibana folder.
./ ├── dockerfile ├── kibana-7.10.1-amd64.deb └── run.sh
- The content of the dockerfile in the above folder.
FROM ubuntu:16.04 ADD kibana-7.10.1-amd64.deb ./ # Install jdk and elasticsearch. RUN dpkg -i kibana-7.10.1-amd64.deb && rm -rf kibana-7.10.1-amd64.deb EXPOSE 5601 # Add startup shell script. ADD run.sh . RUN chmod 755 run.sh ENTRYPOINT [ "/run.sh"]
- Content of the kibana run.sh script file.
#!/bin/bash # Add time zone. TZ=Asia/Shanghai ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone #elasticsearch="192.168.8.169" if [ -z $elasticsearch ];then echo "elasticsearch parameter is empty! Please input a valide ip address." exit fi # Modify the configuration file. # Modify the listening port. sed -i '[email protected]#server.host: "localhost"@server.host: "0.0.0.0"@g' /etc/kibana/kibana.yml sed -i '28d' /etc/kibana/kibana.yml sed -i "N;28 i elasticsearch.hosts: ["http://$elasticsearch:9200"]" /etc/kibana/kibana.yml # Startup kibana. /usr/share/kibana/bin/kibana "-c /etc/kibana/kibana.yml"
- Create the kibana image file.
docker build -t kibana-7.10.1
- Start kibana from the above image file.
docker run -d -it --restart=always -p 5601:5601 -e elasticsearch=192.168.19.19 kibana-7.10.1