Fluentd requires Ruby 1.9.3 or newer, along with bundler. We'll install Ruby and additional dependencies first.
Update the package list:
sudo apt updateInstall prerequisites:
sudo apt install -y git build-essential libssl-dev zlib1g-dev libjemalloc-devInstall Ruby: To get the latest stable Ruby version, use the following:
sudo apt install -y ruby-fullVerify the installation by running:
ruby -vInstall Bundler:
sudo gem install bundlerClone the Fluentd GitHub repository:
git clone https://github.com/fluent/fluentd.git
cd fluentdCheck out the stable branch (the latest stable version is in v1.x rather than v0.12, which is outdated):
git checkout v1.17Install gem dependencies:
bundle installIf you get any errors, you can configure Bundler to install gems to a directory in your home folder instead. This avoids permission issues by keeping the installation local to your user account.
Set up Bundler to install gems in your home directory:
bundle config set path 'vendor/bundle'Install the gems:
bundle install --path vendor/bundleRun the build command to create the Fluentd gem package:
bundle exec rake buildThis should create a .gem file in the pkg directory (e.g., pkg/fluentd-xxx.gem).
Install the Fluentd gem:
gem install pkg/fluentd-xxx.gemReplace xxx with the specific version number of the Fluentd gem file that was created.
Set up a sample configuration:
fluentd --setup ./fluentThis creates a basic directory structure with a sample configuration file in ./fluent/fluent.conf.
Run Fluentd with the sample configuration:
fluentd -c ./fluent/fluent.conf -vv &The -vv flag enables verbose output, which is useful for verifying that Fluentd runs without issues.
Send a test message to Fluentd:
echo '{"json":"message"}' | fluent-cat debug.testIf everything is working, Fluentd should output a log message similar to:
[timestamp] debug.test: {"json":"message"}
After confirming Fluentd is working, the next steps are to set it up as your log accumulator:
Edit the fluent.conf file to set up Fluentd to accept logs from your microservices, and configure it to forward logs to Apache Kafka. Fluentd has a Kafka output plugin that you can use to send logs to Kafka. You can install it by running:
sudo fluent-gem install fluent-plugin-kafka- Set up an input plugin to receive logs (e.g., in_forward for receiving JSON logs from each microservice)
- Configure an output plugin to send logs to Kafka