Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@ vagrant-elasticsearch-puppet
============================

Creates a multi-node elasticsearch cluster using Vagrant and puppet

In order to create more nodes, edit the Vagrantfile for server count

```
server_count = 2
```

Current ElasticSearch version used is 1.3 based on the Elasticsearch supported Repo for Centos

### Usage

```
vagrant up
curl localhost:9200
```
*Note that if multiple nodes have been created, they will be forwarded to localhost:9201, localhost:9202, etc.*
9 changes: 5 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ seeds = ""
end
servers << {'name' => name,
'ip' => ip,
'num' => i.to_s
'num' => i.to_s,
'port' => (i + 9200).to_s
}
end

Expand All @@ -26,18 +27,18 @@ Vagrant.configure("2") do |config2|
servers.each do |server|
config2.vm.define server['name'] do |config|

config.vm.box = "Centos6_4"
config.vm.box = "centos"
config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box"

config.vm.hostname = server['name']
config.vm.network :private_network, ip: server['ip']
config.vm.network "forwarded_port", guest: 9200, host: server['port']
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end

config.vm.provision :puppet do |puppet|
# puppet.options = "--verbose --debug"
puppet.facter = { "esversion" => "0.19.10", "seeds" => seeds }
puppet.facter = { "seeds" => seeds }
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "elasticsearchnode.pp"
Expand Down
10 changes: 6 additions & 4 deletions puppet/manifests/elasticsearchnode.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class{ 'elasticsearch':
version => "$esversion",
seeds => "$seeds"
}
# TODO: Classifying the nodes allows future provision for the full ELK stack to be provisioned. This should at some point be part of the Vagrant setup
node 'default' {
class {'elasticsearch':
seeds => "$seeds",
}
}
110 changes: 28 additions & 82 deletions puppet/modules/elasticsearch/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,100 +1,46 @@
class elasticsearch($version = "0.19.10", $seeds = "") {

class elasticsearch($seeds = "") {
$es_version = "1.3"
# As good practice just incase there are any exec statements or cache directories required
Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

$tmpDir = "/tmp/elasticsearch"

package { 'java-1.6.0-openjdk':
ensure => present,
}
->
package { 'unzip':
ensure => present,
}
->

file { "$tmpDir":
ensure => directory,
}
->
user { 'elasticsearch':
ensure => present,
uid => '507',
home => "/usr/local/share/elasticsearch-$version",
}
->
exec { 'es-download-tarball':
command => "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$version.tar.gz -O elasticsearch.tar.gz",
cwd => "$tmpDir",
creates => "$tmpDir/elasticsearch.tar.gz"
}
->
exec { 'es-untar':
command => 'tar -xf elasticsearch.tar.gz',
cwd => "$tmpDir",
creates => "$tmpDir/elasticsearch-$version"
}
->
exec { 'es-move-binaries':
command => "cp -rp elasticsearch-$version /usr/local/share",
cwd => "$tmpDir",
creates => "/usr/local/share/elasticsearch-$version",
}
->
exec { 'es-download-servicewrapper':
command => 'curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz',
cwd => "$tmpDir",
unless => "ls | grep servicewrapper",
}
->
exec { 'es-move-servicewrapper':
command => "cp -rp *servicewrapper*/service /usr/local/share/elasticsearch-$version/bin/",
cwd => "$tmpDir",
creates => "/usr/local/share/elasticsearch-$version/bin/service",

# Set up yum repo for elastic search as this is now supported
file { "/etc/yum.repos.d/elasticsearch.repo":
content => template('elasticsearch/elasticsearch.repo.erb'),
}
->
exec { 'es-install-servicewrapper':
command => "/usr/local/share/elasticsearch-$version/bin/service/elasticsearch install && touch /usr/local/share/elasticsearch-$version/bin/service/service.installed",
creates => "/usr/local/share/elasticsearch-$version/bin/service/service.installed",

# Note that elasticsearch 1.3 onwards only supports Java 7
# Verify that update-alternatives is used just in case there is a version mismatch
# Tested against a base box with no issues

package { ["java-1.7.0-openjdk","elasticsearch"]:
ensure => present,
require => File["/etc/yum.repos.d/elasticsearch.repo"],
}
->
file { "/usr/local/share/elasticsearch-$version/config/elasticsearch.yml":

file { "/etc/elasticsearch/elasticsearch.yml":
content => template('elasticsearch/elasticsearch.yml.erb'),
require => Package['elasticsearch'],
}
->
exec { 'es-servicewrapper-runasuser':
command => "sed -i -e 's/#RUN_AS_USER=/RUN_AS_USER=elasticsearch/' /usr/local/share/elasticsearch-$version/bin/service/elasticsearch",
onlyif => "cat /usr/local/share/elasticsearch-$version/bin/service/elasticsearch | grep '#RUN_AS_USER'",
}
->
exec { 'es-servicewrapper-ulimit':
command => "sed -i -e 's/#ULIMIT_N=/ULIMIT_N=64000/' /usr/local/share/elasticsearch-$version/bin/service/elasticsearch",
onlyif => "cat /usr/local/share/elasticsearch-$version/bin/service/elasticsearch | grep '#ULIMIT_N'",
}
->

file { '/etc/security/limits.d/80-nofile.conf':
content => template('elasticsearch/80-nofile.conf')
}
->
exec { 'es-install-head-plugin':
command => "/usr/local/share/elasticsearch-$version/bin/plugin -install mobz/elasticsearch-head",
creates => "/usr/local/share/elasticsearch-$version/plugins/head",
content => template('elasticsearch/80-nofile.conf'),
require => Package['elasticsearch'],
}
->
exec { 'es-install-paramedic-plugin':
command => "/usr/local/share/elasticsearch-$version/bin/plugin -install karmi/elasticsearch-paramedic",
creates => "/usr/local/share/elasticsearch-$version/plugins/paramedic",
}
->
exec { 'es-chown-everything':
command => "chown -R elasticsearch:elasticsearch /usr/local/share/elasticsearch-$version/",
}
->
service { 'elasticsearch':

service { 'elasticsearch':
ensure => running,
subscribe => File['/etc/elasticsearch/elasticsearch.yml'],
require => Package['elasticsearch'],
}
->

service { 'iptables':
ensure => stopped, #HACK! use the puppet firewall module to manage iptables
require => Service['elasticsearch'],
}

}
7 changes: 7 additions & 0 deletions puppet/modules/elasticsearch/templates/elasticsearch.repo.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[elasticsearch-<%= @es_version %>]
name=Elasticsearch repository for <%= @es_version %>.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/<%= @es_version %>/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1