Skip to content

Instantly share code, notes, and snippets.

@JCotton1123
Created April 1, 2019 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCotton1123/0daa655a02083849d2462697484e1621 to your computer and use it in GitHub Desktop.
Save JCotton1123/0daa655a02083849d2462697484e1621 to your computer and use it in GitHub Desktop.
Fluentd setup for Ubuntu
# Install dependencies
apt-get update; apt-get install -y build-essential ruby2.5-dev
gem install bundler --version 1.16.1
# Install fluentd
mkdir /opt/fluentd
pushd .; cd /opt/fluentd
cat <<EOD > Gemfile
source "https://rubygems.org"
gem "fluentd", "1.2.3"
gem "fluent-plugin-secure-forward", "0.4.5"
gem "fluent-plugin-record-reformer", "0.9.1"
gem "fluent-plugin-kubernetes_metadata_filter", "2.1.2"
gem "fluent-plugin-kinesis", "2.1.1"
gem "fluent-plugin-json-parser", "0.0.3"
gem "json", "2.1.0"
gem "oj", "3.6.5"
EOD
bundle install --path vendor/bundle
# Configure fluentd
cat <<'EOD' > fluent.conf
## match tag=debug.** and dump to console
<match debug.**>
@type stdout
@id stdout_output
</match>
# INSTANCEID
EOD
instanceid=$(wget --proxy off -qO- http://169.254.169.254/latest/meta-data/instance-id/ | tr -d 'i-')
sed -i "s/INSTANCEID/$instanceid/g" fluent.conf
# Setup service
cat <<EOD > /etc/systemd/system/fluentd.service
[Install]
WantedBy=multi-user.target
[Service]
ExecStart=/usr/local/bin/bundle exec fluentd -c /opt/fluentd/fluent.conf
Restart=on-failure
Type=simple
User=nobody
WorkingDirectory=/opt/fluentd
[Unit]
Description=Run fluentd
After=network-online.target
EOD
systemctl daemon-reload
systemctl enable fluentd
systemctl start fluentd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment