forked from vangj/vagrant-hadoop-2.3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
142 lines (125 loc) · 3.72 KB
/
setup.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
#!/bin/bash
export JAVA_HOME=/usr/local/java
export HADOOP_PREFIX=/usr/local/hadoop
HADOOP_ARCHIVE=hadoop-2.3.0.tar.gz
JAVA_ARCHIVE=jdk-7u51-linux-x64.gz
HADOOP_MIRROR_DOWNLOAD=http://apache.mirror.quintex.com/hadoop/common/hadoop-2.3.0/hadoop-2.3.0.tar.gz
function fileExists {
FILE=/vagrant/resources/$1
if [ -e $FILE ]
then
return 0
else
return 1
fi
}
function disableFirewall {
echo "disabling firewall"
service iptables save
service iptables stop
chkconfig iptables off
}
function installLocalJava {
echo "installing oracle jdk"
FILE=/vagrant/resources/$JAVA_ARCHIVE
tar -xzf $FILE -C /usr/local
}
function installRemoteJava {
echo "install open jdk"
yum install -y java-1.7.0-openjdk.x86_64
}
function installLocalHadoop {
echo "install hadoop from local file"
FILE=/vagrant/resources/$HADOOP_ARCHIVE
tar -xzf $FILE -C /usr/local
}
function installRemoteHadoop {
echo "install hadoop from remote file"
curl -o /home/vagrant/hadoop-2.3.0.tar.gz -O -L $HADOOP_MIRROR_DOWNLOAD
tar -xzf /home/vagrant/hadoop-2.3.0.tar.gz -C /usr/local
}
function setupJava {
echo "setting up java"
if fileExists $JAVA_ARCHIVE; then
ln -s /usr/local/jdk1.7.0_51 /usr/local/java
else
ln -s /usr/lib/jvm/jre /usr/local/java
fi
}
function setupHadoop {
echo "creating hadoop directories"
mkdir /tmp/hadoop-namenode
mkdir /tmp/hadoop-logs
mkdir /tmp/hadoop-datanode
ln -s /usr/local/hadoop-2.3.0 /usr/local/hadoop
echo "copying over hadoop configuration files"
cp -f /vagrant/resources/core-site.xml /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/hdfs-site.xml /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/mapred-site.xml /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/yarn-site.xml /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/slaves /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/hadoop-env.sh /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/yarn-env.sh /usr/local/hadoop/etc/hadoop
cp -f /vagrant/resources/yarn-daemon.sh /usr/local/hadoop/sbin
cp -f /vagrant/resources/mr-jobhistory-daemon.sh /usr/local/hadoop/sbin
echo "modifying permissions on local file system"
chown -fR vagrant /tmp/hadoop-namenode
chown -fR vagrant /tmp/hadoop-logs
chown -fR vagrant /tmp/hadoop-datanode
mkdir /usr/local/hadoop-2.3.0/logs
chown -fR vagrant /usr/local/hadoop-2.3.0/logs
}
function setupEnvVars {
echo "creating java environment variables"
#if fileExists $JAVA_ARCHIVE; then
# echo export JAVA_HOME=/usr/local/jdk1.7.0_51 >> /etc/profile.d/java.sh
#else
# echo export JAVA_HOME=/usr/lib/jvm/jre >> /etc/profile.d/java.sh
#fi
echo export JAVA_HOME=/usr/local/java >> /etc/profile.d/java.sh
echo export PATH=\${JAVA_HOME}/bin:\${PATH} >> /etc/profile.d/java.sh
echo "creating hadoop environment variables"
cp -f /vagrant/resources/hadoop.sh /etc/profile.d/hadoop.sh
}
function setupHadoopService {
echo "setting up hadoop service"
cp -f /vagrant/resources/hadoop /etc/init.d/hadoop
chmod 777 /etc/init.d/hadoop
chkconfig --level 2345 hadoop on
}
function setupNameNode {
echo "setting up namenode"
/usr/local/hadoop-2.3.0/bin/hdfs namenode -format myhadoop
}
function startHadoopService {
echo "starting hadoop service"
service hadoop start
}
function installHadoop {
if fileExists $HADOOP_ARCHIVE; then
installLocalHadoop
else
installRemoteHadoop
fi
}
function installJava {
if fileExists $JAVA_ARCHIVE; then
installLocalJava
else
installRemoteJava
fi
}
function initHdfsTempDir {
$HADOOP_PREFIX/bin/hdfs --config $HADOOP_PREFIX/etc/hadoop dfs -mkdir /tmp
$HADOOP_PREFIX/bin/hdfs --config $HADOOP_PREFIX/etc/hadoop dfs -chmod -R 777 /tmp
}
disableFirewall
installJava
installHadoop
setupJava
setupHadoop
setupEnvVars
setupNameNode
setupHadoopService
startHadoopService
initHdfsTempDir