-
Notifications
You must be signed in to change notification settings - Fork 0
/
hadoop.sh
executable file
·249 lines (205 loc) · 9.63 KB
/
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
#!/usr/bin/env bash
# Navigate to home directory and clear up folders and directories
cd
FOLDER=`ls -d */ | grep hadoop-`
if [ -d "${FOLDER}" ]; then
echo "test"
#sudo rm hadoop-*
sudo rm -rf hadoop-*
fi
if [ -d "dfsdata" ]; then
sudo rm -rf dfsdata
fi
if [ -d "tmpdata" ]; then
sudo rm -rf tmpdata
fi
# Update stuff first
sudo apt update -y
sudo apt upgrade -y
# Install Java 8
sudo apt install openjdk-8-jdk -y
java -version
javac -version
# Setup and enable passwordless SSH
sudo apt install openssh-server openssh-client -y
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
# Download Hadoop
cd
wget https://dlcdn.apache.org/hadoop/common/hadoop-3.3.6/hadoop-3.3.6.tar.gz
tar xzf $HOME/hadoop-3.3.6.tar.gz
# Setting up Hadoop directories
mkdir dfsdata
mkdir tmpdata
mkdir dfsdata/datanode
mkdir dfsdata/namenode
sudo chown -R $USER:$USER $HOME/dfsdata/
sudo chown -R $USER:$USER $HOME/dfsdata/datanode/
sudo chown -R $USER:$USER $HOME/dfsdata/namenode/
# Setting up bashrc
echo "export HADOOP_HOME=$HOME/hadoop-3.3.6" >> ~/.bashrc
source ~/.bashrc
echo "export HADOOP_INSTALL=$HADOOP_HOME" >> ~/.bashrc
echo "export HADOOP_MAPRED_HOME=$HADOOP_HOME" >> ~/.bashrc
echo "export HADOOP_COMMON_HOME=$HADOOP_HOME" >> ~/.bashrc
echo "export HADOOP_HDFS_HOME=$HADOOP_HOME" >> ~/.bashrc
echo "export YARN_HOME=$HADOOP_HOME" >> ~/.bashrc
echo "export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native" >> ~/.bashrc
echo "export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin" >> ~/.bashrc
echo "export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"" >> ~/.bashrc
source ~/.bashrc
# Setting up hadoop-env.sh
if [ -f "$HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh
fi
sudo touch $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh
sudo chmod 777 $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh
while read line;
do
if [ "$line" = "# export JAVA_HOME=" ]; then
echo "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64" >> $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh
else
echo $line >> $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh
fi
done < $HADOOP_HOME/etc/hadoop/hadoop-env.sh
if [ -f "$HADOOP_HOME/etc/hadoop/hadoop-env.sh" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/hadoop-env.sh
fi
sudo mv $HADOOP_HOME/etc/hadoop/tmp-hadoop-env.sh $HADOOP_HOME/etc/hadoop/hadoop-env.sh
# Setting up core-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/tmp-core-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
fi
sudo touch $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
sudo chmod 777 $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
while read line;
do
if [ "$line" = "<configuration>" ]; then
echo "<configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo " <name>hadoop.tmp.dir</name>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo " <value>$HOME/tmpdata</value>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo " <name>fs.default.name</name>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo " <value>hdfs://127.0.0.1:9000</value>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
echo "</configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
break
else
echo $line >> $HADOOP_HOME/etc/hadoop/tmp-core-site.xml
fi
done < $HADOOP_HOME/etc/hadoop/core-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/core-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/core-site.xml
fi
sudo mv $HADOOP_HOME/etc/hadoop/tmp-core-site.xml $HADOOP_HOME/etc/hadoop/core-site.xml
# Setting up hdfs-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
fi
sudo touch $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
sudo chmod 777 $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
while read line;
do
if [ "$line" = "<configuration>" ]; then
echo "<configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <name>dfs.name.dir</name>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <value>$HOME/dfsdata/namenode</value>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <name>dfs.data.dir</name>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <value>$HOME/dfsdata/datanode</value>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <name>dfs.replication</name>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo " <value>1</value>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
echo "</configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
break
else
echo $line >> $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml
fi
done < $HADOOP_HOME/etc/hadoop/hdfs-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/hdfs-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/hdfs-site.xml
fi
sudo mv $HADOOP_HOME/etc/hadoop/tmp-hdfs-site.xml $HADOOP_HOME/etc/hadoop/hdfs-site.xml
# Setting up mapred-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
fi
sudo touch $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
sudo chmod 777 $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
while read line;
do
if [ "$line" = "<configuration>" ]; then
echo "<configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
echo " <name>mapreduce.framework.name</name>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
echo " <value>yarn</value>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
echo "</configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
break
else
echo $line >> $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml
fi
done < $HADOOP_HOME/etc/hadoop/mapred-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/mapred-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/mapred-site.xml
fi
sudo mv $HADOOP_HOME/etc/hadoop/tmp-mapred-site.xml $HADOOP_HOME/etc/hadoop/mapred-site.xml
# Setting up yarn-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
fi
sudo touch $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
sudo chmod 777 $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
while read line;
do
if [ "$line" = "<configuration>" ]; then
echo "<configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <name>yarn.nodemanager.aux-services</name>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <value>mapreduce_shuffle</value>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <value>org.apache.hadoop.mapred.ShuffleHandler</value>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <name>yarn.resourcemanager.hostname</name>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <value>127.0.0.1</value>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <name>yarn.acl.enable</name>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <value>0</value>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "<property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <name>yarn.nodemanager.env-whitelist</name> " >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo " <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PERPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</property>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
echo "</configuration>" >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
break
else
echo $line >> $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
fi
done < $HADOOP_HOME/etc/hadoop/yarn-site.xml
if [ -f "$HADOOP_HOME/etc/hadoop/yarn-site.xml" ]; then
sudo rm $HADOOP_HOME/etc/hadoop/yarn-site.xml
fi
sudo mv $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml $HADOOP_HOME/etc/hadoop/tmp-yarn-site.xml
# Formatting HDFS NameNode
hdfs namenode -format
# Starting Hadoop Processes
cd
cd hadoop-3.3.6/sbin/
./start-all.sh
# Checking Java Processes (should show 6 processes, including jps)
jps
./stop-all.sh
echo "---------------------"
echo "Run ./start-all.sh to start all hadoop processes"
echo "--------------------"