Browse Source

Merge first-boot, setup-hadoop and setup-ssh with distro switching based on lsb_release

Implements: blueprint merge-dib-hadoop-elements
Change-Id: I5090a556471414cfd663fa07a0efec2ff94c3581
tags/0.2.1.rc1
Matthew Farrellee 5 years ago
parent
commit
c21cba3d7b

+ 23
- 15
elements/hadoop_fedora/first-boot.d/99-setup View File

@@ -5,18 +5,26 @@ chown root:root /mnt
5 5
 mkdir -p /var/run/hadoop ; chown hadoop:hadoop /var/run/hadoop
6 6
 mkdir -p /mnt/log/hadoop ; chown hadoop:hadoop /mnt/log/hadoop
7 7
 
8
-# Unique to Ubuntu
9
-#mkdir /run/hadoop
10
-#chown hadoop:hadoop /run/hadoop/
11
-#mkdir -p /home/ubuntu/.ssh
12
-#touch /home/ubuntu/.ssh/authorized_keys
13
-#chown -R ubuntu:ubuntu /home/ubuntu
14
-
15
-# Unique to Fedora
16
-sleep 10
17
-rm /etc/resolv.conf
18
-service network restart
19
-chown -R ec2-user:ec2-user /home/ec2-user
20
-chown -R ec2-user:ec2-user /etc/hadoop
21
-#TODO: configure iptables (https://bugs.launchpad.net/savanna/+bug/1195744)
22
-iptables -F
8
+distro=$(lsb_release -is || :)
9
+case "$distro" in
10
+   Ubuntu )
11
+      mkdir /run/hadoop
12
+      chown hadoop:hadoop /run/hadoop/
13
+      mkdir -p /home/ubuntu/.ssh
14
+      touch /home/ubuntu/.ssh/authorized_keys
15
+      chown -R ubuntu:ubuntu /home/ubuntu
16
+   ;;
17
+   Fedora )
18
+      sleep 10
19
+      rm /etc/resolv.conf
20
+      service network restart
21
+      chown -R ec2-user:ec2-user /home/ec2-user
22
+      chown -R ec2-user:ec2-user /etc/hadoop
23
+      #TODO: configure iptables (https://bugs.launchpad.net/savanna/+bug/1195744)
24
+      iptables -F
25
+   ;;
26
+   * )
27
+      echo "Unknown distro: $distro. Exiting."
28
+      exit 1
29
+   ;;
30
+esac

+ 50
- 17
elements/hadoop_fedora/install.d/30-setup-hadoop View File

@@ -1,32 +1,65 @@
1 1
 #!/bin/bash
2
-echo "Hadoop setup begins"
2
+
3
+distro=$(lsb_release -is || :)
4
+if [ ! "$distro" == "Fedora" -a ! "$distro" == "Ubuntu" ]; then
5
+   echo "Unknown distro: $distro. Exiting."
6
+   exit 1
7
+fi
8
+
9
+echo "Hadoop setup begins for $distro"
3 10
 tmp_dir=/tmp/hadoop
4 11
 
5
-install-packages wget
6 12
 echo "Creating hadoop user & group"
7
-adduser -G adm,wheel hadoop
13
+case "$distro" in
14
+   Ubuntu )
15
+      addgroup hadoop
16
+      adduser --ingroup hadoop --disabled-password --gecos GECOS hadoop
17
+      adduser hadoop sudo
18
+   ;;
19
+   Fedora )
20
+      adduser -G adm,wheel hadoop
21
+   ;;
22
+esac
8 23
 
9 24
 echo "Hadoop version $DIB_HADOOP_VERSION will be injected into image. Starting the download"
10
-wget -P $tmp_dir/ "http://archive.apache.org/dist/hadoop/core/hadoop-"$DIB_HADOOP_VERSION"/hadoop-"$DIB_HADOOP_VERSION"-1.x86_64.rpm"
25
+case "$distro" in
26
+   Ubuntu )
27
+      package="hadoop_$DIB_HADOOP_VERSION-1_x86_64.deb"
28
+   ;;
29
+   Fedora )
30
+      package="hadoop-$DIB_HADOOP_VERSION-1.x86_64.rpm"
31
+   ;;
32
+esac
33
+
34
+install-packages wget
35
+wget -P $tmp_dir "http://archive.apache.org/dist/hadoop/core/hadoop-$DIB_HADOOP_VERSION/$package"
11 36
 if [ $? -ne 0 ]; then
12 37
    echo -e "Could not find Hadoop version $DIB_HADOOP_VERSION.\nAborting"
13 38
    exit 1
14 39
 fi
15 40
 
16
-rpm -ivh --replacefiles $tmp_dir/hadoop-"$DIB_HADOOP_VERSION"-1.x86_64.rpm
17
-chmod 755 /usr/sbin/start-*
18
-chmod 755 /usr/sbin/stop-*
19
-chmod 755 /usr/sbin/slaves.sh
20
-chmod 755 /usr/sbin/update-hadoop-env.sh
21
-rm $tmp_dir/hadoop-"$DIB_HADOOP_VERSION"-1.x86_64.rpm
41
+case "$distro" in
42
+   Ubuntu )
43
+      dpkg -i $tmp_dir/$package
44
+   ;;
45
+   Fedora )
46
+      rpm -ivh --replacefiles $tmp_dir/$package
47
+      chmod 755 /usr/sbin/start-*
48
+      chmod 755 /usr/sbin/stop-*
49
+      chmod 755 /usr/sbin/slaves.sh
50
+      chmod 755 /usr/sbin/update-hadoop-env.sh
51
+   ;;
52
+esac
22 53
 rm -r $tmp_dir
23 54
 
24 55
 echo "Pre-configuring Hadoop"
25 56
 filename=$(find $TARGET_ROOT/usr/java/ -maxdepth 1 -name "jdk*")
26
-echo -e "PATH=\$PATH:/usr/sbin:$filename/bin\nJAVA_HOME=$filename" >> /home/hadoop/.bashrc
27
-echo -e "HADOOP_HOME=/usr/share/hadoop/" >> /home/hadoop/.bashrc
28
-sed -i "s,export JAVA_HOME=.*,export JAVA_HOME=$filename," /etc/hadoop/hadoop-env.sh
29
-log_dir=/mnt/log/hadoop/\$USER/
30
-sed -i "s,export HADOOP_LOG_DIR=.*,export HADOOP_LOG_DIR=$log_dir," /etc/hadoop/hadoop-env.sh
31
-log_dir=/mnt/log/hadoop/hdfs
32
-sed -i "s,export HADOOP_SECURE_DN_LOG_DIR=.*,export HADOOP_SECURE_DN_LOG_DIR=$log_dir," /etc/hadoop/hadoop-env.sh
57
+cat >> /home/hadoop/.bashrc <<EOF
58
+PATH=\$PATH:/usr/sbin:$filename/bin
59
+JAVA_HOME=$filename
60
+HADOOP_HOME=/usr/share/hadoop/
61
+EOF
62
+sed -i -e "s,export JAVA_HOME=.*,export JAVA_HOME=$filename," \
63
+       -e "s,export HADOOP_LOG_DIR=.*,export HADOOP_LOG_DIR=/mnt/log/hadoop/\$USER," \
64
+       -e "s,export HADOOP_SECURE_DN_LOG_DIR=.*,export HADOOP_SECURE_DN_LOG_DIR=/mnt/log/hadoop/hdfs," \
65
+    /etc/hadoop/hadoop-env.sh

+ 1
- 0
elements/hadoop_fedora/install.d/40-setup-ssh View File

@@ -6,6 +6,7 @@ echo "Adjusting ssh configuration"
6 6
 # /etc/ssh/ssh_config is provided by openssh-clients
7 7
 # Note0: augtool is provided by augeas-tools on Ubuntu
8 8
 # Note1: augtool on Ubuntu does not auto-save, pass -s
9
+# Note2: openssh-clients is openssh-client on Ubuntu
9 10
 install-packages augeas openssh-server openssh-clients
10 11
 
11 12
 

Loading…
Cancel
Save