Skip to content

Instantly share code, notes, and snippets.

@egobude
Created May 26, 2014 13:12
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 egobude/a6ce7e196908eb70a183 to your computer and use it in GitHub Desktop.
Save egobude/a6ce7e196908eb70a183 to your computer and use it in GitHub Desktop.
Vagrant Logstash
==============================
This vagrant file is intended to be used with the vmware fusion provider and as such has been configured and tested with a vmware base box. It also uses the berkshelf vagrant plugin in order to handle loading the necessary chef cookbooks for configuring this machine.
The machine serves up an instance of elasticsearch, logstash and kibana for use with testing.
Kibana is available at:
http://localhost:8383
Elasticsearch is available at:
http://localhost:9200
The included logstash.conf can be run locally and uses the logstash plugin elasticsearch_http to forward to the elasticsearch instance in the vagrant vm. Several file monitors have been setup to capture log data, and additional stdin has been setup to route log messages to elasticsearch. The latter, stdin, makes it easy to test and verify that the image is running correctly.
Those on macs can use brew to install logstash and then run the agent like so:
$: logstash agent -f ./logstash.conf
# Encoding: utf-8
cookbook 'yum'
cookbook 'vim'
cookbook 'curl'
cookbook 'nginx'
cookbook 'logstash', git: 'git://github.com/lusis/chef-logstash.git'
cookbook 'elasticsearch', git: 'git://github.com/elasticsearch/cookbook-elasticsearch.git'
input {
stdin { }
file {
type => "apache-access"
start_position => "end"
path => "/var/log/apache2/access_log"
}
file {
type => "apache-error"
start_position => "end"
path => "/var/log/apache2/error_log"
}
file {
type => "php-error"
start_position => "end"
path => "/var/log/apache2/php_errors.log"
}
file {
type => "app"
start_position => "end"
format => "plain"
path => "/var/log/app.log"
charset => "UTF-8"
}
file {
type => "backend"
start_position => "end"
format => "plain"
path => "/var/log/backend.log"
charset => "UTF-8"
}
}
filter {
if [type] == "apache-access" or [type] == "apache-error" {
grok {
match => [ "message", "%{COMBINEDAPACHELOG}" ]
}
}
}
output {
stdout {
debug => true
codec => rubydebug
}
elasticsearch_http {
host => "localhost"
port => "9200"
}
}
# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion'
# This Vagrantfile uses the berkshelf plugin to install the cookbook dependencies, install it by:
# $: vagrant plugin install vagrant-berkshelf
# This Vagrantfile uses the omnibus plugin to ensure the correct version of chef, install it by:
# $: vagrant plugin install vagrant-omnibus
Vagrant.configure("2") do |config|
config.omnibus.chef_version = :latest
config.vm.box = 'centos65'
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/vmware/opscode_centos-6.5_chef-provisionerless.box"
config.vm.hostname = "logstash"
config.vm.provider "vmware_fusion" do |v, override|
v.vmx['memsize'] = '1024'
v.vmx['numvcpus'] = '1'
end
config.vm.network :forwarded_port, guest: 80, host: 8383
config.vm.network :forwarded_port, guest: 9200, host: 9200
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.json = {
:kibana => {
:es_server => "127.0.0.1",
:webserver_listen => "0.0.0.0",
:webserver_aliases => ["logstash", "localhost", "127.0.0.1"],
:nginx => {
:enable_default_site => false
}
}
}
chef.run_list = [
"recipe[vim]",
"recipe[curl]",
"recipe[java]",
"recipe[logstash]",
"recipe[elasticsearch]",
"recipe[nginx]",
"recipe[kibana]"
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment