Goal
The goal of this blog is to describe steps to reach following state.
- I want to run CentOS7 box in Vagrant using VirtualBox Vagrant provider.
- I want to run ElasticSearch in the CentOS7 box on port 9200.
- I want tu run Kibana in the CentOS7 box on port 5601.
- I want Kibana to display data from ElasticSearch.
- I want ElasticSearch to be accessible through port 9201 on our localhost.
- I want Kibana to be accessible through port 5602 on our localhost.
Set up Vagrant
Get official CentOS 7 box if you yet don’t have it.
1 |
vagrant box add centos/7 |
Run the box.
1 |
vagrant init box/7 |
Now Vagrantfile
was created in our current directory. We need to edit to configure following.
- Setup port forwarding from port 5601(in box) to 5602 (localhost of host machine).
- Setup port forwarding from 9201 to 9200.
- Setup amount of memory available for the box to 4GB (the default amount for VirtualBox is not enough to run ES/Kibana).
Uncomment and setup following options in your Vagrantfile
.
1 2 3 4 5 6 7 8 9 |
# port forwarding config.vm.network "forwarded_port", guest: 9200, host: 9201 # ES config.vm.network "forwarded_port", guest: 5601, host: 5602 # Kibana config.vm.network "forwarded_port", guest: 8111, host: 8112 # HTTP server for test # memory setup config.vm.provider "virtualbox" do |vb| vb.memory = "4096" end |
You can also use provider other than VirtualBox, then you should however check how to setup memory for it because the memory setup above might not work.
Let’s boot it up!
1 2 |
vagrant up; vagrant ssh; |
Install ElasticSearch and Kibana
Now we need to install java, setup YUM repository for elasticsearch, start the service and then check whether it is up and running. You can simly use following script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/bin/bash rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch echo "Adding Elasticsearch repository elastic.repo." touch '/etc/yum.repos.d/elastic.repo' echo "[elasticsearch-5.x] name=Elasticsearch repository for 5.x packages baseurl=https://packages.elastic.co/elasticsearch/5.x/centos gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1" > '/etc/yum.repos.d/elastic.repo' yum install -y java elasticsearch echo "Making sure Elastic-Search service starts automatically on system bootup" systemctl daemon-reload systemctl enable elasticsearch.service echo "Start Elastic-Search service" systemctl start elasticsearch.service service elasticsearch status echo "Now I will sleep for 11 seconds and then verify if elastic search API is reachable." n=0 while (( $n <= 11 )); do echo -n "."; sleep 1; ((n++)); done if curl -XGET http://127.0.0.1:9200; then echo "Seems like ElasticSearch is up and running. Don't forget to set up whatever is needed in /etc/elasticsearch/" exit 0; else echo "ERROR: Can't reach ElasticSearch!" exit 1; fi; |
Similarly, for Kibana you can use following script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/bin/bash rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch echo "Adding Kibana repository kibana.repo." touch '/etc/yum.repos.d/kibana.repo' echo "[kibana-5.x] name=Kibana repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md" > '/etc/yum.repos.d/kibana.repo' yum install -y kibana # Making sure Kibana service starts automatically on system bootup systemctl daemon-reload systemctl enable kibana.service # Start Kibana systemctl start kibana.service service kibana status echo "Now I will sleep for 11 seconds and then verify if elastic search API is reachable." n=0 while (( $n <= 11 )); do echo -n "."; sleep 1; ((n++)); done if curl -XGET http://127.0.0.1:5601; then echo "Seems like Kibana is up and running. Don't forget to set up whatever is needed in /etc/kibana/" exit 0; else echo "ERROR: Can't reach Kibana!" exit 1; fi; |
Configure ElasticSearch and Kibana
The ElasticSearch configuration is located at /etc/elasticsearch/elasticsearch.yml
The minimal change required to configuration is to set following value
1 |
network.host: 0.0.0.0 |
By default the value is 127.0.0.1
, which however prevents to access from outside the machine. Learn here why is that.
Kibana confiruation file is similarly located at /etc/kibana/kibana.yml
and the values you have to modify are
1 2 |
server.host: 0.0.0.0 elasticsearch.url: "http://localhost:9200" |
After modifying configuration, you need to restart elasticsearch and kibana service.
1 2 |
service elasticsearch restart service kibana restart |
You can wait few seconds and make sure they are truly still up and running.
1 2 |
service elasticsearch status service kibana status |
If some of the services failed, you can investigate why that happend by running
1 2 |
journalctl -u elasticsearch -f --lines 200 journalctl -u kibana -f --lines 200 |
Otherwise, if everything is fine, you can navigate to http://localhost:5602 in your browser – your Kibana should be there.
However, Kibana will first of all ask you for index pattern. To get going quickly, you can post some sample data to ES, which will also by default create index and mapping.
1 |
curl -XPOST http://localhost:9201/catalog/products -d '{ "hello": "world" }' |
Now you can setup your first index pattern in Kibana catalog*
and you should be able to discover the '{ "hello": "world" }'
document.