This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangjianlong-galaxy-auto-d…/install.sh
2021-09-08 11:33:00 +08:00

730 lines
18 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#######################基础变量######################
#脚本目录
bin_path=$(cd `dirname $0`; pwd)
#脚本目录的上层目录
base_path=$(cd `dirname $0`/..; pwd)
#uuid
uuid=`uuidgen`
NUM_DIR="/usr/galaxyinstmp"
if [ ! -d "$NUM_DIR/" ];then
mkdir -p $NUM_DIR/
fi
#######################基础变量######################
cd parcels
function checkManager() {
echo "Check whether the current executor has Docker and Ansible environment, if not, install it"
echo -e "\033[31;1mThe process may prompt command not found error, please ignore it.\033[0m"
sleep 2
a=`docker -v 2>/dev/null`
hasDocker=$?
if [[ $hasDocker != '0' ]]; then
echo "
"
echo -e "\033[31;1mThis Docker not installed, Please install\033[0m"
exit 1
else
echo "
"
echo -e "\033[32;1mThis Docker installed, the version is:\033[0m"
docker -v
fi
a=`ansible --version 2>/dev/null`
hasAnsible=$?
if [[ $hasAnsible != '0' ]]; then
echo "
"
echo -e "\033[31;1mThis Ansible not installed, beginning install . . . \033[0m"
mkdir /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`
cp ${bin_path}/software_packages/ansible/ansible.repo /etc/yum.repos.d/
sed -i -e "s#s_ansible_rpm_dir#${bin_path}#g" /etc/yum.repos.d/ansible.repo
yum clean all && yum makecache
yum -y -q install ansible
if [ $? == 0 ]; then
mv /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`/* /etc/yum.repos.d/
rm -r /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`
echo -e "\033[32;1mThis Ansible installed, the version is:\033[0m"
ansible --version
echo 1 > $NUM_DIR/checkManager
else
mv /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`/* /etc/yum.repos.d/
rm -r /etc/yum.repos.d/bak_`date '+%Y-%m-%d'`
echo -e "\033[32;1mThis Ansible install failed, please check it manually\033[0m"
exit 1
fi
else
echo "
"
echo -e "\033[32;1mThis Ansible installed, the version is:\033[0m"
ansible --version
echo 1 > $NUM_DIR/checkManager
fi
sleep 5
}
function checkCluster() {
clear
echo "Check the environment to be deployed, including JDK, PIP, Docker, Firewall, TimeZone if not installed"
sleep 2
ansible-playbook -i ../configurations/hosts environment.yml
if [ $? -eq '0' ];then
clear
echo -e "\033[32;1mEnvironmental check complete, ready for installation\033[0m"
sleep 5
echo 1 > $NUM_DIR/checkCluster
else
exit 1
fi
}
#记录组件安装次数
function recordinstnum() {
FILE_NAME=$1
if [ -f "$NUM_DIR/$FILE_NAME" ];then
OLD_NUM=`cat $NUM_DIR/$FILE_NAME`
INS_NUM=`expr $OLD_NUM + 1`
echo $INS_NUM > $NUM_DIR/$FILE_NAME
else
echo 1 > $NUM_DIR/$FILE_NAME
fi
}
#获取组件安装次数
function getrecordnum() {
FILE_NAME=$1
if [ ! -d "$NUM_DIR/" ];then
mkdir -p $NUM_DIR/
fi
if [ -f "$NUM_DIR/$FILE_NAME" ];then
echo `cat $NUM_DIR/$FILE_NAME`
else
echo 0 > $NUM_DIR/$FILE_NAME
echo 0
fi
}
#输出组件安装信息
function echoSuccess() {
NAME=$1
echo -e "
\033[32;1m$NAME Components have been installed.\033[0m
"
echo "`date "+%Y-%m-%d %H:%M:%S"` - $NAME 剧本已执行完成." >> ../auditlog
sleep 5
clear
}
#输出组件安装信息
function echoError() {
NAME=$1
echo -e "\033[31;1m $NAME The installation fails. Please check\033[0m"
echo "`date "+%Y-%m-%d %H:%M:%S"` - $NAME 剧本执行异常." >> ../auditlog
sleep 5
}
#=========================================commons======================================#
#单个安装执行方法,根据传入的组件名称进行安装
#若安装出现异常导致ansible停止则脚本直接终止
#若本机多次安装过某组件则会提示是否继续安装y 继续 N 停止
function installation() {
NAME=$1
is=`getrecordnum $NAME`
if [ $is -lt '1' ];then
ansible-playbook -i ../configurations/hosts $NAME.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $NAME
recordinstnum $NAME
else
echoError $NAME
exit 1
fi
else
clear && echo -e "\033[31;1m本执行机已成功安装过 $is$NAME,缺是否继续安装,误操作可根据提示返回 \033[0m" && sleep 1
while true; do
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
ansible-playbook -i ../configurations/hosts $NAME.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $NAME
recordinstnum $NAME
break
else
echoError $NAME
exit 1
fi
;;
[Nn]*)
break;;
* )
echo "Please answer yes or no."
;;
esac
done
fi
}
#组合安装正常逻辑逐个组件询问Y执行 N不执行安装。
#记录数组通过循环顺序执行安装
function installAllCommon() {
clear
i=0
#ins_names=(Zookeeper Mariadb galaxy-gateway-keepalive Nacos Kafka Storm Hadoop HBase Clickhouse Druid Spark Arangodb)
#替换Storm成Flink
ins_names=(Zookeeper Mariadb galaxy-gateway-keepalive Nacos Kafka Hadoop HBase Flink Clickhouse Druid Spark Arangodb)
echo ${ins_names[@]} > $NUM_DIR/common_list
#根据组合进行顺序安装
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
echo ${ins_names[@]} > $NUM_DIR/common_list
else
echoError $element
exit 1
fi
done
}
#组合安装异常终止执行操作
#询问是否需要再上次基础上执行,否则清空文件跳出循环
function abnormalCombination() {
clear
while true; do
echo -e "
\033[31;1m上次选择部署后还有 `cat $NUM_DIR/common_list`未执行部署,是否继续执行.\033[0m
"
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
i=0
#根据组合进行顺序安装
list=`cat $NUM_DIR/common_list`
ins_names=(${list//,/ })
oldnums=${#ins_names[*]}
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
if [ $i -eq $oldnums ];then
cat /dev/null > $NUM_DIR/common_list
else
echo ${ins_names[@]} > $NUM_DIR/common_list
fi
else
echoError $element
exit 1
fi
done
break
;;
[Nn]*)
cat /dev/null > $NUM_DIR/common_list
break;;
* )
echo "Please answer yes or no."
;;
esac
done
}
#组合安装调用方法
function installcombination() {
if [ -f $NUM_DIR/common_list ];then
#if [ `cat $NUM_DIR/common_list | egrep "Mariadb|Nacos|Zookeeper|galaxy-gateway-keepalive|Kafka|Storm|Hadoop|HBase|Clickhouse|Druid|Spark|Arangodb" | wc -l` -gt '0' ]
#替换Storm成Flink
if [ `cat $NUM_DIR/common_list | egrep "Mariadb|Nacos|Zookeeper|galaxy-gateway-keepalive|Kafka|Flink|Hadoop|HBase|Clickhouse|Druid|Spark|Arangodb" | wc -l` -gt '0' ]
then
abnormalCombination
else
installAllCommon
fi
else
installAllCommon
fi
clear
}
#=========================================commons======================================#
#=========================================apps======================================#
#单个安装执行方法,根据传入的组件名称进行安装
#若安装出现异常导致ansible停止则脚本直接终止
#若本机多次安装过某组件则会提示是否继续安装y 继续 N 停止
function installationApps() {
NAME=$1
is=`getrecordnum $NAME`
if [ $is -lt '1' ];then
ansible-playbook -i ../configurations/hosts $NAME.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $NAME
recordinstnum $NAME
else
echoError $NAME
exit 1
fi
else
clear && echo -e "\033[31;1m本执行机已成功安装过 $is$NAME,缺是否继续安装,误操作可根据提示返回 \033[0m" && sleep 1
while true; do
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
ansible-playbook -i ../configurations/hosts $NAME.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $NAME
recordinstnum $NAME
break
else
echoError $NAME
exit 1
fi
;;
[Nn]*)
break;;
* )
echo "Please answer yes or no."
;;
esac
done
fi
}
#组合安装正常逻辑逐个组件询问Y执行 N不执行安装。
#记录数组通过循环顺序执行安装
function installAllApps() {
clear
i=0
hoskeep=`cat ../configurations/config.yml | grep -vE "^#|^$" | grep "hos_keepalive_need" | grep yes | wc -l`
if [[ $hoskeep -eq "1" ]]; then
ins_names=(galaxy-gateway-nginx galaxy-chproxy galaxy-qgw-service galaxy-job-service galaxy-report-service galaxy-hos-nginx galaxy-hos-keepalive galaxy-hos-service galaxy-gohangout)
else
ins_names=(galaxy-gateway-nginx galaxy-chproxy galaxy-qgw-service galaxy-job-service galaxy-report-service galaxy-hos-service galaxy-gohangout)
fi
echo ${ins_names[@]} > $NUM_DIR/app_list
#根据组合进行顺序安装
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
echo ${ins_names[@]} > $NUM_DIR/app_list
else
echoError $element
exit 1
fi
done
}
#组合安装异常终止执行操作
#询问是否需要再上次基础上执行,否则清空文件跳出循环
function abnormalApps() {
clear
while true; do
echo -e "
\033[31;1m上次选择部署后还有 `cat $NUM_DIR/app_list`未执行部署,是否继续执行.\033[0m
"
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
i=0
#根据组合进行顺序安装
list=`cat $NUM_DIR/app_list`
ins_names=(${list//,/ })
oldnums=${#ins_names[*]}
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
if [ $i -eq $oldnums ];then
cat /dev/null > $NUM_DIR/app_list
else
echo ${ins_names[@]} > $NUM_DIR/app_list
fi
else
echoError $element
exit 1
fi
done
break;;
[Nn]*)
cat /dev/null > $NUM_DIR/app_list
break;;
* )
echo "Please answer yes or no."
;;
esac
done
}
#组合安装调用方法
function installApps() {
if [ -f $NUM_DIR/app_list ];then
if [ `cat $NUM_DIR/app_list | egrep "galaxy-qgw-service|galaxy-job-service|galaxy-report-service|galaxy-hos-service|galaxy-chproxy|galaxy-gateway-nginx|galaxy-hos-nginx|galaxy-hos-keepalive|galaxy-gohangout" | wc -l` -gt '0' ]
then
abnormalApps
else
installAllApps
fi
else
installAllApps
fi
clear
}
#======================================apps======================================#
#======================================init======================================#
#组合安装正常逻辑逐个组件询问Y执行 N不执行安装。
#记录数组通过循环顺序执行安装
function initAll() {
clear
i=0
#ins_names=(init-galaxy-gateway-keepalive init-kafka init-hbase init-druid init-clickhouse init-storm init-spark init-galaxy-hos-service init-dos)
#替换init-storm成init-flink
ins_names=(init-galaxy-gateway-keepalive init-kafka init-hbase init-druid init-clickhouse init-flink init-spark init-galaxy-hos-service init-dos)
echo ${ins_names[@]} > $NUM_DIR/init_list
#根据组合进行顺序安装
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
unset ins_names[$i]
let i++
echo ${ins_names[@]} > $NUM_DIR/init_list
else
echoError $element
exit 1
fi
done
break
}
#组合安装异常终止执行操作
#询问是否需要再上次基础上执行,否则清空文件跳出循环
function abnormalInit() {
clear
while true; do
echo -e "
\033[31;1m上次选择部署后还有 `cat $NUM_DIR/init_list`未执行部署,是否继续执行.\033[0m
"
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
i=0
#根据组合进行顺序安装
list=`cat $NUM_DIR/init_list`
ins_names=(${list//,/ })
oldnums=${#ins_names[*]}
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
if [ $i -eq $oldnums ];then
cat /dev/null > $NUM_DIR/init_list
else
echo ${ins_names[@]} > $NUM_DIR/init_list
fi
else
echoError $element
exit 1
fi
done
break;;
[Nn]*)
cat /dev/null > $NUM_DIR/init_list
break;;
* )
echo "Please answer yes or no."
;;
esac
done
}
#组合安装调用方法
function installInit() {
if [ -f $NUM_DIR/init_list ];then
#if [ `cat $NUM_DIR/init_list | egrep "init-galaxy-gateway-keepalive|init-kafka|init-hbase|init-druid|init-clickhouse|init-storm|init-spark|init-galaxy-job-service|init-galaxy-hos-service|init-dos" | wc -l` -gt '0' ]
#替换init-storm成init-flink
if [ `cat $NUM_DIR/init_list | egrep "init-galaxy-gateway-keepalive|init-kafka|init-hbase|init-druid|init-clickhouse|init-flink|init-spark|init-galaxy-job-service|init-galaxy-hos-service|init-dos" | wc -l` -gt '0' ]
then
abnormalInit
else
initAll
fi
else
initAll
fi
}
#======================================init======================================#
#======================================check======================================#
#组合安装正常逻辑逐个组件询问Y执行 N不执行安装。
#记录数组通过循环顺序执行安装
function checkAll() {
clear
i=0
ins_names=(check-services check-components)
echo ${ins_names[@]} > $NUM_DIR/check_list
#根据组合进行顺序安装
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
echoSuccess $element
unset ins_names[$i]
let i++
echo ${ins_names[@]} > $NUM_DIR/check_list
else
echoError $element
exit 1
fi
done
clear
echo -e "
\033[32;1mCheck finished, service and component status is normal.\033[0m
"
sleep 5
break
}
#组合安装异常终止执行操作
#询问是否需要再上次基础上执行,否则清空文件跳出循环
function abnormalCheck() {
clear
while true; do
echo -e "
\033[31;1m上次选择部署后还有 `cat $NUM_DIR/check_list`未执行部署,是否继续执行.\033[0m
"
read -p "y/Y 继续执行安装,n/N 返回选择菜单:" yn
case $yn in
[Yy]*)
i=0
#根据组合进行顺序安装
list=`cat $NUM_DIR/check_list`
ins_names=(${list//,/ })
oldnums=${#ins_names[*]}
for element in ${ins_names[@]}
do
ansible-playbook -i ../configurations/hosts $element.yml
if [ $? -eq '0' ];then
sleep 10
echoSuccess $element
recordinstnum $element
unset ins_names[$i]
let i++
if [ $i -eq $oldnums ];then
cat /dev/null > $NUM_DIR/check_list
else
echo ${ins_names[@]} > $NUM_DIR/check_list
fi
else
echoError $element
exit 1
fi
done
clear
echo -e "
\033[32;1mCheck finished, service and component status is normal.\033[0m
"
sleep 5
break;;
[Nn]*)
# cat /dev/null > $NUM_DIR/check_list
break;;
* )
echo "Please answer yes or no."
;;
esac
done
}
#组合安装调用方法
function installCheck() {
if [ -f $NUM_DIR/check_list ];then
if [ `cat $NUM_DIR/check_list | egrep "check-services|check-components" | wc -l` -gt '0' ]
then
abnormalCheck
else
checkAll
fi
else
checkAll
fi
}
#======================================check======================================#
while true; do
if [[ -f $NUM_DIR/checkManager ]]; then
if [[ `cat $NUM_DIR/checkManager` -eq 0 ]]; then
checkManager
fi
else
checkManager
fi
if [[ -f $NUM_DIR/checkCluster ]]; then
if [[ `cat $NUM_DIR/checkCluster` -eq 0 ]]; then
checkCluster
fi
else
checkCluster
fi
clear
cat ../parcels/menu/homePage
if [ -f $NUM_DIR/stepNum ]; then
step_num=`cat $NUM_DIR/stepNum`
next_step_num=`expr ${step_num} + 1`
#if [ ${next_step_num} -eq '5' ]; then
# echo -e "\033[33m You have successfully installed, exiting ! ! \033[0m"
# break;
#fi
#if [ ${next_step_num} -ne ${yn_main} ]; then
# #echo "Then next step should be ${next_step_num}"
# echo -e "\033[33m Then next step should be ${next_step_num} \033[0m"
# sleep 3s
#continue
#fi
echo -e "\033[33m Then next step should be ${next_step_num}, but you can chose other number of step if you want ! ! \033[0m"
else
echo -e "\033[33m Then next step should be 1, but you can chose other number of step if you want ! ! \033[0m"
#sleep 3s
#continue
fi
read -p "
Selection(1-4)? " yn_main
case $yn_main in
[1])
while true; do
clear
#installcombination
cat ../parcels/menu/commonMenu
echo " ********************************************************************************************************* "
echo " * *
* Press Ctrl+C or N to exit, Enter or Y to continue.                                   *
* *
*********************************************************************************************************
"
read -p "Enter [yY] or [nN] " yn
case $yn in
[Yy]* )
installcombination
echo ${yn_main} > $NUM_DIR/stepNum
break;;
[Nn]*)
break;;
* )
echo "Please Enter [yY] or [nN].";;
esac
done;;
[2] )
while true; do
clear
cat ../parcels/menu/appMenu
read -p "Enter [yY] or [nN] " yn
case $yn in
[Yy]* )
installApps
echo ${yn_main} > $NUM_DIR/stepNum
break;;
[Nn]* )
break;;
* )
echo "Please Enter [yY] or [nN].";;
esac
done;;
[3] )
installInit
echo ${yn_main} > $NUM_DIR/stepNum
;;
[4] )
installCheck
echo ${yn_main} > $NUM_DIR/stepNum
;;
* )
echo "Please Enter (1-4)."
;;
esac
done