{"id":1818,"date":"2017-02-01T09:48:59","date_gmt":"2017-02-01T09:48:59","guid":{"rendered":"http:\/\/cloudkul.com\/blog\/?p=1818"},"modified":"2017-06-14T11:33:26","modified_gmt":"2017-06-14T11:33:26","slug":"setting-elasticsearch-logstash-kibana-centralized-logging","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/","title":{"rendered":"Setting up Elasticsearch, Logstash and Kibana for centralized logging"},"content":{"rendered":"<p>For proper analysis of a server or a system, <strong>logs<\/strong> play a very important role. By reading logs we can know about\u00a0 system incidents\u00a0 which happened in a particular time. Logs help us to detect the problems in the system and troubleshoot the problems. <strong>Logs<\/strong> are generally stored in <strong>files<\/strong>. For different services different log files are generated. If we have many systems and\u00a0 we need to analyze the logs,then it will be difficult to manage all the <strong>logs<\/strong>. So it is best practice to store the logs in a <strong>centralized<\/strong> sever.<\/p>\n<p>As logs are saved in files, sometimes it is hard to analyze the data in text format. If we can extract the data from logs and convert the data in <strong>table, graph, pie-chart<\/strong> form it will be easy for us to analyze the data. It is easier to analyze the data in detailed picture form rather than reading the text based log files.<\/p>\n<p>In case of apache\u00a0 log, contents of the log file increases every time some one visit the website. So for proper analysis we should able to read the logs in real time. So the centralized server should be able to fetch the data from the servers in real time.<\/p>\n<p>The above requirements are fulfilled by the <strong>ELK<\/strong> (<strong>Elasticsearch, Logstash and Kibana<\/strong>) <strong>stack<\/strong>. <strong>Elasticsearch<\/strong> is used as a centralized log server where as <strong>Logstash<\/strong> is used to send log data to Elasticsearch in real time. <strong>Kibana<\/strong> is used for view the complex log data in picture form.<\/p>\n<p>In this tutorial I will show you how to setup\u00a0 ELK stack. I am using <strong>ubuntu 14.04<\/strong> in all the servers.<\/p>\n<p><strong>Setting up ELK stack<\/strong><\/p>\n<p>Suppose I have 3 different servers running apache service and I need to get the log files from each server. So, I need to setup Logstash in each of the server.<strong> Logstash<\/strong> will read the <strong>apache log<\/strong> files and send it to the <strong>Elasticsearch<\/strong> server. Elasticsearch will save the logs in unique <strong>index<\/strong> defined by the Logstash. I need another server which will use <strong>Kibana<\/strong> to fetch the data from the <strong>Elasticsearch<\/strong> and visualize the data.<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/elk.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1821\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/elk.png\" alt=\"\" width=\"786\" height=\"429\" \/><\/a><\/p>\n<p><strong>Install Java<br \/>\n<\/strong><\/p>\n<p>The <strong>ELK<\/strong> stack needs java to run the applications. So you need to install java in all the servers. Before installing any of the application make sure <strong>Java<\/strong> is installed.<\/p>\n<pre class=\"lang:sh decode:true\">sudo apt-add-repository ppa:webupd8team\/java\r\nsudo apt-get update\r\nsudo apt-get install oracle-java8-installer\r\n#verfify your java version\r\njava -version\r\n\r\n<\/pre>\n<p><strong>Install Kibana<\/strong><\/p>\n<p>Login to you server where you want to setup kibana<\/p>\n<pre class=\"lang:default decode:true\"># Download the deb package for ubuntu\r\nsudo wget https:\/\/artifacts.elastic.co\/downloads\/kibana\/kibana-5.1.2-amd64.deb\r\nsudo dpkg -i kibana-5.1.2-amd64.deb\r\n\r\n\r\n<\/pre>\n<p>Open <strong>\/etc\/kibana\/kibana.yml <\/strong>and change the following.<\/p>\n<pre class=\"lang:sh decode:true \">server.host: \"192.168.1.80\"\r\n# IP of the Elasticsearch server\r\nelasticsearch.url: \"http:\/\/192.168.1.56:9200\"<\/pre>\n<p>Now, restart the kibana service.<\/p>\n<pre class=\"lang:default decode:true\">sudo service kibana restart<\/pre>\n<p><strong>Install Elasticsearch<\/strong><\/p>\n<p>Login to your server where you want to setup Elasticsearch<\/p>\n<pre class=\"lang:sh decode:true \"># Download the deb package for ubuntu\r\nsudo wget https:\/\/artifacts.elastic.co\/downloads\/elasticsearch\/elasticsearch-5.1.2.deb\r\nsudo dpkg -i elasticsearch-5.1.2.deb\r\n<\/pre>\n<p>Open <strong>\/etc\/elasticsearch\/elasticsearch.yml<\/strong>\u00a0 and change the following.<\/p>\n<pre class=\"lang:sh decode:true\">network.host: 192.168.1.56\r\n<\/pre>\n<p>Now,restart the Elasticsearch service.<\/p>\n<pre class=\"lang:default decode:true \">sudo service elasticsearch restart<\/pre>\n<p><strong>Install Logstash<\/strong><\/p>\n<p>You need to install Logstash for each\u00a0 server. Installation and configuration is same for all the server, you just need to define different index name for <strong>Elasticsearch<\/strong>.<\/p>\n<pre class=\"lang:default decode:true \"># Download deb package for ubuntu\r\nsudo wget https:\/\/artifacts.elastic.co\/downloads\/logstash\/logstash-5.1.2.deb\r\nsudo dpkg -i logstash-5.1.2.deb<\/pre>\n<p>Create a file\u00a0 <strong>\/etc\/logstash\/conf.d\/apache.conf<\/strong> and copy the following content.<\/p>\n<pre class=\"lang:sh decode:true \">input {\r\n    file {\r\n        # Give path to your log file\r\n        path =&gt; '\/var\/log\/apache2\/mysite_access.log'\r\n    }\r\n}\r\n\r\nfilter {\r\n    grok {\r\n        #match =&gt; { \"message\" =&gt; \"%{COMBINEDAPACHELOG}\" }\r\n        match =&gt; { \"message\" =&gt; \"%{NOTSPACE:clientip} \\- \\- \\[%{NOTSPACE:date} \\+%{INT}\\] \\\"%{WORD:method} \/%{NOTSPACE:request} %{NOTSPACE:httpversion}\\\" %{INT:response} %{INT} \\\"%{NOTSPACE:fullurl}\\\" \\\"%{GREEDYDATA:misc}\\\"\" }\r\n    }\r\n}\r\n\r\n#output {\r\n#    stdout { codec =&gt; rubydebug }\r\n#}\r\noutput {\r\n    elasticsearch {\r\n         # Elastic server IP and port\r\n         hosts =&gt; [\"192.168.1.56:9200\"]\r\n         # choose an index name\r\n         index =&gt; \"client1-apache\"\r\n    }\r\n}\r\n<\/pre>\n<p>For different server change the <strong>index<\/strong>. Make sure the path to the log file is correct in the <strong>input<\/strong> section. In filter section you can define your own pattern and get the logs in key value format.<\/p>\n<p>Now, restart the <strong>Logstash<\/strong> service and use the <strong>configuration<\/strong> file we wrote for sending logs to Elasticsearch.<\/p>\n<pre class=\"lang:default decode:true\">sudo service logstash restart\r\nsudo \/usr\/share\/logstash\/bin\/logstash -f \/etc\/logstash\/conf.d\/apache.conf<\/pre>\n<p>If there is no error in configuration, you will see output like this<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/logstash-successful.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1825\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/logstash-successful.png\" alt=\"\" width=\"724\" height=\"59\" \/><\/a><\/p>\n<p>Now, In the browser open <strong>Kibana<\/strong> server, in my case it is <strong>http:\/\/192.168.1.80:5601<\/strong>.<\/p>\n<p>Go to <strong>Management -&gt; Index Patterns -&gt; Add New<\/strong> and add your <strong>index<\/strong> name., the <strong>index<\/strong> name you added in the <strong>logstash<\/strong> configuration file.<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/kibana-index.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1826\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/kibana-index.png\" alt=\"\" width=\"972\" height=\"527\" \/><\/a><\/p>\n<p>After you create your <strong>index<\/strong> you can able to visualize your logs in <strong>Kibana<\/strong> Dashboard. Do this for other servers also and you will be able to view logs by <strong>index<\/strong> name. If you have any query regarding\u00a0 <strong>ELK<\/strong> <strong>stack<\/strong> <strong>setup<\/strong>, you can ask me in the comment.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/cloudkul.com\/contact\/\" target=\"_blank\" rel=\"noopener noreferrer\"> IN CASE OF ANY QUERY,CONTACT US<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For proper analysis of a server or a system, logs play a very important role. <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":8,"featured_media":1835,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"For proper analysis of a server or a system, logs play a very important role. [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-01T09:48:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-14T11:33:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/6i2gm2uH.png\" \/>\n\t<meta property=\"og:image:width\" content=\"848\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"suranjan horrow\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\",\"name\":\"Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2017-02-01T09:48:59+00:00\",\"dateModified\":\"2017-06-14T11:33:26+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting up Elasticsearch, Logstash and Kibana for centralized logging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809\",\"name\":\"suranjan horrow\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"suranjan horrow\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/cloudkul.com\/blog\/author\/suranjan-horrow869\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/","og_locale":"en_US","og_type":"article","og_title":"Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul","og_description":"For proper analysis of a server or a system, logs play a very important role. [...]","og_url":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/","og_site_name":"Cloudkul","article_published_time":"2017-02-01T09:48:59+00:00","article_modified_time":"2017-06-14T11:33:26+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/02\/6i2gm2uH.png","type":"image\/png"}],"author":"suranjan horrow","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/","url":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/","name":"Setting up Elasticsearch, Logstash and Kibana for centralized logging - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2017-02-01T09:48:59+00:00","dateModified":"2017-06-14T11:33:26+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/setting-elasticsearch-logstash-kibana-centralized-logging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting up Elasticsearch, Logstash and Kibana for centralized logging"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809","name":"suranjan horrow","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"suranjan horrow"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/cloudkul.com\/blog\/author\/suranjan-horrow869\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1818"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=1818"}],"version-history":[{"count":14,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1818\/revisions"}],"predecessor-version":[{"id":2823,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1818\/revisions\/2823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/1835"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=1818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=1818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=1818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}