#!/bin/bash
function log_echo
{
typeset func_name="log_echo"
LOG_PREFIX=""
LOG_SUFFIX=""
typeset cur_dt="0000-00-00 00:00:00"
typeset get_dt="date '+%y-%m-%d %H:%M:%S'"
typeset LogLevel="$1"
typeset module_name="$2"
shift
shift
typeset msg="$@"
case ${LogLevel} in
ERR|err|Err|ERROR|error|Error)
LogLevel="ERROR"
;;
INFO|info|Info|Log|LOG|log)
LogLevel="INFO"
;;
WARN|warn|Warn)
LogLevel="WARN"
;;
DEBUG|Debug|debug)
LogLevel="DEBUG"
;;
*)
echo "${func_name}" "Parameter(s) unmatched"
return 1
;;
esac
cur_dt=`eval ${get_dt}`
echo "[${LogLevel}][${cur_dt} ${module_name}] ${LOG_PREFIX}${msg}${LOG_SUFFIX} [/${LogLevel}]" | tee -a ${LOGFILE}
return 0
}
function env_path()
{
typeset Funcname="env_path"
log_echo "INFO" "${FuncName}" "Begin to env path"
#添加doris环境变量
echo "###doris环境变量###" >> /etc/profile.d/my_env.sh && \
echo "DORIS_HOME=/home/bigdata/doris" >> /etc/profile.d/my_env.sh && \
source /etc/profile.d/my_env.sh
log_echo "INFO" "${Funcname}" " env_path add completed"
}
function uninstall_doris()
{
typeset Funcname="uninstall_doris"
log_echo "INFO" "${FuncName}" "Begin to uninstall doris"
#删除doris的环境变量
sed -i '/###doris环境变量###/d' /etc/profile.d/my_env.sh && \
sed -i '/DORIS_HOME=\/home\/bigdata\/doris/d' /etc/profile.d/my_env.sh && \
source /etc/profile.d/my_env.sh
jps | grep DorisFE | grep -v grep | awk '{print $1}' |xargs kill -9 >/dev/null 2>&1
jps | grep DorisBE | grep -v grep | awk '{print $1}' |xargs kill -9 >/dev/null 2>&1
#删除doris数据目录和根目录
rm -rf /data/doris/* && \
rm -rf $DORIS_HOME
if [[ $? -eq 0 ]];then
log_echo "INFO" "${Funcname}" "doris uninstall completed"
else
log_echo "ERROR" "${Funcname}" "doris uninstall fail"
exit 1
fi
}
function edit_config()
{
typeset Funcname="edit_config"
log_echo "INFO" "${FuncName}" "Begin to edit config"
#关闭交换分区
echo 0 | sudo tee /proc/sys/vm/swappiness > /dev/null
#启动Memory Overcommit
echo 1 | sudo tee /proc/sys/vm/overcommit_memory > /dev/null
#禁用Transparent Huge Pages
echo 'madvise' | sudo tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null
# 修改虚拟内存区域至少 2000000
sysctl -w vm.max_map_count=2000000 > /dev/null
#修改fe.conf的配置
doris_model_config="$script_dir/model/doris"
fe_config_path="$DORIS_HOME/fe/conf"
Host_Ip=$(ifconfig | grep -oP 'inet (?:addr:)?\K([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -v '127.0.0.1' | head -n 1)
IFS='.' read -ra IP_ARRAY <<< $Host_Ip
priority_Ip="${IP_ARRAY[0]}.${IP_ARRAY[1]}.${IP_ARRAY[2]}.0"
echo priority_Ip : $priority_Ip
cat $doris_model_config/fe.conf.model | sed "s/\$Host_Ip/$Host_Ip/g" | sed "s/\$priority_Ip/$priority_Ip\/24/g" > temp1 && \
mv temp1 ${fe_config_path}/fe.conf
#创建元数据目录
mkdir -p /data/doris/meta
mkdir -p /data/doris/storage
chown -R bigdata:bigdata /data/doris
mkdir -p /home/bigdata/doris/storage
#修改be.conf和cn.conf的配置
be_config_path="$DORIS_HOME/be/conf"
cat $doris_model_config/be.conf.model | sed "s/\$Host_Ip/$Host_Ip/g" | sed "s/\$priority_Ip/$priority_Ip\/24/g" > temp2 && \
mv temp2 ${be_config_path}/be.conf
chown -R bigdata:bigdata /home/bigdata
}
function install_doris()
{
typeset Funcname="install_doris"
log_echo "info" "${FuncName}" "Begin to install doris"
source /etc/profile.d/my_env.sh
if [ -d "${DORIS_HOME}" ];then
log_echo "INFO" "${Funcname}" "doris is already exist"
uninstall_doris
fi
#配置全局环境变量
env_path
# 这里需要加逻辑判断 使用那个tar包
sys=$(uname -m)
if [ "$sys" = "aarch64" ]; then
doris_tar=apache-doris-2.0.9-bin-arm64.tar.gz
elif [ "$sys" = "x86_64" ]; then
if cat /proc/cpuinfo | grep -q 'avx2'; then
doris_tar=apache-doris-2.0.9-bin-x64.tar.gz
else
doris_tar=apache-doris-2.0.9-bin-x64-noavx2.tar.gz
fi
fi
doris_pkg="./pkg/$doris_tar"
tar -xzvf $doris_pkg -C /home/bigdata > /dev/null 2>&1 && \
cd /home/bigdata && \
mv apache-doris* doris && \
chown -R bigdata:bigdata /home/bigdata
if [ $? -ne 0 ];then
log_echo "ERROR" "${Funcname}" "install doris fail"
exit 1
fi
#安装成功修改配置
edit_config
if [ $? -eq 0 ];then
log_echo "INFO" "${Funcname}" "install doris successfully"
else
log_echo "ERROR" "${Funcname}" "edit doris config fail"
exit 1
fi
}
function main(){
log_echo
script_dir=$(cd "$(dirname "$0")" && pwd)
#安装doris
install_doris
}
main "$@"
02-13
1943
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-12
1290
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)