Project

General

Profile

Support #437

Updated by Daniel Curtis over 10 years ago

I've decided to centralize all the logs generated by a client's production systems to a syslog server and after assessing a bunch of products, I am not working with Fluentd. 

 The platform chosen to run Fluentd is FreeBSD inside a Jail (9.2-RELEASE at the time), a rock-solid and very well documented UNIX-like operating system. Besides, it also ships a production-ready ZFS implementation which always comes handy in the data center. FreeBSD-9.2 currently has the _sysutils/rubygem-fluentd_ is available in the ports tree, however the package has been marked as BROKEN, and is not available using pkg. So I will document how to install Fluentd with ElasticSearch and Kibana. This guide assumes that a user has been created for fluentd, using the @adduser@ command. 

 h2. Prerequisites 

 * In order to build Fluentd, there are are a few packages needed: 
 <pre> 
 pkg install git ruby ruby19-gems rubygem-bundler 
 </pre> 

 h2. Installation of Fluentd 

 * Fetch the Fluentd source code: 
 <pre> 
 su - fluentd 
 git clone https://github.com/fluent/fluentd.git 
 cd fluentd 
 </pre> 

 * Build and Install 
 <pre> 
 su - 
 bundle install 
 </pre> 
 > Fetching gem metadata from https://rubygems.org/......... 
 > ... 
 > Your bundle is complete! 
 > Use `bundle show [gemname]` to see where a bundled gem is installed. 
 <pre> 
 bundle exec rake build 
 </pre> 
 > fluentd xxx built to pkg/fluentd-xxx.gem. 
 <pre> 
 gem install pkg/fluentd-xxx.gem 
 </pre> 

 h3. Test Run 

 * Run the following commands to to confirm that Fluentd was installed successfully: 
 <pre> 
 fluentd --setup ./fluent 
 fluentd -c ./fluent/fluent.conf -vv & 
 echo '{"json":"message"}' | fluent-cat debug.test 
 </pre> 

 The last command sends Fluentd a message ‘{“json”:”message”}’ with a “debug.test” tag. If the installation was successful, Fluentd will output the following message: 
 > 2011-07-10 16:49:50 +0900 debug.test: {"json":"message"} 

 h2. Install ElasticSearch 

 * h2. Install ElasticSearch: 
 <pre> 
 pkg install elasticsearch 
 </pre> 
 #* Enable ElasticSearch at boot 
 <pre> 
 echo 'elasticsearch_enable="YES"' >> /etc/rc.conf 
 </pre> 
 #* Start ElasticSearch 
 <pre> 
 service elasticsearch start 
 </pre> 

 h3. Securing Elasticsearch 

 * Up to version 1.2, Elasticsearch's dynamic scripting capability was enabled by default. Since this tutorial sets up the Kibana dashboard to be accessed from the public Internet, let's disable dynamic scripting by appending the following line at the end of the ElasticSearch configuration file: 
 <pre> 
 vi /etc/elasticsearch/elasticsearch.yml 
 </pre> 
 > script.disable_dynamic: true 

 * Restart Elasticsearch: 
 <pre> 
 service elasticsearch restart 
 </pre> 

 h2. Installing and Configuring Kibana 

 h3. Getting Kibana 

 * Move to your home directory: 
 <pre> 
 cd ~ 
 </pre> 

 * We will download Kibana as follows: 
 <pre> 
 curl -L https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz | tar xzf - 
 cp -r kibana-3.1.0 /usr/local/kibana 
 </pre> 

 h3. Configuring Kibana 

 Since Kibana will use port 80 to talk to Elasticsearch as opposed to the default port 9200, Kibana's config.js must be updated. 

 Open Kibana configuration file and look for the following line: 
 <pre> 
 vi /usr/share/kibana-3.1.0/config.js 
 </pre> 
 > elasticsearch: "http://"+window.location.hostname+":9200", 

 and *replace it* with the following line: 

 > elasticsearch: "http://"+window.location.hostname+":80", 

 h2. Installing and Configuring Nginx (Proxy Server) 

 We will use Nginx as a proxy server to allow access to the dashboard from the Public Internet (with basic authentication). 

 * Install Nginx as follows: 
 <pre> 
 pkg install nginx 
 </pre> 

 Kibana provides a good default nginx.conf, which we will modify slightly. 

 * First, install the configuration file as follows: 
 <pre> 
 wget https://assets.digitalocean.com/articles/fluentd/nginx.conf 
 sudo cp nginx.conf /etc/nginx/sites-available/default 
 </pre> 

 * Note: The original file is from this Kibana GitHub repository. 

 Then, edit /usr/local/etc/nginx/nginx.conf as follows: 
 <pre> 
 # 
 # Nginx proxy for Elasticsearch + Kibana 
 # 
 # In this setup, we are password protecting the saving of dashboards. You may 
 # wish to extend the password protection to all paths. 
 # 
 # Even though these paths are being called as the result of an ajax request, the 
 # browser will prompt for a username/password on the first request 
 # 
 # If you use this, you'll want to point config.js at http://FQDN:80/ instead of 
 # http://FQDN:9200 
 # 
 server { 
  listen                  *:80 ; 
  server_name             localhost; 
  access_log              /var/log/nginx/kibana.log; 
  location / { 
    root    /usr/share/kibana-3.1.0; 
    index    index.html    index.htm; 
  } 
 </pre> 

 * Finally, restart nginx as follows: 
 <pre> 
 service nginx restart 
 </pre> 

 Now, you should be able to see the generic Kibana dashboard at your server's IP address or domain, using your favorite browser. 

 h2. Installing Fluentd Plugins 

 We need a couple of plugins: 
 # *out_elasticsearch*: this plugin lets Fluentd to stream data to Elasticsearch. 
 # *outrecordreformer*: this plugin lets us process data into a more useful format. 

 * The following commands install both plugins, it requires libcurl 
 <pre> 
 pkg install curl fpc-libcurl 
 </pre> 

 * Next, we configure Fluentd to listen to syslog messages and send them to Elasticsearch. Open /etc/td-agent/td-agent.conf and add the following lines at the top of the file: 
 <pre> 
 <source> 
  type syslog 
  port 5140 
  tag    system 
 </source> 
 <match system.*.*> 
  type record_reformer 
  tag elasticsearch 
  facility ${tag_parts[1]} 
  severity ${tag_parts[2]} 
 </match> 
 <match elasticsearch> 
  type copy 
  <store> 
    type stdout 
  </store> 
  <store> 
  type elasticsearch 
  logstash_format true 
  flush_interval 5s #debug 
  </store> 
 </match> 
 </pre> 

 h2. Starting Fluentd 

 * Start Fluentd with the following command: 
 <pre> 
 su - fluentd 
 cd ~/fluentd 
 fluentd -c ./fluent/fluent.conf -vv & 
 </pre> 

 h2. Forwarding rsyslog Traffic to Fluentd 

 Ubuntu 14.04 ships with rsyslogd. It needs to be reconfigured to forward syslog events to the port Fluentd listens to (port 5140 in this example). 

 * Open the rsyslog configuration file and add the following line at the top 
 <pre> 
 sudo vi/etc/rsyslog.conf 
 </pre> 
 <pre> 
 *.* @127.0.0.1:5140 
 </pre> 

 * After saving and exiting the editor, restart rsyslogd as follows: 
 <pre> 
 sudo service rsyslog restart 
 </pre> 

 h2. Setting Up Kibana Dashboard Panels 

 Kibana's default panels are very generic, so it's recommended to customize them. Here, we show two methods. 

 h3. *Method 1*: Using a Template 

 * The Fluentd team offers an alternative Kibana configuration that works with this setup better than the default one. To use this alternative configuration, run the following command: 
 <pre> 
 wget -O default.json https://assets.digitalocean.com/articles/fluentd/default.json 
 sudo cp default.json /usr/share/kibana-3.1.0/app/dashboards/default.json 
 </pre> 

 Note: The original configuration file is from the author's GitHub gist. 

 If you refresh your Kibana dashboard home page at your server's URL, Kibana should now be configured to show histograms by syslog severity and facility, as well as recent log lines in a table. 

 h3. *Method 2*: Manually Configuring 

 Go to your server's IP address or domain to view the Kibana dashboard. 

 There are a couple of starter templates, but let's choose the blank one called *Blank Dashboard*. 

 Next, click on the *+ ADD A ROW* button on the right side of the dashboard. A configuration screen for a new row (a row consists of one or more panels) should show up. Enter a title, press the *Create Row* button, followed by *Save*. This creates a row. 

 When an empty row is created, Kibana shows the prompt Add panel to empty row on the left. Click this button. It takes you to the configuration screen to add a new panel. Choose histogram from the dropdown menu.  

 There are many parameters to configure for a new histogram, but you can just scroll down and press the Save button. This creates a new panel. 

 h2. Resources 

 http://docs.fluentd.org/articles/install-from-source 
 https://www.digitalocean.com/community/tutorials/elasticsearch-fluentd-and-kibana-open-source-log-search-and-visualization 

Back