-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo-hadoop.sh
executable file
·293 lines (258 loc) · 7.22 KB
/
demo-hadoop.sh
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#! /bin/bash -xe
if [ -z "$3" ]; then
cat <<EOF
Usage: $0 MASTER_HOSTNAME MASTER_IP DEVICE [ROLE [DEPLOYED]]"
ROLE: master|slave
DEPLOYED: true|false
EOF
exit 1
fi
if [ ! -d /etc/puppet/modules/hadoop ]; then
apt-get update
apt-get dist-upgrade -y
apt-get install -y --no-install-recommends puppet
puppet module install cesnet-site_hadoop
puppet module install cesnet-hue
fi
MASTER="$1"
MASTER_IP="$2"
DEVICE="$3"
ROLE="${4:-slave}"
DEPLOYED="${5:-true}"
HBASE='false'
NFS='false'
# local IP dynamicaly (we need to know device)
IP="`ip -4 addr show dev \"$DEVICE\" | grep inet | awk '{print $2}' | cut -d/ -f1`"
if [ $? -ne 0 ]; then
echo "Device $2 not found"
exit 1
fi
# puppet hadoop module role detections is according to FQDN (hacky)
if [ "$ROLE" = "slave" ]; then
SLAVES="['$IP']"
else
SLAVES='[]'
fi
if [ "$HBASE" = "true" ]; then
hue_blacklist="search,sentry,spark,sqoop,zookeeper"
else
hue_blacklist="hbase,search,sentry,spark,sqoop,zookeeper"
fi
# rack awareness (optional)
if [ -f /usr/local/sbin/topology ]; then
topology=" 'net.topology.script.file.name' => '/usr/local/sbin/topology',
"
fi
cat > site.pp <<EOF
\$master = '$MASTER'
\$zookeepers = [
\$master,
]
\$hdfs_deployed = $DEPLOYED
\$acl = true
include ::stdlib
class { '::java_ng':
ensure => 'held',
repo => 'ppa:oracle',
version => 8,
stage => 'setup',
}
class { '::hadoop':
hdfs_hostname => \$master,
yarn_hostname => \$master,
frontends => [\$master],
slaves => $SLAVES,
hue_hostnames => [\$master],
httpfs_hostnames => [\$master],
nfs_hostnames => [\$master],
oozie_hostnames => [\$master],
zookeeper_hostnames => \$zookeepers,
acl => \$acl,
hdfs_deployed => \$hdfs_deployed,
features => {
aggregation => true,
multihome => true,
yellowmanager => true,
},
properties => {
'dfs.namenode.acls.enabled' => true,
'dfs.replication' => 3,
'hadoop.security.auth_to_local' => '::undef',
# need that without DNS infrastructure
'dfs.namenode.datanode.registration.ip-hostname-check' => false,
# shorter heartbeat
'dfs.heartbeat.interval' => 2,
# shorter patience (2 minutes to detect offline datanode)
'dfs.namenode.heartbeat.recheck-interval' => 60000,
'nfs.exports.allowed.hosts' => "\$::fqdn rw; \$::ipaddress_${DEVICE} rw",
$topology }
}
class { '::impala':
catalog_hostname => \$master,
statestore_hostname => \$master,
features => {
launcher => true,
manager => true,
},
parameters => {
catalog => {
authorized_proxy_user_config => "'hue=*'",
},
server => {
authorized_proxy_user_config => "'hue=*'",
},
statestore => {
authorized_proxy_user_config => "'hue=*'",
},
},
}
class { '::hbase':
acl => \$acl,
hdfs_hostname => \$master,
master_hostname => \$master,
slaves => $SLAVES,
thrift_hostnames => [ \$master ],
zookeeper_hostnames => \$zookeepers,
features => {
hbmanager => true,
},
}
class { '::hive':
metastore_hostname => \$master,
server2_hostname => \$master,
zookeeper_hostnames => \$zookeepers,
db => 'mysql',
db_password => 'hive_rw_password',
features => {
manager => true,
},
}
class { '::oozie':
#defaultFS => "hdfs://\$master:8020",
hdfs_hostname => \$master,
hue_hostnames => [\$master],
acl => true,
db => 'mysql',
db_password => 'oozie_rw_password',
gui_enable => false,
}
class { '::spark':
hdfs_hostname => \$master,
historyserver_hostname => \$master,
}
class { '::site_hadoop':
# too ugly (binding not configurable, requires NAT everywhere)
hbase_enable => $HBASE,
hue_enable => true,
impala_enable => true,
java_enable => false,
nfs_frontend_enable => $NFS,
oozie_enable => true,
users => [
'hawking',
],
version => '5.11',
}
EOF
case $ROLE in
master)
# we have a hostname for master
export FACTER_fqdn="$MASTER"
cat >> site.pp <<EOF
# required for hive, oozie
class { '::mysql::bindings':
java_enable => true,
}
class { '::mysql::server':
root_password => 'mysql_rw_password',
}
if \$hdfs_deployed {
class { '::hue':
hdfs_hostname => \$master,
historyserver_hostname => \$master,
hive_server2_hostname => \$master,
httpfs_hostname => \$master,
impala_hostname => \$master,
oozie_hostname => \$master,
yarn_hostname => \$master,
db => 'mysql',
db_password => 'hue_rw_password',
https => false,
https_hue => true,
https_cachain => '/etc/grid-security/ca-chain.pem',
secret => 'American president can\'t read',
properties => {
'desktop.app_blacklist' => '$hue_blacklist',
},
}
}
class { '::zookeeper':
hostnames => \$zookeepers,
}
include ::site_hadoop::role::master
include ::site_hadoop::role::frontend
include ::site_hadoop::role::hue
# just to found any impala server
include ::impala::server
include ::hadoop::httpfs
EOF
# for hue
if [ "$HBASE" = "true" ]; then
echo "include ::hbase::thriftserver" >> site.pp
fi
# from external network permit only the status html pages
cat > /etc/network/if-pre-up.d/iptables <<EOF2
#! /bin/sh
/sbin/iptables-restore <<EOF
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:fail2ban-ssh - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -i $DEVICE -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
# HDFS, YARN, Spark HS, JHS, Impala (impalad, state, catalog), HBase
-A INPUT -p tcp -m multiport --dports 50070,8088,18088,19888,8888,25000,25010,25020,60010 -j fail2ban-ssh
-A INPUT -j REJECT
-A fail2ban-ssh -j ACCEPT
COMMIT
EOF
EOF2
sed -e 's,/sbin/iptables-restore,/sbin/ip6tables-restore,' /etc/network/if-pre-up.d/iptables > /etc/network/if-pre-up.d/ip6tables
chmod +x /etc/network/if-pre-up.d/ip*tables
/etc/network/if-pre-up.d/iptables
/etc/network/if-pre-up.d/ip6tables
apt-get install -y python-snappy || :
;;
slave)
# force proper IP addres for slave (no hostname for slave)
export FACTER_fqdn="$IP"
cat >> site.pp <<EOF
include ::site_hadoop::role::slave
EOF
;;
*)
;;
esac
# hadoop requires hostname for namenode (DNS or hosts file)
if ! grep -q "\\<$MASTER_IP\\>.*\\<$MASTER\\>" /etc/hosts; then
echo "$MASTER_IP ${MASTER}. ${MASTER}" >> /etc/hosts
if [ -f /etc/cloud/cloud.cfg ]; then
sed -e 's,^\(\s*manage_etc_hosts\):.*,\1: False,' -i /etc/cloud/cloud.cfg
fi
fi
# launch!
ret=0
puppet apply --test ./site.pp || ret=$?
if [ $ret -gt 1 ]; then
# no security needed for impala
adduser impala users
# impala server can't recover when HDFS is initially installed
if [ "$DEPLOYED" = "true" ]; then
impmanager restart || :
fi
fi
exit $ret