Skip to content

Commit 2b96bb3

Browse files
committed
Refactoring
kibanaをfluent pluginとしてインストールするよう変更。 td-agentとElasticsearchをぞれぞれ別recipeに分離 .kitchen.ymlを追加
1 parent 9d77673 commit 2b96bb3

File tree

14 files changed

+170
-147
lines changed

14 files changed

+170
-147
lines changed

.kitchen.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
driver:
3+
name: vagrant
4+
driver_config:
5+
require_chef_omnibus: true
6+
7+
provisioner:
8+
name: chef_solo
9+
10+
platforms:
11+
- name: ubuntu-12.04
12+
driver_config:
13+
box: opscode-ubuntu-12.04
14+
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
15+
16+
suites:
17+
- name: default
18+
run_list:
19+
- recipe[apt]
20+
- recipe[elasticsearch-aio::default]
21+
attributes:

Berksfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
cookbook 'apt'
2-
cookbook 'nginx',
1+
site :opscode
2+
3+
metadata
4+
35
cookbook 'td-agent',
46
:git => '[email protected]:treasure-data/chef-td-agent.git'

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'berkshelf'
4+
gem 'foodcritic', '~> 3.0.3'
5+
gem 'rubocop'
6+
gem 'strainer'
7+
gem 'serverspec', :group => :integration
8+
gem 'test-kitchen', :group => :integration
9+
gem 'kitchen-vagrant', :group => :integration
10+
gem 'pry'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
es-with-fluentd Cookbook
1+
elasticsearch-aio Cookbook
22
========================
33

44
Deploy elasticsearch with Kibana3 and Fluentd.

attributes/default.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
es = default[:es_with_fluentd]
1+
es = default[:elasticsearch_aio]
22
es[:es_base_url] = "https://download.elasticsearch.org/elasticsearch/elasticsearch/"
33
es[:es_deb_filename] = "elasticsearch-0.90.7.deb"
44

5-
es[:fluentd][:in_forward][:enabled] = "true"
6-
es[:fluentd][:in_forward][:port] = "25224"
7-
es[:fluentd][:http][:enabled] = "true"
8-
es[:fluentd][:http][:port] = "8888"
5+
es[:td_agent][:in_forward][:enabled] = "true"
6+
es[:td_agent][:in_forward][:port] = "25224"
7+
es[:td_agent][:http][:enabled] = "true"
8+
es[:td_agent][:http][:port] = "8888"
99

10-
es[:nginx][:port] = "28080"
11-
es[:nginx][:server_name] = "elasticsearch.example.com"
10+
es[:kibana][:port] = "28080"
1211
es[:elasticsearch_head][:git] = "https://github.com/mobz/elasticsearch-head.git"
13-
es[:kibana][:zip] = "http://download.elasticsearch.org/kibana/kibana/kibana-latest.zip"
14-
1512
conf = es[:config]
1613

1714
## These attributes are export to elasticsearch.yml.

metadata.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
name 'es_with_fluentd'
1+
name 'elasticsearch-aio'
22
maintainer 'Kazuto Kusama'
33
maintainer_email '[email protected]'
44
license 'All rights reserved'
5-
description 'Installs/Configures Elasticsearch, Fluentd(td-agent), Kibana and Elasticsearch Head'
5+
description 'Installs/Configures Elasticsearch, td-agent, Kibana and Elasticsearch Head'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '0.2.0'
7+
version '0.3.0'
88

99
depends "apt"
1010
depends "td-agent"
11-
depends "nginx"
11+
12+
recipe "elasticsearch-aio", "setup all in one"
13+
recipe "elasticsearch-aio::elasticsearch", "setup elasticsearch and plugins"
14+
recipe "elasticsearch-aio::td-agent", "setup td-agent and plugins"
15+

recipes/default.rb

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,9 @@
11
#
2-
# Cookbook Name:: es-with-fluentd
2+
# Cookbook Name:: elasticsearch-aio
33
# Recipe:: default
44
#
55
# Copyright 2013, Kazuto Kusama @jacopen
66
#
77

8-
include_recipe "apt"
9-
include_recipe "td-agent"
10-
include_recipe "nginx"
11-
12-
config = node[:es_with_fluentd]
13-
14-
%w(openjdk-7-jdk git curl unzip).each do |pkg|
15-
package pkg
16-
end
17-
18-
remote_file "/tmp/#{config[:es_deb_filename]}" do
19-
source config[:es_base_url] + config[:es_deb_filename]
20-
action :create_if_missing
21-
end
22-
23-
dpkg_package "/tmp/#{config[:es_deb_filename]}" do
24-
action :install
25-
end
26-
27-
remote_file "/tmp/kibana-latest.zip" do
28-
source config[:kibana][:zip]
29-
end
30-
31-
bash "extract kibana" do
32-
code "unzip -o /tmp/kibana-latest.zip -d /var/www"
33-
end
34-
35-
git "/var/www/eh" do
36-
repository config[:elasticsearch_head][:git]
37-
action :sync
38-
notifies :restart, "service[nginx]"
39-
end
40-
41-
template "/etc/elasticsearch/elasticsearch.yml" do
42-
notifies :restart, "service[elasticsearch]"
43-
end
44-
45-
template "/etc/td-agent/td-agent.conf" do
46-
notifies :restart, "service[td-agent]"
47-
end
48-
49-
template "/etc/nginx/sites-available/kibana" do
50-
notifies :restart, "service[nginx]"
51-
end
52-
53-
link File.join("/etc/nginx/sites-available/kibana") do
54-
to File.join("/etc/nginx/sites-enabled/kibana")
55-
end
56-
57-
file "/var/log/fluentd-kibana" do
58-
action :touch
59-
owner "td-agent"
60-
group "td-agent"
61-
end
62-
63-
file "/var/log/syslog" do
64-
action :touch
65-
mode "0644"
66-
end
67-
68-
service "elasticsearch" do
69-
supports [:restart]
70-
action :enable
71-
end
72-
73-
service "nginx" do
74-
supports [:restart, :reload]
75-
action :enable
76-
end
77-
78-
service "td-agent" do
79-
supports [:restart, :reload]
80-
action :enable
81-
end
8+
include_recipe "elasticsearch-aio::td-agent"
9+
include_recipe "elasticsearch-aio::elasticsearch"

recipes/elasticsearch.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Cookbook Name:: elasticsearch-aio
3+
# Recipe:: elasticsearch
4+
#
5+
# Copyright 2013, Kazuto Kusama @jacopen
6+
#
7+
8+
include_recipe "elasticsearch-aio::td-agent"
9+
10+
config = node[:elasticsearch_aio]
11+
12+
%w(openjdk-7-jdk git curl unzip).each do |pkg|
13+
package pkg
14+
end
15+
16+
remote_file "/tmp/#{config[:es_deb_filename]}" do
17+
source config[:es_base_url] + config[:es_deb_filename]
18+
action :create_if_missing
19+
end
20+
21+
dpkg_package "/tmp/#{config[:es_deb_filename]}" do
22+
action :install
23+
end
24+
25+
template "/etc/elasticsearch/elasticsearch.yml" do
26+
notifies :restart, "service[elasticsearch]"
27+
end
28+
29+
service "elasticsearch" do
30+
supports [:restart]
31+
action :enable
32+
end

recipes/td-agent.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include_recipe "td-agent"
2+
3+
td_agent_gem "kibana-server" do
4+
version "0.0.2"
5+
plugin true
6+
end
7+
8+
directory "/etc/td-agent/conf.d" do
9+
owner "root"
10+
group "root"
11+
action :create
12+
not_if { File.exist? "/etc/td-agent/conf.d" }
13+
end
14+
15+
directory "/var/log/kibana" do
16+
action :create
17+
owner "td-agent"
18+
group "td-agent"
19+
end
20+
21+
template "/etc/td-agent/td-agent.conf" do
22+
source "td-agent.conf.erb"
23+
owner "root"
24+
group "root"
25+
notifies :restart, "service[td-agent]"
26+
end
27+
28+
template "/etc/td-agent/conf.d/kibana.conf" do
29+
source "kibana.conf.erb"
30+
owner "root"
31+
group "root"
32+
notifies :restart, "service[td-agent]"
33+
end
34+
35+
execute "change permission" do
36+
command "chown -R td-agent: /usr/lib/fluent/ruby/lib/ruby/gems/1.9.1/gems/fluent-plugin-kibana-server-*"
37+
end
38+
39+
service "td-agent" do
40+
supports [:restart, :reload]
41+
action :enable
42+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<% if node[:elasticsearch_aio][:td_agent][:in_forward][:enabled] == "true" %>
2+
<source>
3+
type forward
4+
port <%= node[:elasticsearch_aio][:td_agent][:in_forward][:port] %>
5+
</source>
6+
<% end %>
7+
8+
<% if node[:elasticsearch_aio][:td_agent][:http][:enabled] == "true" %>
9+
<source>
10+
type http
11+
port <%= node[:elasticsearch_aio][:td_agent][:http][:port] %>
12+
</source>
13+
<% end %>
14+
15+
<source>
16+
type tail
17+
format syslog
18+
path /var/log/syslog
19+
tag linux.syslog
20+
pos_file /tmp/syslog.pos
21+
</source>
22+
23+
<match *.*>
24+
index_name fluentd
25+
type_name fluentd
26+
type elasticsearch
27+
include_tag_key true
28+
tag_key @log_name
29+
host localhost
30+
port 9200
31+
logstash_format true
32+
flush_interval 10s
33+
</match>

0 commit comments

Comments
 (0)