rackspace-cookbooks / elkstack

Elasticsearch, logstash, and kibana stack
Other
81 stars 54 forks source link

elkstack

Elasticsearch, Logstash, and Kibana stack. Due to the recommendations of the community, we are not using the embedded elasticsearch functionality of logstash at this point. This cookbook provides recipes for all three components, along with wrapper recipes such as single or cluster to facilitate different use cases.

This stack's design is intended for one or many standalone nodes, with a full stack of elasticsearch, logstash, and kibana. The only difference between one and many nodes is that elasticsearch is clustered together. Data dispatched to Logstash on a particular node will use the local elasticsearch transport interface to index those logs to the node (and thus, the cluster). HTTP traffic dispatched to Kibana on port 80 on any node will also use the local elasticsearch HTTP interface to fetch and manipulate data.

Please read the individual recipe summaries to understand what each recipe does, as well as what each wrapper recipe is actually wrapping. As much as possible, upstream attributes have been exposed/overriden for our needs.

Things you should know

There exists a make-lumberjack-key.sh to help you make this. For Go 1.3+, you may be required by the standard libraries to create a SAN cert as described here.

Changelog

See CHANGELOG.md for additional information about changes to this stack over time.

Supported Platforms

Ubuntu 12.04

Ubuntu 14.04

CentOS 6.5

Attributes

Key Type Description Default
['elkstack']['config']['logstash']['instance_name'] String Default logstash instance name server
['elasticsearch']['discovery']['search_query'] String A query to search for and connect Elasticsearch to cluster nodes (see `attributes/elasticsearch.rb`)
['logstash_forwarder']['config']['files'] Hash See customizing the stack section below. Most logs in `/var/log`
['elkstack']['config']['data_disk']['disk_config_type'] Boolean or String See customizing the stack section below. false
['elkstack']['config']['agent']['enabled'] Boolean Enable/Disable agent functionality true
['elkstack']['config']['cloud_monitoring']['enabled'] Boolean Enable/Disable cloud_monitoring functionality true
['elkstack']['config']['iptables']['enabled'] Boolean Enable/Disable iptables functionality true
['elkstack']['config']['site_name'] String Control the name of the self-signed SSL key and cert in /etc/nginx/ssl kibana
['elkstack']['config']['kibana']['prepare_ssl'] Boolean Enable/disable automatic creation of an SSL certificate and private key and htpassword file for Kibana's nginx reverse-proxy. If disabled, you are responsible for placing these items in the correct location or supplying your own nginx vhost configuration for Kibana. See the `kibana_ssl` recipe for details. true
['elkstack']['config']['kibana']['redirect'] Boolean Enable/Disable nginx redirect for kibana from port 80 to port 443 true
node.run_state['elkstack_kibana_username'] and ['elkstack']['config']['kibana']['username'] String Default username for basic auth for kibana, run_state used first kibana
node.run_state['elkstack_kibana_password'] String Password for basic auth for kibana random from Opscode::OpenSSL::Password
['elkstack']['config']['lumberjack_data_bag'] String Data bag name for lumberjack key and certificate lumberjack
['elkstack']['config']['custom_logstash']['name'] Array of strings See `attributes/logstash.rb` for an explanation of how to use this attribute to populate additional logstash configuration file templates []
['elkstack']['config']['restart_logstash_service'] Boolean Restart logstash if we deploy a custom config file true

Customizing the stack

To override local storage for elasticsearch nodes (the stack will format and mount, as well as configure elasticsearch), set ['elkstack']['config']['data_disk']['disk_config_type'] to custom and provide each storage device and mount point in the following way:

disk_config = {
  'file_system' => 'ext4',
  'mount_options' => 'rw,user',
  'mount_path' => '/usr/local/var/data/elasticsearch/disk1',
  'format_command' => 'mkfs -t ext4 ',
  'fs_check_command' => 'dumpe2fs'
}

node.override['elasticsearch']['data']['devices']['/dev/xvde1'] = disk_config
node.override['elasticsearch']['path']['data'] = disk_config['mount_path']

To add additional logstash configuration to this stack, simply add additional templates in your wrapper cookbook. They should be placed in "#{@basedir}/#{@instance}/etc/conf.d" (see the config provider in the logstash cookbook). If you choose to use logstash-forwarder instead of the regular agent, please see the hash structure in attributes/forwarder.rb for adding additional files for the forwarder to watch and forward, node['logstash_forwarder']['config']['files'].

To override the nginx configuration, simply supply a new template and specify your cookbook using ['kibana']['nginx']['template_cookbook'] and ['kibana']['nginx']['template']. You can also override just the password for the reverse proxy using node.run_state['elkstack_kibana_password'].

To override anything else, set the appropriate node hash (logstash, kibana, or elasticsearch).

Usage

elkstack::default

A simple wrapper recipe that sets up Elasticsearch, Logstash, and Kibana. Also configures an rsyslog sink into logstash on the local box. Everything except Logstash and Kibana is locked down to listen only on localhost.

elkstack::agent

A simple wrapper recipe that sets up a logstash agent on the local box. Also configures an rsyslog sink into logstash on the local box. You need node['elkstack']['config']['agent']['enabled'] set to true if you want to use this recipe (default to true).

elkstack::forwarder

A go-based alternative to the normal agent, configured simply to watch logs forward them directly on to the cluster. This project is in heavy development, and is not publishing releases very often, so the packaged versions may be quite old or buggy. As of the addition of the recipe, the package was almost a year behind current development, but only because there also had been no releases either.

elkstack::elasticsearch

Leans on the upstream elasticsearch/cookbook-elasticsearch cookbook for much of its work. We do override the default set of plugins to be installed, as well as the amount of JVM heap. See attributes/default.rb for those settings.

This recipe also tags the node so that other nodes that run this recipe can discover it, and configure Elasticsearch appropriately to join their cluster. It uses a tag, the current chef environment, and the cluster name as the default search criteria.

Most of this is configurable using the upstream Elasticsearch cookbook's attributes, including the chef search itself. There is not an easy toggle to turn off the search, however. Enables iptables rules if node['elkstack']['config']['iptables']['enabled'] is not nil.

elkstack::logstash

Leans on the upstream lusis/chef-logstash cookbook for much of its work. We do override the default set of plugins to be installed, as well as the amount of JVM heap. See attributes/default.rb for those settings.

elkstack::kibana

Leans on the upstream lusis/chef-kibana cookbook for most of its work. Sets up an nginx site for kibana by default. By default, it also does not pass through most of the http paths directly to elasticsearch (whitelist).

elkstack::newrelic

Validates if there is a newrelic license set and based on that, see if the node is tagged as 'elkstack' and creates a file with elasticsearch details. Installs python, pip and setuptools packages in order to support newrelic_meetme_plugin

elkstack::acl

Adds cluster node basic iptables rules and cluster iptables rules if appropriate attributes are set.

elkstack::agent_acl

Adds agent node basic iptables rules.

elkstack::disk_setup

Look for node['elkstack']['config']['data_disk']['disk_config_type'] to be truthy, and configure the upstream elasticsearch cookbook to format, mount, and use devices appropriately.

elkstack::*_monitoring

These correspond with the recipes above, and just provide a way to pull out the monitoring work to make the original recipes cleaner.

Miscellaneous

The wrapper recipes are single and cluster. These change attributes and then invoke elasticsearch, logstash, kibana, and rsyslog. Finally, there are utility recipes like java and newrelic (not invoked otherwise), as well as acl which is called by _base if node['elkstack']['config']['iptables']['enabled'].

Contributing

See CONTRIBUTING.

Authors

Author:: Rackspace (devops-chef@rackspace.com)

License

# Copyright 2014, Rackspace Hosting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#