-
Notifications
You must be signed in to change notification settings - Fork 14
/
make-emr-edge-node.sh
215 lines (188 loc) · 5.52 KB
/
make-emr-edge-node.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
#!/bin/sh
# Run the below commands as root
if [ "$USER" != "root" ]; then
echo "Run me with root user!"
exit 1
fi
showUsage() {
printHeading "[ MAKE EMR EDGE NODE SCRIPTS ] USAGE"
echo "# 说明:初始化(只需执行一次), 安装基础软件包,emr基础app, 配置emr repo, 创建hadoop用户, 创建必要文件夹"
echo "$0 init [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作hadoop客户端"
echo "$0 make-hadoop-client [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作spark客户端"
echo "$0 make-spark-client [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作hive客户端"
echo "$0 make-hive-client [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作hbase客户端"
echo "$0 make-hbase-client [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作oozie客户端"
echo "$0 make-oozie-client [PEM_FILE_PATH] [MASTER_NODE_IP]"
echo
echo "# 说明:制作hudi客户端"
echo "$0 make-hudi-client"
echo
echo "# 说明:制作sqoop客户端"
echo "$0 make-sqoop-client"
echo
}
printHeading() {
title="$1"
paddingWidth=$((($(tput cols) - ${#title}) / 2 - 3))
printf "\n%${paddingWidth}s" | tr ' ' '='
printf " $title "
printf "%${paddingWidth}s\n\n" | tr ' ' '='
}
init() {
pemFile="$1"
masterNode="$2"
chmod 600 "$pemFile"
makeYumRepo "$pemFile" "$masterNode"
yum -y install vim wget zip unzip expect tree htop iotop nc telnet lrzsz openssl-devel emrfs emr-ddb emr-goodies emr-kinesis emr-s3-select emr-scripts emr-puppet
makeHadoopUser "$pemFile"
makeDir
makeJdk
echo "Plase REBOOT!!"
}
makeUser() {
# add group if not exists
user="$1"
group="$2"
egrep "^$group\:" /etc/group >&/dev/null
if [ "$?" != "0" ]; then
groupadd "$group"
echo "Group: $group is added."
fi
# add user if not exists and set password
egrep "^$user\:" /etc/passwd >&/dev/null
if [ "$?" != "0" ]; then
useradd -g "$group" "$user"
echo "User: $user is added."
fi
# enable all users of bdp group can as hdfs.
echo "$user ALL = (ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/hadoop
}
makeHadoopUser() {
makeUser "hadoop" "hadoop"
mkdir -p /home/$user/.ssh
chown $user:$group /home/$user/.ssh
chmod 700 /home/$user/.ssh
cp $pemFile /home/$user/.ssh/id_isa
chown $user:$group /home/$user/.ssh/id_isa
chmod 600 /home/$user/.ssh/id_isa
}
makeYumRepo() {
pemFile="$1"
masterNode="$2"
scp -o StrictHostKeyChecking=no -i $pemFile hadoop@$masterNode:/etc/yum.repos.d/*.repo /etc/yum.repos.d/
scp -o StrictHostKeyChecking=no -i $pemFile hadoop@$masterNode:/var/aws/emr/repoPublicKey.txt .
mkdir -p /var/aws/emr/
mv repoPublicKey.txt /var/aws/emr/repoPublicKey.txt
}
makeDir() {
mkdir -p /mnt/s3
chmod 777 -R /mnt/s3
mkdir -p /mnt/tmp
chmod 777 -R /mnt/tmp
}
makeJdk() {
yum -y install java-1.8.0-openjdk
tee /etc/profile.d/java.sh <<EOF
export JAVA_HOME=/etc/alternatives/jre
export PATH=$JAVA_HOME/bin:$PATH
EOF
}
makeHadoopClient() {
pemFile="$1"
masterNode="$2"
yum -y install hadoop-client hadoop-lzo
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/hadoop/conf/*' /etc/hadoop/conf
}
makeHiveClient() {
pemFile="$1"
masterNode="$2"
yum -y install tez hive hive-hcatalog
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/hive/conf/*' /etc/hive/conf
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/hive-hcatalog/conf/*' /etc/hive-hcatalog/conf
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/tez/conf/*' /etc/tez/conf
mkdir -p /var/log/hive/user
chmod 777 -R /var/log/hive/user
}
makeSparkClient() {
pemFile="$1"
masterNode="$2"
yum -y install spark-core spark-python spark-datanucleus
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/spark/conf/*' /etc/spark/conf
echo "spark.hadoop.yarn.timeline-service.enabled false" | tee -a /etc/spark/conf/spark-defaults.conf
mkdir -p /var/log/spark/user
chmod 777 -R /var/log/spark/user
}
makeHBaseClient() {
pemFile="$1"
masterNode="$2"
yum -y install hbase
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/hbase/conf/*' /etc/hbase/conf
mkdir -p /var/log/hbase
chmod 777 -R /var/log/hbase
}
makeHudiClient() {
yum -y install hudi
}
makeSqoopClient() {
yum -y install sqoop
}
makeOozieClient() {
pemFile="$1"
masterNode="$2"
yum -y install oozie # if install oozie-client only, oozie user won't create automatically.
rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i $pemFile" hadoop@$masterNode:'/etc/oozie/conf/*' /etc/oozie/conf
mkdir -p /var/log/oozie
chmod 777 -R /var/log/oozie
}
case $1 in
init)
shift
init "$@"
;;
make-hadoop-user)
shift
makeHadoopUser "$@"
;;
make-hadoop-client)
shift
makeHadoopClient "$@"
;;
make-hive-client)
shift
makeHiveClient "$@"
;;
make-spark-client)
shift
makeSparkClient "$@"
;;
make-hbase-client)
shift
makeHBaseClient "$@"
;;
make-oozie-client)
shift
makeOozieClient "$@"
;;
make-hudi-client)
makeHudiClient
;;
make-sqoop-client)
makeSqoopClient
;;
help)
showUsage
;;
*)
showUsage
;;
esac