#!/bin/sh
###############################################################################################################
#Script name: installDatax.sh
#Script description: Install Datax.
#Current Release Version: 1.0.0
#Script Owner: He ,Haibo
#Latest editor: He, Haibo
#Support platform: Linux OS for redhat and centos.
#Date: 2021/8/17---first Version for install Datax.
#Change log:
#Descript:Put software to /var/www/html/software directory,make ${downLoadIp} as httpd server.
#All install software will be in httpd server
###############################################################################################################
###Define Shell variables
export LANG=en_US
osbox=`uname`
RHversion=$(cat /proc/version | sed 's/[^0-9]//g' | cut -b -3)
####Defile httpd downLoad IP
downLoadIp=192.168.56.100
#######Set datax user and password,"wwwwww" is a example
dataxUser=datax
dataxUserPassword=wwwwww

###创建Log目录
mkdirLogPath(){
if [[ ! -d /tmp/log ]];then
mkdir -p /tmp/log
chmod 767 /tmp/log
fi
dataxLogPath="/tmp/log"
dataxLog=datax_$(date +%y%m%d).log
}

###Get OS Arch Linux or not
getOsArch(){
if [[ "$osbox" == "Linux" ]];then
continue
else
echo "Current OS is $osbox,shell is exit now." | tee $dataxLogPath/$dataxLog
echo 0
exit 0
fi
}

###Get redhat or centos
getOsCentosOrRedhat(){
cat /proc/version | grep -iE "redhat|centos" > /dev/null
if [[ $? == 0 ]];then
continue
else
echo "Current OS is not centos or redhat." | tee -a $dataxLogPath/$dataxLog
echo 1
exit 1
fi
}

###Get OS Version
getOsVerion(){
###判断系统是否为Redhat,如果不是则退出,支持Redhat|Centos 7版本
cat /proc/version | grep -i redhat > /dev/null
if [[ $? == 0 ]];then
if [[ "$RHversion" -ge 310 ]];then
OSVersion="redhat7"
else
echo "Current Rehat Version will not support." | tee -a $dataxLogPath/$dataxLog
echo 1
exit 1
fi
else
if [[ "$RHversion" -ge 310 ]];then
OSVersion="centos7"
else
echo "Current Rehat Version will not support." | tee -a $dataxLogPath/$dataxLog
echo 1
exit 1
fi
fi
}

###Get firewalld stopped or running
checkFirewalld(){
if [[ $OSVersion == "redhat7" || $OSVersion == "centos7" ]];then
systemctl status firewalld | grep -i running > /dev/null
if [[ $? == 0 ]];then
systemctl stop firewalld
else
echo "Firewalld is stopped,Success" | tee -a $dataxLogPath/$dataxLog
fi
fi
}

###Get firewalld enable or disabled
checkFirewalldisEnabled(){
systemctl list-unit-files | grep firewalld | grep disabled > /dev/null
if [[ $? == 0 ]];then
echo "check firewalld disabled.check success." | tee -a $dataxLogPath/$dataxLog
else
systemctl disable firewalld
fi
}

###Get SeLinux enforcing or not
checkSeLinux(){
cat /etc/selinux/config | grep -w "SELINUX=enforcing" > /dev/null
if [[ $? == 0 ]];then
sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
setenforce 0
else
echo "Current SeLinux is stopped,Success." | tee -a $dataxLogPath/$dataxLog
fi
}

checkPythonVersion(){
which python > /dev/null
if [[ $? == 0 ]];then
pythonVersion=`python -V 2>&1|awk '{print $2}'`
if [[ $pythonVersion =~ 2.7 ]];then
echo "Current Python Version is $pythonVersion,check success." | tee -a $dataxLogPath/$dataxLog
else
echo "Current Python Version is $pythonVersion,check failed." | tee -a $dataxLogPath/$dataxLog
exit 1
fi
else
echo "Current OS does not hava python." | tee -a $dataxLogPath/$dataxLog
fi
}

checkJavaVersion(){
which java > /dev/null
if [[ $? == 0 ]];then
javaVersion=`echo $(java -version 2>&1 |awk 'NR==1{gsub(/"/,"");print $3}')`
if [[ "$javaVersion" > "1.8" ]];then
echo "Current java version is $javaVersion,check success." | tee -a $dataxLogPath/$dataxLog
else
echo "Current java version is $javaVersion,check failed." | tee -a $dataxLogPath/$dataxLog
exit 1
fi
else
echo "Current OS does not have java."
fi
}

checkIpValid(){
ping -c 2 ${downLoadIp} >/dev/null
if [[ $? == 0 ]];then
echo "ping ${downLoadIp} success." | tee -a $dataxLogPath/$dataxLog
else
echo "ping ${downLoadIp} failed." | tee -a $dataxLogPath/$dataxLog
exit 1
fi
}

installDatax(){
###确保/datax目录被单独挂载。
df -h | grep /datax > /dev/null
if [[ $? == 0 ]];then
wget ${downLoadIp}/software/datax.tar.gz -P /tmp
if [[ $? == 0 ]];then
tar xvf /tmp/datax.tar.gz -C / > /dev/null
else
echo "wget datax.tar.gz failed." | tee -a $dataxLogPath/$dataxLog
fi
else
echo "Does not hava /datax" | tee -a $dataxLogPath/$dataxLog
fi

}

installMaven(){
wget ${downLoadIp}/software/apache-maven-3.3.9-bin.tar.gz -P /tmp
if [[ $? == 0 ]];then
tar xvf /tmp/apache-maven-3.3.9-bin.tar.gz -C /datax > /dev/null
else
echo "wget apache-maven-3.3.9-bin.tar.gz failed." | tee -a $dataxLogPath/$dataxLog
fi
}

getJarPackages(){
wget ${downLoadIp}/software/ojdbc8.jar -P /datax/plugin/reader/oraclereader/libs
wget ${downLoadIp}/software/ojdbc8.jar -P /datax/plugin/writer/oraclewriter/libs
}

createDataxUser(){
id $dataxUser > /dev/null
if [[ $? == 0 ]];then
echo "user $dataxUser is already exists." | tee -a $dataxLogPath/$dataxLog
else
/usr/sbin/useradd ${dataxUser}
echo "$dataxUserPassword" | passwd --stdin $dataxUser
fi
}

setProfile(){
cat /home/${dataxUser}/.bash_profile | grep -w 'dataxHome=/datax/bin;export dataxHome'
if [[ $? == 0 ]];then
echo "Check dataxHome success." | tee -a $dataxLogPath/$dataxLog
else
echo 'dataxHome=/datax/bin;export dataxHome' >> /home/${dataxUser}/.bash_profile
fi

cat /home/${dataxUser}/.bash_profile | grep -w 'mavenHome=/datax/apache-maven-3.3.9/bin;export mavenHome'
if [[ $? == 0 ]];then
echo "Check mavenHome success." | tee -a $dataxLogPath/$dataxLog
else
echo 'mavenHome=/datax/apache-maven-3.3.9/bin;export mavenHome' >> /home/${dataxUser}/.bash_profile
fi

su - ${dataxUser} -c "source /home/$dataxUser/.bash_profile"
}

chownDataxPath(){
chown -R ${dataxUser}:${dataxUser} /datax
}


main(){
mkdirLogPath
getOsArch
getOsCentosOrRedhat
getOsVerion
checkFirewalld
checkFirewalldisEnabled
checkSeLinux
checkPythonVersion
checkJavaVersion
checkIpValid
installDatax
installMaven
getJarPackages
createDataxUser
setProfile
chownDataxPath
}


main

版权声明:本文为博主原创文章,未经博主允许不得转载。

DATAX