OSDN Git Service

add HDP-2.0.6.0 GA support to the hadoop cookbook.
[metasearch/grid-chef-repo.git] / cookbooks / hadoop / recipes / hdp.rb
1 #
2 # Cookbook Name:: hadoop
3 # Recipe:: hdp
4 #
5 # Copyright 2013, whitestar
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 ::Chef::Recipe.send(:include, Commons::PackageUtils)
21
22 ::Chef::Recipe.send(:include, Hadoop::Helper)
23
24 install_root = '/usr/lib/hadoop'
25 conf_dir = '/etc/hadoop/conf'
26
27 daemons = nil
28 conf_files = nil
29
30 daemons_v1 = [
31   'namenode',
32   'datanode',
33   'secondarynamenode',
34   'jobtracker',
35   'tasktracker'
36 ]
37
38 daemons_v2 = [
39   'hdfs-namenode',
40   'hdfs-secondarynamenode',
41   'hdfs-datanode',
42   'yarn-resourcemanager',
43   'yarn-nodemanager',
44   'mapreduce-historyserver'
45 ]
46
47 conf_files_v1 = [
48   'capacity-scheduler.xml',
49   'configuration.xsl',
50   'core-site.xml',
51   'fair-scheduler.xml',
52   'hadoop-env.sh',
53   'hadoop-metrics2.properties',
54   'hadoop-policy.xml',
55   'hdfs-site.xml',
56   'hosts.include',
57   'hosts.exclude',
58   'log4j.properties',
59   'mapred-queue-acls.xml',
60   'mapred-site.xml',
61   'masters',
62   'slaves',
63   # not supported.
64   #'ssl-client.xml',
65   #'ssl-server.xml'
66 ]
67
68 conf_files_v2 = \
69   conf_files_v1 \
70   - [
71     'configuration.xsl',
72     'fair-scheduler.xml',
73     'hadoop-policy.xml',  # missing!?
74     'mapred-queue-acls.xml',
75     'masters'
76   ] \
77   + [
78     # TODO: -> hdp_httpfs recipe. (hadoop-httpfs rpm package)
79     #'httpfs-env.sh',
80     #'httpfs-log4j.properties',
81     #'httpfs-signature.secret',
82     #'httpfs-site.xml',
83     'mapred-env.sh',
84     'yarn-env.sh',
85     'yarn-site.xml'
86   ] 
87
88 version, major_version, middle_version \
89   = parse_hdp_version_number(node['hdp']['version'])
90 equivalent_apache_hadoop_middle_version \
91   = get_equivalent_apache_hadoop_version_of('hdp', node['hdp']['version'])
92
93 users = get_users(major_version)
94 # do not add any hadoop accounts by Chef.
95
96 case major_version
97 when '1'
98   daemons = daemons_v1
99   if middle_version >= '1.3' then
100     daemons.push('historyserver')
101   end
102   conf_files = conf_files_v1
103 when '2'
104   daemons = daemons_v2
105   conf_files = conf_files_v2
106 end
107
108 daemons.each {|daemon|
109   package "hadoop-#{daemon}" do
110     action node['hadoop']['packages']['action']
111   end
112
113   service "hadoop-#{daemon}" do
114     action node['hadoop']['services']['action']
115   end
116 }
117
118 if major_version == '1' then
119   %w{
120     libhdfs
121     native
122     pipes
123   }.each {|native_lib|
124     package "hadoop-#{native_lib}" do
125       action node['hadoop']['packages']['action']
126     end
127   }
128 else
129   # do nothing in the ver. 2
130   # native -> hadoop package
131   # pipes -> hadoop package
132 end
133
134 if node['hadoop']['with_hadoop_lzo'] then
135   %w{
136     lzo
137     lzo-native
138   }.each {|lzo_pkg|
139     package "hadoop-#{lzo_pkg}" do
140       action node['hadoop']['packages']['action']
141     end
142   }
143 end
144
145 if node['hadoop']['io.compression.codec.bzip2.library'] == 'system-native' \
146   && equivalent_apache_hadoop_middle_version >= '2.1' then
147   package get_libbz2_pkg_name do
148     action :install
149   end
150 end
151
152 link node['hadoop']['HADOOP_PREFIX'] do
153   to install_root
154   action [:delete, :create]
155 end
156
157 active_vol_nums = setup_directories(major_version)
158 log "This node active volumes: #{active_vol_nums}"
159
160 alt_conf_path = node['hadoop']['hdp']['alternatives']['hadoop-conf']['path']
161 alt_conf_priority \
162   = node['hadoop']['hdp']['alternatives']['hadoop-conf']['priority']
163 bash 'alternatives_hadoop-conf' do
164   code <<-EOC
165     cp -R /etc/hadoop/conf.empty #{alt_conf_path}
166     alternatives --install #{conf_dir} hadoop-conf #{alt_conf_path} #{alt_conf_priority}
167   EOC
168   creates alt_conf_path
169 end
170
171 tpl_vars = {
172   :active_vol_nums => active_vol_nums
173 }
174 conf_template(conf_dir, equivalent_apache_hadoop_middle_version, conf_files, tpl_vars)
175
176 # with security
177 if node['hadoop']['with_security'] then
178   directory node['hadoop']['this.keytab.dir'] do
179     owner 'root'
180     group 'root'
181     mode '0755'
182     action :create
183     recursive true
184   end
185   
186   case major_version
187   when '1'
188     # task-controller, jsvc
189     package 'hadoop-sbin' do
190       action node['hadoop']['packages']['action']
191     end
192 =begin
193     file "#{install_root}/bin/task-controller" do
194       owner 'root'
195       group users[:mapred][:name]
196       mode '6050'  # '4750' by the distribution?!
197     end
198 =end
199     template "#{conf_dir}/taskcontroller.cfg" do
200       source "conf-#{equivalent_apache_hadoop_middle_version}/taskcontroller.cfg"
201       owner 'root'
202       group 'root'
203       mode '0400'  # '0644' by the distribution?!
204       variables({
205         :active_vol_nums => active_vol_nums
206       })
207     end
208   when '2'
209     # jsvc installation is not necessary.
210     # hadoop-hdfs requires bigtop-jsvc package.
211     template "/etc/default/hadoop-hdfs-datanode" do
212       source "etc-#{equivalent_apache_hadoop_middle_version}/default/hadoop-hdfs-datanode"
213       owner 'root'
214       group 'root'
215       mode '0644'
216     end
217
218     file "/usr/lib/hadoop-yarn/bin/container-executor" do
219       owner 'root'
220       group users[:yarn][:name]
221       mode '6050'
222     end
223     
224     template "#{conf_dir}/container-executor.cfg" do
225       source "etc-#{equivalent_apache_hadoop_middle_version}/hadoop/container-executor.cfg"
226       owner 'root'
227       group 'root'
228       mode '0400'
229       variables({
230         :active_vol_nums => active_vol_nums
231       })
232     end
233
234     if version >= '2.0.0.2' then
235       setup_cgroup(equivalent_apache_hadoop_middle_version)
236     end
237   end
238 end
239
240 # Note: update the following template (hadoop_pseudo_distributed_init.sh)
241 #       if this section will be modified.
242 case major_version
243 when '1'
244   log <<-EOM
245 Note:
246 You must initialize HDFS in the first installation:
247   $ sudo -u hdfs hadoop namenode -format
248   $ sudo service hadoop-namenode start
249   $ sudo service hadoop-datanode start
250   $ sudo -u hdfs hadoop fs -chown hdfs:hdfs /
251   $ sudo -u hdfs hadoop fs -chmod 755 /
252   $ sudo -u hdfs hadoop fs -mkdir /user
253   $ sudo -u hdfs hadoop fs -mkdir #{node['grid']['vol_root']}/0/var/lib/mapred
254   $ sudo -u hdfs hadoop fs -chown mapred:mapred #{node['grid']['vol_root']}/0/var/lib/mapred
255   EOM
256
257   examples_jar = '/usr/lib/hadoop/hadoop-examples.jar'
258 when '2'
259   log <<-EOM
260 Note:
261 You must initialize HDFS in the first installation:
262   $ sudo -u hdfs hdfs namenode -format
263   $ sudo service hadoop-hdfs-namenode start
264   $ sudo service hadoop-hdfs-datanode start
265   $ sudo -u hdfs hadoop fs -chown hdfs:hdfs /
266   $ sudo -u hdfs hadoop fs -chmod 755 /
267   $ sudo -u hdfs hadoop fs -mkdir /user
268   $ sudo -u hdfs hadoop fs -mkdir -p #{node['grid']['vol_root']}/0/var/log/yarn/nm
269   $ sudo -u hdfs hadoop fs -chown yarn:hadoop #{node['grid']['vol_root']}/0/var/log/yarn/nm
270   $ sudo -u hdfs hadoop fs -chmod 1777        #{node['grid']['vol_root']}/0/var/log/yarn/nm
271   $ sudo -u hdfs hadoop fs -mkdir -p #{node['grid']['vol_root']}/0/var/lib/mapred/history
272   $ sudo -u hdfs hadoop fs -chown -R mapred:hadoop #{node['grid']['vol_root']}/0/var/lib/mapred
273   $ sudo -u hdfs hadoop fs -chmod -R 755           #{node['grid']['vol_root']}/0/var/lib/mapred
274   EOM
275
276   examples_jar = "/usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples-<version>.jar"
277 end
278
279 template "#{node['grid']['app_root']}/sbin/hadoop_pseudo_distributed_init.sh" do
280   source "grid/usr/sbin/hadoop_pseudo_distributed_init.hdp.sh"
281   owner 'root'
282   group 'root'
283   mode '0755'
284   variables({
285     :major_version => major_version,
286   })
287 end
288
289 if node['hadoop']['with_security'] then
290   log <<-EOM
291 Note:
292 Example MapReduce job execution:
293   $ sudo -u alice kinit
294   Password for alice@LOCALDOMAIN: 
295   $ sudo -u alice hadoop jar #{examples_jar} pi \\
296   > -D mapreduce.job.acl-view-job=* -D mapreduce.job.acl-modify-job=alice 5 10
297   EOM
298 else
299   log <<-EOM
300 Note:
301 Example MapReduce job execution:
302   $ sudo adduser alice
303   $ sudo -u hdfs hadoop fs -mkdir /user/alice
304   $ sudo -u hdfs hadoop fs -chown alice:alice /user/alice
305   $ sudo -u alice hadoop jar #{examples_jar} pi 5 10
306   EOM
307 end