-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_through_puppet.pp
240 lines (187 loc) · 5.62 KB
/
install_through_puppet.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# MAKE SURE YOU SET A UNIQUE NAME FOR THE ELASTICSEARCH CLUSTER:
$ES_CLUSTER = ""
if $ES_CLUSTER==undef {
fail("You need to define a unique name to the ES_CLUSTER variable")
}
$LOGSTASH_VER = "1.5.4"
$ES_VER = "1.7.2"
$KIBANA_VER = "4.1.2"
$INSTALL_DIR = "/elk"
$DOWNLOAD_DIR = "/tmp"
$LOGSTASH_CONTENT = "
input {
redis {
host => \"127.0.0.1\"
type => 'redis'
data_type => 'list'
key => 'logstash'
}
syslog {
tags => [ 'syslogmessage' ]
type => syslog
}
tcp {
port => 8888
type => listentcp
tags => [ 'tcpmessage' ]
}
}
output {
stdout { }
elasticsearch {
cluster => \"$ES_CLUSTER\"
}
}"
$LOGSTASH_INIT = "
# logstash - agent instance
#
description 'logstash agent'
start on virtual-filesystems
stop on runlevel [06]
# Respawn it if the process exits
respawn
## We're setting high here, we'll re-limit below.
#limit nofile 65550 65550
setuid root
setgid root
# You need to chdir somewhere writable because logstash needs to unpack a few
# temporary files on startup.
console log
script
# Defaults
LS_HOME=$INSTALL_DIR/logstash-$LOGSTASH_VER
LS_CONF_DIR=/etc/logstash/logstash.conf
LS_OPEN_FILES=16384
LS_NICE=19
LS_OPTS=\"\"
# Override our defaults with user defaults:
[ -f /etc/default/logstash ] && . /etc/default/logstash
# Reset filehandle limit
ulimit -n \${LS_OPEN_FILES}
cd \"\${LS_HOME}\"
# Export variables
export PATH HOME JAVA_OPTS LS_HEAP_SIZE LS_JAVA_OPTS LS_USE_GC_LOGGING
test -n \"\${JAVACMD}\" && export JAVACMD
exec nice -n \${LS_NICE} $INSTALL_DIR/logstash-$LOGSTASH_VER/bin/logstash agent -f \"\${LS_CONF_DIR}\"
end script
"
$KIBANA_INIT = "
# kibana init file
#
description 'kibana service'
start on virtual-filesystems
stop on runlevel [06]
# Respawn it if the process exits
respawn
## We're setting high here, we'll re-limit below.
#limit nofile 65550 65550
setuid root
setgid root
# You need to chdir somewhere writable because logstash needs to unpack a few
# temporary files on startup.
console log
script
exec $INSTALL_DIR/kibana-$KIBANA_VER/bin/kibana
end script
"
file { "elk-dir":
name => $INSTALL_DIR,
ensure => "directory",
}
file { "/etc/logstash":
ensure => "directory",
}
# install java
package { "openjdk-7-jre" :
ensure => present,
require => File["elk-dir"],
}
package { "redis-server" :
ensure => present,
require => File["elk-dir"],
}
#
# LOGSTASH
exec { "download-logstash" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "curl https://download.elastic.co/logstash/logstash/logstash-$LOGSTASH_VER.tar.gz | tar xz -C $INSTALL_DIR",
unless => "ls $INSTALL_DIR/logstash-$LOGSTASH_VER",
require => File['elk-dir'],
}
file { "/etc/init/logstash.conf" :
ensure => present,
content => $LOGSTASH_INIT,
require => Exec['download-logstash'],
notify => Service['logstash'],
}
service { 'logstash' :
ensure => running,
require => File['/etc/init/logstash.conf'],
}
# ELASTICSEARCH
exec { "download-elasticsearch" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "wget -O $DOWNLOAD_DIR/elasticsearch-$ES_VER.deb https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ES_VER.deb",
unless => "ls $DOWNLOAD_DIR/elasticsearch-$ES_VER.deb",
}
exec { "install-elasticsearch" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "dpkg -i $DOWNLOAD_DIR/elasticsearch-$ES_VER.deb",
unless => "dpkg -l elasticsearch",
require => [Exec['download-elasticsearch'], Package['openjdk-7-jre']],
}
exec { "uncomment-cluster-name" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "echo cluster.name: elasticsearch >> /etc/elasticsearch/elasticsearch.yml",
unless => "egrep '^cluster.name:' /etc/elasticsearch/elasticsearch.yml",
require => Exec['install-elasticsearch'],
}
exec { "set-cluster-name" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "sed -i.bak 's/cluster.name: .*/cluster.name: $ES_CLUSTER/g' /etc/elasticsearch/elasticsearch.yml",
unless => "egrep '^cluster.name: $ES_CLUSTER' /etc/elasticsearch/elasticsearch.yml",
require => Exec['uncomment-cluster-name'],
}
service { "elasticsearch" :
ensure => running,
require => Exec['set-cluster-name'],
}
# KIBANA
file { "kibana-dir" :
name => "$INSTALL_DIR/kibana-$KIBANA_VER",
ensure => directory,
require => File['elk-dir'],
}
exec { "download-kibana" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "curl https://download.elastic.co/kibana/kibana/kibana-$KIBANA_VER-linux-x64.tar.gz | tar xz --strip-components 1 -C $INSTALL_DIR/kibana-$KIBANA_VER",
unless => "ls $INSTALL_DIR/kibana-$KIBANA_VER/bin/kibana",
require => File['kibana-dir'],
}
file { "/etc/init/kibana.conf" :
ensure => present,
content => $KIBANA_INIT,
require => Exec['download-kibana'],
notify => Service['kibana'],
}
service { "kibana" :
ensure => running,
require => File['/etc/init/kibana.conf'],
}
service { "redis-server" :
ensure => running,
require => Package['redis-server'],
}
exec { "configure-redis" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' /etc/redis/redis.conf",
unless => "grep 'bind 0.0.0.0' /etc/redis/redis.conf",
notify => Service['redis-server'],
require => Package['redis-server'],
}
exec { "configure-logstash" :
path => "/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin",
command => "echo '$LOGSTASH_CONTENT' > /etc/logstash/logstash.conf",
unless => "ls /etc/logstash/logstash.conf",
require => Exec['download-logstash'],
}