Until version 1.3 included, Logstash was distributed as a single JAR file, and when version 1.4 was released a new packaging style was introduced. As a consequence, new instructions are required to properly setup Logstash in FreeBSD and registering it as a service. Further information about the new distribution layout can be found in the Logstash release notes.
As seen in the previous post, a Logstash FreeBSD port exists, but it is currently outdated since it bundles Logstash v. 1.2. But while this could be used as a starting point for JAR-based Logstash installations (as we have seen, the update process only required updating the Logstash JAR), this is not possible with the new Logstash distribution because the included rc script will fail to work.
Edit: I've managed to patch the broken Logstash dependency and I'm waiting for the pull request to be merged upstream. In the meantime you can use an updated FreeBSD port I've created to install Logstash on FreeBSD 10.
Edit: The Logstash port has been updated and I'm the new maintainer. Also, the pull request solving a JRuby bug on FreeBSD has been merged to upstream and will hopefully hit a Logstash release soon.
Skimming through the original post is recommended because it provides general information about Logstash and FreeBSD which is required to properly plan and execute a Logstash setup.
Prerequisites
The essential prerequisites required to execute Logstash are:- A working Java runtime environment.
- An ElasticSearch instance.
Installing Java
To install OpenJDK on FreeBSD you can use pkg to install a ready-to-use binary package:# pkg install openjdk
Currently, this command will install an instance of OpenJDK v. 7 in both FreeBSD 9 and 10. If you'd rather install a different version, you can search the available packages and pick the one you prefer (command output has been filtered for brevity):
# pkg search openjdk
openjdk-7.60.19,1
openjdk6-b31_3,1
openjdk8-8.5.13_7
# pkg install openjdk8-8.5.13_7
Installing ElasticSearch
Logstash includes an embedded ElasticSearch instance you can use for standalone installations (see my previous post for an introductory view on Logstash operation modes). The required configuration to bootstrap the embedded ElasticSearch instance and to have Logstash use it as its outputs is described in the following sections.Although simpler from the standpoint of the configuration, Logstash installations using separate ElasticSearch instances are out of the scope of this post.
Installing Logstash
Logstash installation procedure is fairly simple since it is distributed as a tarball:- Download Logstash from the official website.
- Extract the tarball in the designated installation directory (my personal suggestion is to avoid /usr/local because it is used by ports and to use /opt instead).
Creating an rc.d Script
An rc.d script is required in a BSD system to register a service, define its configuration and have the rc framework manage its lifetime. The following script can be used as is or as a starting point to customise your own. If used as is, be aware that the script uses the following default values:- Installation directory: ${logstash14_home="/opt/logstash-1.4.1"}
- Configuration file path: ${logstash14_config="/usr/local/etc/${name}/${name}.conf"}
- ElasticSearch data directory: ${logstash14_elastic_datadir="/var/db/logstash14"}
- Java home: ${logstash14_java_home="/usr/local/openjdk6"}
You can override any of the supported configuration values in the /etc/rc.conf file. If, for example, you want to use an alternate Java home path, just add the following line to /etc/rc.conf setting the desired value:
logstash14_java_home="/usr/local/openjdk7"
# service logstash14 onestart
To stop it, use:
# service logstash14 onestop
To help troubleshooting any problem you might find you can enable the Logstash log, setting the logstash14_log variable to YES in the /etc/rc.conf file:
logstash14_log="YES"
The log file location is specified by the logstash14_log_file variable, whose default value is set by the service rc file (only the relevant lines are shown):
name=logstash14
logdir="/var/log"
: ${logstash14_log_file="${logdir}/${name}.log"}
The log file location can be overridden setting the logstash14_log_file variable in the /etc/rc.conf file.
Note that the rc script described above does not enable the Logstash service:logstash14_java_home="/usr/local/openjdk7"
Testing the Service
To test the Logstash service, the following command can be used:# service logstash14 onestart
To stop it, use:
# service logstash14 onestop
To help troubleshooting any problem you might find you can enable the Logstash log, setting the logstash14_log variable to YES in the /etc/rc.conf file:
logstash14_log="YES"
The log file location is specified by the logstash14_log_file variable, whose default value is set by the service rc file (only the relevant lines are shown):
name=logstash14
logdir="/var/log"
: ${logstash14_log_file="${logdir}/${name}.log"}
The log file location can be overridden setting the logstash14_log_file variable in the /etc/rc.conf file.
Enabling the Service
: ${logstash14_enable="NO"}
If everything works, you can enable the Logstash service just adding the following line to /etc/rc.conf:
logstash14_enable="YES"