Logstash: How To Install A Plugin- The Simplest Ways.

Logstash, one of the key tools of the ELK stack has been gaining a lot of popularity in the last couple of years. In this tutorial, we’ll go through the two ways to install a plugin on Logstash.
First up, we have to know exactly which plugin we’re going to install. Logstash has got four (04) types of plugins: input plugins, filter plugins, output plugins, and codec plugins. As we talked about in a previous article, there are tons of tons of Logstash plugins. They are written in Ruby and are available either as gem packages on https://rubygems.org/ or on https://github.com/logstash-plugins.
Now that we’ll are sunk into Logstash plugins word, let’s get started.
1- Install a plugin from the internet
The first thing we’re going to do will be to find the installation directory of Logstash on our machine.
Run this command if you’re on Ubuntu:
whereis logstash
Check each one of the paths you’ve got and look for a bin folder for the path we’re looking for. On Ubuntu, the right path is /usr/share/logstash as default path.
So let’s move to that folder.
cd /usr/share/logstash
We’re now ready to install our plugin. The plugin I’m going to install is logstash-input-rabbitmq.
sudo bin/logstash-plugin install logstash-input-rabbitmq
After few minutes, you’re ready to check if your plugin is well installed. Let’s do that.
bin/logstash-plugin list | grep logstash-input-rabbitmq
This should prompt your newly installed plugin at the end of the output content in your terminal. Now without too much talk, let’s get into the manual installation
2- Install a plugin offline — from Github.com
The first time I came across this possibility, I asked myself why engineers are going to install a Logstash plugin offline. The truth is that there are a lot of private network Logstash deployments without network access.
For offline installation, there are two ways to proceed. But for both of them, we’ll need a machine with internet access.
On your machine that is connected to the internet, go through these steps.
git clone https://github.com/logstash-plugins/logstash-input-rabbitmq.git
Then move into the cloned folder.
cd logstash-input-rabbitmq
Then we’re going to build the plugin gem. In order to do that, we need the Ruby bundler. Let’s go ahead and install it.
On Ubuntu, execute this command:
sudo apt-get install ruby-bundler
Now we’re good to go. Let’s build our plugin. The file we’re interested in is the .gemspec file.
gem build logstash-input-rabbitmq.gemspec
We’re almost done. Now we need to move the cloned folder to our offline machine.
On your machine offline machine, go through these steps.
Move to your Logstash installation directory. On Ubuntu, the default path is /usr/share/logstash.
cd /usr/share/logstash
Open your Gemfile
sudo nano Gemfile
Add this line:
gem "logstash-input-rabbitmq", :path => "/full/path/to/your/plugin/folder"
My full path is: /var/lib/logstash/plugins/logstash-input-rabbitmq.
Do you feel like you want to give up? Hold on. These are the final steps 🥁.
Now run:
cd /usr/share/logstash
bin/logstash-plugin install --no-verify
Let’s check if everything went well.
bin/logstash-plugin list | grep logstash-input-rabbitmq
🛑 Don’t forget to replace your plugin name everywhere I used bold text for the terminal commands!
You should get back the name of your fresh install Logstash plugin.
Logstash is an amazing tool. Its tons of plugins make it just wonderful to use. Thank you’ll guys for following along.
In the following article, we’ll be working on a very interesting project proposed to me by Nidhi.
Till next time, take care.