Skip to content

Instantly share code, notes, and snippets.

@oleewere
Last active September 21, 2015 11:59
Show Gist options
  • Save oleewere/ac0cad755348b391ad26 to your computer and use it in GitHub Desktop.
Save oleewere/ac0cad755348b391ad26 to your computer and use it in GitHub Desktop.
install-spark-to-ambari-hdp
#!/bin/bash
: ${HDP_VERSION:=2.2.0.0-2041}
: ${SPARK_VERSION:=1.2.0}
: ${SPARK_DIST_PREFIX_VERSION:=2.2.0.0-82}
: ${SPARK_HADOOP_VERSION:=2.6.0}
SPARK_DIST_VERSION=$SPARK_VERSION.$SPARK_DIST_PREFIX_VERSION-bin-$SPARK_HADOOP_VERSION.$HDP_VERSION
SPARK_ASSEMBLY_VERSION=$SPARK_VERSION.$SPARK_DIST_PREFIX_VERSION-hadoop$SPARK_HADOOP_VERSION.$HDP_VERSION
set-spark-envs() {
export SPARK_HOME=/usr/local/spark
export YARN_CONF_DIR=/usr/hdp/$HDP_VERSION/hadoop/conf
export PATH=$PATH:$SPARK_HOME/bin
export HADOOP_USER_NAME=hdfs
export SPARK_JAR=hdfs:///spark/spark-assembly-$SPARK_ASSEMBLY_VERSION.jar
}
set-default-spark-conf() {
(cat <<- EOF
spark.driver.extraJavaOptions -Dhdp.version=$HDP_VERSION
spark.yarn.am.extraJavaOptions -Dhdp.version=$HDP_VERSION
EOF
) > $SPARK_HOME/conf/spark-defaults.conf
}
install-local-spark() {
curl -s http://public-repo-1.hortonworks.com/HDP-LABS/Projects/spark/$SPARK_VERSION/spark-$SPARK_DIST_VERSION.tgz | tar -xz -C /usr/local/
cd /usr/local && ln -s spark-$SPARK_DIST_VERSION spark
set-spark-envs
set-default-spark-conf
}
install-spark() {
install-local-spark
hadoop fs -rm -r -f /spark
echo "upload assembly jar to hdfs"
hadoop fs -mkdir /spark
hadoop fs -put $SPARK_HOME/lib/spark-assembly-$SPARK_ASSEMBLY_VERSION.jar /spark/
}
main() {
if [[ "$1" == "install" ]]; then
echo "install spark..."
install-spark
elif [[ "$1" == "install-local" ]]; then
echo "install spark without uploading jar to the hdfs..."
install-local-spark
else
echo "command not supported"
fi
}
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment