{"id":9429,"date":"2021-07-01T23:09:13","date_gmt":"2021-07-01T20:09:13","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9429"},"modified":"2024-03-18T19:52:42","modified_gmt":"2024-03-18T16:52:42","slug":"install-elk-stack-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-elk-stack-on-rocky-linux-8\/","title":{"rendered":"Install ELK Stack on Rocky Linux 8"},"content":{"rendered":"\n<p>Welcome to our demo on how to install&nbsp;<a href=\"https:\/\/www.elastic.co\/products\/elastic-stack\" target=\"_blank\" rel=\"noreferrer noopener\">ELK Stack<\/a>&nbsp;on Rocky Linux 8.<\/p>\n\n\n\n<p>ELK is the acronym for three open source projects:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.elastic.co\/what-is\/elk-stack\" target=\"_blank\">Elasticsearch, Logstash, and Kibana<\/a>. Elasticsearch is a search and analytics engine. Logstash is a server\u2011side data processing pipeline that ingests data from multiple sources simultaneously, transforms it, and then sends it to a \u201cstash\u201d like Elasticsearch. Kibana lets users visualize data in Elasticsearch with charts and graphs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing ELK Stack on Rocky Linux 8<\/h2>\n\n\n\n<p>The order of installation of the Elastic Stack components is of great importance. It usually takes the order&nbsp;<strong>Elasticsearch &gt; Kibana &gt; Logstash &gt; Beats<\/strong>. Also note that all components should be of the same versions.<\/p>\n\n\n\n<p>To install Elastic Stack components on Rocky Linux 8 system, you can choose to create the Elastic RPM repo or install each component using their respective RPM binary.<\/p>\n\n\n\n<p>We use the Elastic repositories in this guide.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Elastic Stack RPM Repo on Rocky Linux 8<\/h3>\n\n\n\n<p>Elastic Stack version 7.x repo can be created by running the command below.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > \/etc\/yum.repos.d\/elasticstack.repo << EOL\n[elasticsearch]\nname=Elasticsearch repository for 7.x packages\nbaseurl=https:\/\/artifacts.elastic.co\/packages\/7.x\/yum\ngpgcheck=1\ngpgkey=https:\/\/artifacts.elastic.co\/GPG-KEY-elasticsearch\nenabled=1\nautorefresh=1\ntype=rpm-md\nEOL\n<\/code><\/pre>\n\n\n\n<p>Run system package update.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-elasticsearch-rocky-linux\"><a href=\"#install-elasticsearch-rocky-linux\">Install Elasticsearch on Rocky Linux 8<\/a><\/h3>\n\n\n\n<p>You can install Elasticsearch on Rocky Linux 8 from the created Elastic RPM repos<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install elasticsearch<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring Elasticsearch<\/h4>\n\n\n\n<p>Out of the box, Elasticsearch works well with the default configuration options. In this demo, we are going to however make a few changes as per&nbsp;<a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/7.5\/important-settings.html\" target=\"_blank\" rel=\"noreferrer noopener\">Important Elasticsearch Configurations<\/a>.<\/p>\n\n\n\n<p>Set the Elasticsearch bind address to a specific IP if you need to enable remote access either from Kibana or Logstash or from Beats.&nbsp;<strong>Replace the IP, 192.168.56.154, with your appropriate server IP address<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sed -i 's\/#network.host: 192.168.0.1\/network.host: 192.168.60.19\/' \/etc\/elasticsearch\/elasticsearch.yml<\/code><\/pre>\n\n\n\n<p>You can as well leave the default settings to only allow local access to Elasticsearch.<\/p>\n\n\n\n<p>When configured to listen on a non-loopback interface, Elasticsearch expects to join a&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/7.5\/cluster.name.html\" target=\"_blank\">cluster<\/a> when started. But since we are setting up a single node Elastic Stack, you need to define in the ES configuration that this is a single node setup, by entering the line,&nbsp;<strong><code>discovery.type: single-node<\/code><\/strong>, under discovery configuration options. However, you can skip this if your ES is listening on a loopback interface.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/elasticsearch\/elasticsearch.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># --------------------------------- Discovery ----------------------------------\n#\n# Pass an initial list of hosts to perform discovery when this node is started:\n# The default list of hosts is &#91;\"127.0.0.1\", \"&#91;::1]\"]\n#\n#discovery.seed_hosts: &#91;\"host1\", \"host2\"]\n#\n# Bootstrap the cluster using an initial set of master-eligible nodes:\n#\n#cluster.initial_master_nodes: &#91;\"node-1\", \"node-2\"]\n# Single Node Discovery\n<strong>discovery.type: single-node<\/strong><\/code><\/pre>\n\n\n\n<p>Next, configure JVM heap size to no more than half the size of your memory. In this case, our test server has 2G RAM and the heap size is set to 512M for both maximum and minimum sizes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/elasticsearch\/jvm.options<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n################################################################\n\n# Xms represents the initial size of total heap space\n# Xmx represents the maximum size of total heap space\n\n<strong>-Xms512m\n-Xmx512m<\/strong>\n...<\/code><\/pre>\n\n\n\n<p>Start and enable ES to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl daemon-reload<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now elasticsearch<\/code><\/pre>\n\n\n\n<p>Verify that Elasticsearch is running as expected.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>curl -XGET 192.168.60.19:9200<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n{\n  \"name\" : \"localhost.localdomain\",\n  \"cluster_name\" : \"elasticsearch\",\n  \"cluster_uuid\" : \"Ga4BA59FTcqPtAPzaUaezw\",\n  \"version\" : {\n    \"number\" : \"7.13.2\",\n    \"build_flavor\" : \"default\",\n    \"build_type\" : \"rpm\",\n    \"build_hash\" : \"4d960a0733be83dd2543ca018aa4ddc42e956800\",\n    \"build_date\" : \"2021-06-10T21:01:55.251515791Z\",\n    \"build_snapshot\" : false,\n    \"lucene_version\" : \"8.8.2\",\n    \"minimum_wire_compatibility_version\" : \"6.8.0\",\n    \"minimum_index_compatibility_version\" : \"6.0.0-beta1\"\n  },\n  \"tagline\" : \"You Know, for Search\"\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-kibana-rocky-linux\"><a href=\"#install-kibana-rocky-linux\">Install Kibana on Rocky Linux 8<\/a><\/h3>\n\n\n\n<p>The next Elastic Stack component to install is Kabana. Since we already created the Elastic Stack repos, you can simply run the command below to install it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install kibana<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Configuring Kibana<\/h4>\n\n\n\n<p>To begin with, you need to configure Kibana to allow remote access. It usually only allows local access on port 5601\/tcp by default. Hence, open the Kibana configuration file for editing and uncomment and change the following lines;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/kibana\/kibana.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n<strong>#server.port: 5601<\/strong>\n...\n# To allow connections from remote users, set this parameter to a non-loopback address.\n<strong>#server.host: \"localhost\"<\/strong>\n...\n# The URLs of the Elasticsearch instances to use for all your queries.\n<strong>#elasticsearch.hosts: &#91;\"http:\/\/localhost:9200\"]<\/strong><\/code><\/pre>\n\n\n\n<p>Such that it look like as shown below:<\/p>\n\n\n\n<p><strong>Replace the IP addresses of Kibana and Elasticsearch accordingly. Note that in this demo, All Elastic Stack components are running on the same host.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n<strong>server.port: 5601<\/strong>\n...\n# To allow connections from remote users, set this parameter to a non-loopback address.\n<strong>server.host: \"192.168.60.19\"<\/strong>\n...\n# The URLs of the Elasticsearch instances to use for all your queries.\n<strong>elasticsearch.hosts: &#91;\"http:\/\/192.168.60.19:9200\"]<\/strong><\/code><\/pre>\n\n\n\n<p>Start and enable Kibana to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now kibana<\/code><\/pre>\n\n\n\n<p>Checking the status;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf kibana.service - Kibana\n   Loaded: loaded (\/etc\/systemd\/system\/kibana.service; disabled; vendor preset: disabled)\n   Active: active (running) since Thu 2021-07-01 20:06:15 EAT; 9s ago\n     Docs: https:\/\/www.elastic.co\n Main PID: 3594 (node)\n    Tasks: 14 (limit: 4938)\n   Memory: 114.1M\n   CGroup: \/system.slice\/kibana.service\n           \u251c\u25003594 \/usr\/share\/kibana\/bin\/..\/node\/bin\/node \/usr\/share\/kibana\/bin\/..\/src\/cli\/dist --logging.dest=\/var\/log\/kibana\/kibana.log --pid.file=\/run\/kibana\/kibana.pid\n           \u2514\u25003606 \/usr\/share\/kibana\/node\/bin\/node --preserve-symlinks-main --preserve-symlinks \/usr\/share\/kibana\/src\/cli\/dist --logging.dest=\/var\/log\/kibana\/kibana.log --p>\n\nJul 01 20:06:15 localhost.localdomain systemd[1]: Started Kibana.\n<\/code><\/pre>\n\n\n\n<p>Open Kibana Port on FirewallD, if it is running;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --add-port=5601\/tcp --permanent<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Kibana Interface<\/h3>\n\n\n\n<p>You can now access Kibana from your browser by using the URL,&nbsp;<code><strong>http:\/\/kibana-server-hostname-OR-IP:5601<\/strong><\/code>.<\/p>\n\n\n\n<p>On Kibana web interface, you can choose to try sample data since there is no data being sent to Elasticsearch yet. You can as well choose to explore your own data, but of course after sending data to ES.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install Logstash on Rocky Linux 8<\/h3>\n\n\n\n<p>This is optional, by the way<\/p>\n\n\n\n<p>Logstash is the component of Elastic Stack that does further processing of the event data before sending it to the Elasticsearch data store. For example, you can develop custom regex, grok patterns to extract specific fields from the event data.<\/p>\n\n\n\n<p>It is also possible to directly sent the data to Elasticsearch instead of passing them through Logstash.<\/p>\n\n\n\n<p>To install Logstash on Rocky Linux 8.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install logstash<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing Logstash<\/h3>\n\n\n\n<p>Once the installation of Logstash is done, you can verify that it is ready to process event data by running the basic pipeline command as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/usr\/share\/logstash\/bin\/\/logstash -e 'input { stdin { } } output { stdout {} }'<\/code><\/pre>\n\n\n\n<p>Press ENTER to execute the command and wait for the Pipeline to be ready to receive input data (<strong>The stdin plugin is now waiting for input:<\/strong>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n&#91;INFO ] 2021-07-01 20:50:03.470 &#91;LogStash::Runner] agent - No persistent UUID file found. Generating new UUID {:uuid=&gt;\"99d0b8b2-3130-413d-bb95-5be99ac6e138\", :path=&gt;\"\/usr\/share\/logstash\/data\/uuid\"}\n&#91;INFO ] 2021-07-01 20:50:05.404 &#91;Api Webserver] agent - Successfully started Logstash API endpoint {:port=&gt;9600}\n...\n...\n&#91;INFO ] 2021-07-01 20:50:09.164 &#91;&#91;main]-pipeline-manager] javapipeline - Pipeline started {\"pipeline.id\"=&gt;\"main\"}\n&#91;INFO ] 2021-07-01 20:50:09.226 &#91;Agent thread] agent - Pipelines running {:count=&gt;1, :running_pipelines=&gt;&#91;:main], :non_running_pipelines=&gt;&#91;]}\n<strong>The stdin plugin is now waiting for input:<\/strong><\/code><\/pre>\n\n\n\n<p>Type any string, for example,&nbsp;<strong>testing Logstash pipeline<\/strong>&nbsp;and press ENTER.<\/p>\n\n\n\n<p>Logstash process the input data and adds timestamp and host address information to the message.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The stdin plugin is now waiting for input:\ntesting Logstash pipeline &lt;&lt; <strong>PRESS ENTER AFTER THIS LINE<\/strong>\n{\n      \"@version\" =&gt; \"1\",\n    \"@timestamp\" =&gt; 2021-07-01T18:06:31.822Z,\n          \"host\" =&gt; \"elk.kifarunix-demo.com\",\n       \"message\" =&gt; \"testing Logstash pipeline\"\n}<\/code><\/pre>\n\n\n\n<p>You can stop Logstash pipeline by pressing Ctrl+D.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Logstash to Collect and Sent Events to Elasticsearch<\/h3>\n\n\n\n<p>Logstash is now ready to receive and process data. In this demo, we are going to learn how to configure Logstash pipeline to collect events from a local system.<\/p>\n\n\n\n<p>Logstash pipeline is made up of three sections;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>the&nbsp;<strong>input<\/strong>: collect data from different sources<\/li>\n\n\n\n<li>the&nbsp;<strong>filter<\/strong>: (<em>Optional<\/em>) performs further processing on data.<\/li>\n\n\n\n<li>the<strong>&nbsp;output<\/strong>: stashes received data into a destination datastore such as Elasticsearch.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Configure Logstash Input plugin<\/h4>\n\n\n\n<p>You can configure beats to sent data to Logstash or simply read local files on the system. To collect events from the local system, we are going to use the&nbsp;<a href=\"https:\/\/www.elastic.co\/guide\/en\/logstash\/7.5\/plugins-inputs-file.html\" target=\"_blank\" rel=\"noreferrer noopener\">file input plugin<\/a>.<\/p>\n\n\n\n<p>There are multiple input plugins you can use, check them on&nbsp;<a href=\"https:\/\/www.elastic.co\/guide\/en\/logstash\/7.5\/input-plugins.html\" target=\"_blank\" rel=\"noreferrer noopener\">Logstash Input Plugins<\/a>.<\/p>\n\n\n\n<p>In this demo, we are using a single configuration file to define the pipeline components; input, filters, output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/logstash\/conf.d\/local-ssh-events.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>## Collect System Authentication events from \/var\/log\/secure<\/strong>\ninput {\n  file {\n    path =&amp;gt; \"\/var\/log\/secure\"\n    type =&amp;gt; \"ssh_auth\"\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Configure Logstash Filter plugin<\/h4>\n\n\n\n<p>Configure Logstash filter to extract only relevant events such as the lines below from the&nbsp;<code><strong>\/var\/log\/secure<\/strong><\/code>&nbsp;file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Jul  1 21:45:34 localhost sshd&#91;13707]: Failed password for invalid user gentoo from 192.168.60.18 port 53092 ssh2\nJul  1 21:45:50 localhost sshd&#91;13768]: Failed password for invalid user KIFARUNIX from 192.168.60.18 port 53094 ssh2\nJul  1 21:47:14 localhost sshd&#91;13949]: Failed password for root from 192.168.60.18 port 53112 ssh2\nJul  1 21:47:17 localhost sshd&#91;13949]: Accepted password for root from 192.168.60.18 port 53112 ssh2<\/code><\/pre>\n\n\n\n<p>We are using Grok Filters to process extract these lines from the log file;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/logstash\/conf.d\/local-ssh-events.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n## Collect System Authentication events from \/var\/log\/secure\ninput {\n  file {\n    path =&gt; \"\/var\/log\/secure\"\n    type =&gt; \"ssh_auth\"\n  }\n}\n<b>filter {\n  if [type] == \"ssh_auth\" {\n    grok {\n      match =&gt; { \"message\" =&gt; \"%{SYSLOGTIMESTAMP:timestamp}\\s+%{IPORHOST:dst_host}\\s+%{WORD:syslog_program}\\[\\d+\\]:\\s+(?&lt;status&gt;.+)\\s+for\\s+%{USER:auth_user}\\s+from\\s+%{SYSLOGHOST:src_host}.*\" }\n      add_field =&gt; { \"activity\" =&gt; \"SSH Logins\" }\n      add_tag =&gt; \"linux_auth\"\n    }\n    grok {\n      match =&gt; { \"message\" =&gt; \"%{SYSLOGTIMESTAMP:timestamp}\\s+%{IPORHOST:dst_host}\\s+%{WORD:syslog_program}\\[\\d+\\]:\\s+(?&lt;status&gt;.+)\\s+for\\s+invalid\\s+user\\s%{USER:auth_user_nonexist}\\s+from\\s+%{SYSLOGHOST:src_host}.*\" }\n      add_field =&gt; { \"activity\" =&gt; \"SSH Logins\" }\n      add_tag =&gt; \"linux_auth\"\n    }\n  }\n# Drop any message that doesn't contain the keywords below\n  if [message] !~ \/(Failed password|Accepted password|Accepted publickey|for invalid)\/ { drop { } }\n}<\/b>\n<\/code><\/pre>\n\n\n\n<p><strong>Note the grok filter used above will just capture password based and public key SSH logins.&nbsp;<\/strong>You can use the Grok Debugger on Kibana to test your pattern,&nbsp;<strong>Dev-tools &gt; Grok Debugger<\/strong>.<\/p>\n\n\n\n<p>Also, note the filter;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>if [message] !~ \/(Failed password|Accepted password|Accepted publickey|for invalid)\/ { drop { }<\/strong><\/code><\/pre>\n\n\n\n<p>For the purpose of demo and to capture only the logs we need for this demo, that line basically drops any other event log not containing the specified keywords above.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Configure Logstash Output Plugin<\/h4>\n\n\n\n<p>Next, we are going to sent our processed data to Elasticsearch running on the localhost.<\/p>\n\n\n\n<p>Define Elasticsearch output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/logstash\/conf.d\/local-ssh-events.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n## Collect System Authentication events from \/var\/log\/secure\ninput {\n  file {\n    path =&gt; \"\/var\/log\/secure\"\n    type =&gt; \"ssh_auth\"\n  }\n}\nfilter {\n  if [type] == \"ssh_auth\" {\n    grok {\n      match =&gt; { \"message\" =&gt; \"%{SYSLOGTIMESTAMP:timestamp}\\s+%{IPORHOST:dst_host}\\s+%{WORD:syslog_program}\\[\\d+\\]:\\s+(?&lt;status&gt;.+)\\s+for\\s+%{USER:auth_user}\\s+from\\s+%{SYSLOGHOST:src_host}.*\" }\n      add_field =&gt; { \"activity\" =&gt; \"SSH Logins\" }\n      add_tag =&gt; \"linux_auth\"\n    }\n    grok {\n      match =&gt; { \"message\" =&gt; \"%{SYSLOGTIMESTAMP:timestamp}\\s+%{IPORHOST:dst_host}\\s+%{WORD:syslog_program}\\[\\d+\\]:\\s+(?&lt;status&gt;.+)\\s+for\\s+invalid\\s+user\\s%{USER:auth_user_nonexist}\\s+from\\s+%{SYSLOGHOST:src_host}.*\" }\n      add_field =&gt; { \"activity\" =&gt; \"SSH Logins\" }\n      add_tag =&gt; \"linux_auth\"\n    }\n  }\n# Drop any message that doesn't contain the keywords below\n  if [message] !~ \/(Failed password|Accepted password|Accepted publickey|for invalid)\/ { drop { } }\n}\n<b>## Send data to Elasticsearch on the localhost\noutput {\n   elasticsearch {\n     hosts =&gt; [\"192.168.60.19:9200\"]\n     manage_template =&gt; false\n     index =&gt; \"ssh_auth-%{+YYYY.MM}\"\n }\n}<\/b>\n<\/code><\/pre>\n\n\n\n<p>Ensure that Logstash can read the file being monitored,&nbsp;<strong><code>\/var\/log\/secure<\/code><\/strong>. By default, file is owned by root. Therefore, for logstash to be able to read the file, first change the group ownership to adm, add logstash to the group adm, and assign read access to logstash.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown :adm \/var\/log\/secure<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>usermod -aG adm logstash<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chmod g+r \/var\/log\/secure<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify Logstash Grok Filters<\/h4>\n\n\n\n<p>Before you can sent the data to Elasticsearch, you need to verify the grok filters. Follow our guide below to learn how to debug grok patterns.<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/how-to-debug-logstash-grok-filters\/\" target=\"_blank\">How to Debug Logstash Grok Filters<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Verify Logstash Configuration<\/h4>\n\n\n\n<p>After the configurations, run the command below to verify the Logstash configuration before you can start it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo -u logstash \/usr\/share\/logstash\/bin\/logstash --path.settings \/etc\/logstash -t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n&#91;2021-07-01T21:50:50,644]&#91;INFO ]&#91;org.reflections.Reflections] Reflections took 36 ms to scan 1 urls, producing 24 keys and 48 values \n<strong>Configuration OK<\/strong>\n&#91;2021-07-01T21:50:52,005]&#91;INFO ]&#91;logstash.runner          ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash\n...<\/code><\/pre>\n\n\n\n<p><strong>Configuration OK<\/strong>&nbsp;confirms that there is no error in the configuration file.<\/p>\n\n\n\n<p>If you need to debug a specific Logstash pipeline configuration file, you can execute the command below. Replace the path to config file with your file path. Ensure logstash is not running when executing this command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo -u logstash \/usr\/share\/logstash\/bin\/logstash -f <strong>\/etc\/logstash\/conf.d\/local-ssh-events.conf<\/strong> --path.settings \/etc\/logstash\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running Logstash<\/h3>\n\n\n\n<p>You can start and enable Logstash to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now logstash<\/code><\/pre>\n\n\n\n<p>If for some weird reasons Logstash did not generate the systemd service file with the symptom:<br><strong><code>(Failed to restart logstash.service: Unit logstash.service not found.)<\/code><\/strong><br>Simply generate the service file by executing the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/usr\/share\/logstash\/bin\/system-install \/etc\/logstash\/startup.options systemd<\/code><\/pre>\n\n\n\n<p>You can the start and enable it to run on boot as shown above.<\/p>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status logstash<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf logstash.service - logstash\n   Loaded: loaded (\/etc\/systemd\/system\/logstash.service; disabled; vendor preset: disabled)\n   Active: active (running) since Thu 2021-07-01 21:53:56 EAT; 6s ago\n Main PID: 15139 (java)\n    Tasks: 15 (limit: 23673)\n   Memory: 311.8M\n   CGroup: \/system.slice\/logstash.service\n           \u2514\u250015139 \/usr\/share\/logstash\/jdk\/bin\/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.a>\n\nJul 01 21:53:56 elk.kifarunix-demo.com systemd[1]: Started logstash.\nJul 01 21:53:56 elk.kifarunix-demo.com logstash[15139]: Using bundled JDK: \/usr\/share\/logstash\/jdk\nJul 01 22:03:31 elk.kifarunix-demo.com logstash[16724]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be remove>\nJul 01 22:03:48 elk.kifarunix-demo.com logstash[16724]: Sending Logstash logs to \/var\/log\/logstash which is now configured via log4j2.properties\nJul 01 22:03:48 elk.kifarunix-demo.com logstash[16724]: [2021-07-01T22:03:48,814][INFO ][logstash.runner          ] Log4j configuration path used is: \/etc\/logstash\/log4j2.>\nJul 01 22:03:48 elk.kifarunix-demo.com logstash[16724]: [2021-07-01T22:03:48,824][INFO ][logstash.runner          ] Starting Logstash {\"logstash.version\"=>\"7.13.2\", \"jruby>\nJul 01 22:03:50 elk.kifarunix-demo.com logstash[16724]: [2021-07-01T22:03:50,369][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Confirm Data Reception on Elasticsearch Index<\/h4>\n\n\n\n<p>Perform some authentication to your system and head back to <strong>Kibana Interface &gt; Management &gt; Stack Management &gt; Data &gt; Index Management<\/strong>.<\/p>\n\n\n\n<p>If your events have been received and forward to Elasticsearch, the defined index should now have been created.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1855\" height=\"595\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/elastic-data.png\" alt=\"\" class=\"wp-image-9437\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/elastic-data.png?v=1625168046 1855w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/elastic-data-768x246.png?v=1625168046 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/elastic-data-1536x493.png?v=1625168046 1536w\" sizes=\"(max-width: 1855px) 100vw, 1855px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Visualizing Data on Kibana<\/h3>\n\n\n\n<p>To visualize and explore data in Kibana, you need to create an index pattern to retrieve data from Elasticsearch.<\/p>\n\n\n\n<p>In this demo, our index pattern is&nbsp;<strong><code>ssh_auth-*<\/code><\/strong>, as defined on the Logstash Elasticsearch output plugin,&nbsp;<strong><code>index =&gt; \"ssh_auth-%{+YYYY.MM}\"<\/code><\/strong>.<\/p>\n\n\n\n<p>On Kibana Dashboard, Navigate to&nbsp;<strong>Management &gt; Stack Management &gt; Kibana &gt; Index Patterns &gt; Create index pattern<\/strong>.<\/p>\n\n\n\n<p>An index pattern can match the name of a single index, or include a wildcard (*) to match multiple indices.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1826\" height=\"757\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana_index-pattern.png\" alt=\"\" class=\"wp-image-9438\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana_index-pattern.png?v=1625168086 1826w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana_index-pattern-768x318.png?v=1625168086 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana_index-pattern-1536x637.png?v=1625168086 1536w\" sizes=\"(max-width: 1826px) 100vw, 1826px\" \/><\/figure>\n\n\n\n<p>Click Next and select&nbsp;<strong>@timestamp<\/strong>&nbsp;as the time filter and click&nbsp;<strong>Create index pattern<\/strong>.<\/p>\n\n\n\n<p>After that, click&nbsp;<strong>Discover tab<\/strong>&nbsp;on the left pane to view the data. Expand time range appropriately.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1891\" height=\"887\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data.png\" alt=\"\" class=\"wp-image-9439\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data.png?v=1625168110 1891w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-768x360.png?v=1625168110 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-1536x720.png?v=1625168110 1536w\" sizes=\"(max-width: 1891px) 100vw, 1891px\" \/><\/figure>\n\n\n\n<p>You can as well select the fields that you want to view based on your grok pattern. In the screenshot below, time range is last 15 minutes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1897\" height=\"747\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-filtered.png\" alt=\"\" class=\"wp-image-9440\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-filtered.png?v=1625168132 1897w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-filtered-768x302.png?v=1625168132 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/kibana-data-filtered-1536x605.png?v=1625168132 1536w\" sizes=\"(max-width: 1897px) 100vw, 1897px\" \/><\/figure>\n\n\n\n<p>Be sure to customize your Grok patterns to your liking if using Logstash as your data processing engine.<\/p>\n\n\n\n<p>Reference;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/www.elastic.co\/guide\/en\/elastic-stack\/current\/installing-elastic-stack.html\" target=\"_blank\">Installing Elastic Stack<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/integrate-wazuh-manager-with-elk-stack\/\" target=\"_blank\" rel=\"noreferrer noopener\">Integrate Wazuh Manager with ELK Stack<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-elk-stack-alerting-with-elastalert\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure ELK Stack Alerting with ElastAlert<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-linux-system-metrics-with-elk-stack\/\" target=\"_blank\" rel=\"noreferrer noopener\">Monitor Linux System Metrics with ELK Stack<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our demo on how to install&nbsp;ELK Stack&nbsp;on Rocky Linux 8. ELK is the acronym for three open source projects:&nbsp;Elasticsearch, Logstash, and Kibana. Elasticsearch<\/p>\n","protected":false},"author":3,"featured_media":9442,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,910,121],"tags":[913,1852,3783,3782,3587],"class_list":["post-9429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-elastic-stack","category-howtos","tag-elk","tag-elk-stack","tag-elk-stack-rocky-linux-8","tag-install-elk-stack-on-rocky-linux-8","tag-rocky-linux-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9429"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=9429"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9429\/revisions"}],"predecessor-version":[{"id":21749,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9429\/revisions\/21749"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9442"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}