#!/bin/bash : ' @vendor Chorke Academia, Inc. @web https://cdn.chorke.org/docs/academia @version 1.0.00 @since 1.0.00 ' :</dev/null;then sudo groupadd --system hadoop;fi if ! sudo id -u hadoop &>/dev/null;then sudo useradd --system hadoop --gid hadoop --create-home --home-dir ${HADOOP_USER_HOME}; fi sudo mkdir -p ${HADOOP_HOME_DIR}/{etc,logs} sudo chown -R hadoop:hadoop ${HADOOP_HOME_DIR} } function setting(){ # add property for default file system CORE_SITE_FILE="${HADOOP_HOME_DIR}/etc/hadoop/core-site.xml" CONFIGURATION_FIND=$(cat <\n\ EOF ) CONFIGURATION_FILL=$(cat <\n\ \n\ fs.defaultFS\n\ hdfs://localhost:9000\n\ \n\ EOF ) sudo sed -z "s|${CONFIGURATION_FIND}|${CONFIGURATION_FILL}|" -i "${CORE_SITE_FILE}" # add property for replication, namenode & datanode HDFS_SITE_FILE="${HADOOP_HOME_DIR}/etc/hadoop/hdfs-site.xml" CONFIGURATION_FIND=$(cat <\n\n\ EOF ) CONFIGURATION_FILL=$(cat <\n\ \n\ dfs.replication\n\ 1\n\ \n\ \n\ dfs.namenode.name.dir\n\ ${HADOOP_USER_HOME}/hdfs/namenode/\n\ \n\ \n\ dfs.datanode.data.dir\n\ ${HADOOP_USER_HOME}/hdfs/datanode/\n\ \n\ EOF ) sudo sed -z "s|${CONFIGURATION_FIND}|${CONFIGURATION_FILL}|" -i "${HDFS_SITE_FILE}" # add java home to hadoop env JAVA_HOME_FIND='# export JAVA_HOME=' JAVA_HOME_FILL="export JAVA_HOME=${JAVA_HOME_DIR}" HADOOP_ENV_FILE="${HADOOP_HOME_DIR}/etc/hadoop/hadoop-env.sh" sudo sed -i "s|${JAVA_HOME_FIND}|${JAVA_HOME_FILL}|" "${HADOOP_ENV_FILE}" sudo -i -u hadoop bash << EOF # geneate ssh key for password less shell access ssh-keygen -q -b 4096 -t rsa -f ${HADOOP_USER_HOME}/.ssh/id_rsa -C ${SSH_PUB_KEY_TAG} -N '' cat ${HADOOP_USER_HOME}/.ssh/id_rsa.pub >> ${HADOOP_USER_HOME}/.ssh/authorized_keys # format hadoop file system mkdir -p ${HADOOP_USER_HOME}/hdfs/{datanode,namenode} ${HADOOP_HOME_DIR}/bin/hdfs namenode -format EOF } function install(){ sudo chown -R hadoop:hadoop ${HADOOP_HOME_DIR} sudo tee -a /etc/systemd/system/hadoop.service >/dev/null < ${HADOOP_HOME_DIR}/etc/hadoop.pid" ExecStart=${HADOOP_HOME_DIR}/sbin/start-all.sh ExecStop=${HADOOP_HOME_DIR}/sbin/stop-all.sh [Install] WantedBy=multi-user.target EOF } function launch(){ sudo systemctl daemon-reload sudo systemctl enable hadoop.service sudo systemctl start hadoop.service sudo systemctl status hadoop.service } function init(){ validate download approve setting install launch } init