2020-08-03 22:40:02 +08:00
|
|
|
|
#!/bin/bash
|
2018-07-21 00:27:23 +08:00
|
|
|
|
|
2018-09-26 20:05:17 +08:00
|
|
|
|
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
2019-01-27 01:40:26 +08:00
|
|
|
|
cygwin=false
|
|
|
|
|
darwin=false
|
|
|
|
|
os400=false
|
|
|
|
|
case "`uname`" in
|
|
|
|
|
CYGWIN*) cygwin=true;;
|
|
|
|
|
Darwin*) darwin=true;;
|
|
|
|
|
OS400*) os400=true;;
|
|
|
|
|
esac
|
2018-07-21 00:27:23 +08:00
|
|
|
|
error_exit ()
|
|
|
|
|
{
|
|
|
|
|
echo "ERROR: $1 !!"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
|
|
|
|
|
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
|
|
|
|
|
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
|
2019-01-30 17:40:16 +08:00
|
|
|
|
[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME
|
|
|
|
|
|
2019-01-27 01:40:26 +08:00
|
|
|
|
if [ -z "$JAVA_HOME" ]; then
|
|
|
|
|
if $darwin; then
|
2018-07-21 00:27:23 +08:00
|
|
|
|
|
2019-01-27 01:40:26 +08:00
|
|
|
|
if [ -x '/usr/libexec/java_home' ] ; then
|
|
|
|
|
export JAVA_HOME=`/usr/libexec/java_home`
|
|
|
|
|
|
|
|
|
|
elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
|
|
|
|
|
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
JAVA_PATH=`dirname $(readlink -f $(which javac))`
|
|
|
|
|
if [ "x$JAVA_PATH" != "x" ]; then
|
|
|
|
|
export JAVA_HOME=`dirname $JAVA_PATH 2>/dev/null`
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ -z "$JAVA_HOME" ]; then
|
|
|
|
|
error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better!"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2018-07-21 00:27:23 +08:00
|
|
|
|
|
2019-07-01 23:08:08 +08:00
|
|
|
|
export SERVER="nacos-server"
|
2018-07-21 00:27:23 +08:00
|
|
|
|
export MODE="cluster"
|
2019-02-27 20:00:05 +08:00
|
|
|
|
export FUNCTION_MODE="all"
|
2020-04-21 17:14:59 +08:00
|
|
|
|
export MEMBER_LIST=""
|
|
|
|
|
export EMBEDDED_STORAGE=""
|
|
|
|
|
while getopts ":m:f:s:c:p:" opt
|
2018-07-21 00:27:23 +08:00
|
|
|
|
do
|
|
|
|
|
case $opt in
|
|
|
|
|
m)
|
2019-02-27 20:00:05 +08:00
|
|
|
|
MODE=$OPTARG;;
|
|
|
|
|
f)
|
|
|
|
|
FUNCTION_MODE=$OPTARG;;
|
2019-07-01 23:08:08 +08:00
|
|
|
|
s)
|
|
|
|
|
SERVER=$OPTARG;;
|
2020-04-21 17:14:59 +08:00
|
|
|
|
c)
|
|
|
|
|
MEMBER_LIST=$OPTARG;;
|
|
|
|
|
p)
|
|
|
|
|
EMBEDDED_STORAGE=$OPTARG;;
|
2018-07-21 00:27:23 +08:00
|
|
|
|
?)
|
2018-12-07 14:31:31 +08:00
|
|
|
|
echo "Unknown parameter"
|
2018-07-21 00:27:23 +08:00
|
|
|
|
exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
export JAVA_HOME
|
|
|
|
|
export JAVA="$JAVA_HOME/bin/java"
|
|
|
|
|
export BASE_DIR=`cd $(dirname $0)/..; pwd`
|
2020-12-29 09:52:07 +08:00
|
|
|
|
export CUSTOM_SEARCH_LOCATIONS=file:${BASE_DIR}/conf/
|
2018-07-21 00:27:23 +08:00
|
|
|
|
|
|
|
|
|
#===========================================================================================
|
|
|
|
|
# JVM Configuration
|
|
|
|
|
#===========================================================================================
|
|
|
|
|
if [[ "${MODE}" == "standalone" ]]; then
|
2018-11-16 14:22:12 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m"
|
2018-07-21 00:27:23 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true"
|
2018-11-16 14:22:12 +08:00
|
|
|
|
else
|
2020-04-21 17:14:59 +08:00
|
|
|
|
if [[ "${EMBEDDED_STORAGE}" == "embedded" ]]; then
|
|
|
|
|
JAVA_OPT="${JAVA_OPT} -DembeddedStorage=true"
|
|
|
|
|
fi
|
2018-11-16 14:22:12 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
|
|
|
|
|
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof"
|
|
|
|
|
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
2019-02-27 20:00:05 +08:00
|
|
|
|
if [[ "${FUNCTION_MODE}" == "config" ]]; then
|
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config"
|
|
|
|
|
elif [[ "${FUNCTION_MODE}" == "naming" ]]; then
|
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-04-21 17:14:59 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.member.list=${MEMBER_LIST}"
|
2019-02-27 20:00:05 +08:00
|
|
|
|
|
2018-11-16 14:22:12 +08:00
|
|
|
|
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
|
|
|
|
|
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
|
2018-11-20 11:03:25 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
|
2018-11-16 14:22:12 +08:00
|
|
|
|
else
|
2021-08-27 09:33:47 +08:00
|
|
|
|
JAVA_OPT_EXT_FIX="-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
|
2018-11-20 11:03:25 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
|
2018-07-21 00:27:23 +08:00
|
|
|
|
fi
|
2019-01-18 10:57:44 +08:00
|
|
|
|
|
2022-08-12 16:58:39 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins,${BASE_DIR}/plugins/health,${BASE_DIR}/plugins/cmdb,${BASE_DIR}/plugins/selector"
|
2018-11-16 14:22:12 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
|
2019-11-13 14:28:26 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/${SERVER}.jar"
|
2018-07-21 00:27:23 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
|
2020-12-29 09:52:07 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} --spring.config.additional-location=${CUSTOM_SEARCH_LOCATIONS}"
|
2018-10-03 04:26:40 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml"
|
2019-04-16 09:49:42 +08:00
|
|
|
|
JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"
|
2018-11-16 14:22:12 +08:00
|
|
|
|
|
2018-07-21 00:27:23 +08:00
|
|
|
|
if [ ! -d "${BASE_DIR}/logs" ]; then
|
|
|
|
|
mkdir ${BASE_DIR}/logs
|
|
|
|
|
fi
|
|
|
|
|
|
2021-08-27 09:33:47 +08:00
|
|
|
|
echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}"
|
2018-11-15 22:45:53 +08:00
|
|
|
|
|
|
|
|
|
if [[ "${MODE}" == "standalone" ]]; then
|
2019-07-01 23:08:08 +08:00
|
|
|
|
echo "nacos is starting with standalone"
|
2018-11-15 22:45:53 +08:00
|
|
|
|
else
|
2019-07-01 23:08:08 +08:00
|
|
|
|
echo "nacos is starting with cluster"
|
|
|
|
|
fi
|
2018-11-15 22:45:53 +08:00
|
|
|
|
|
2019-07-01 23:08:08 +08:00
|
|
|
|
# check the start.out log output file
|
|
|
|
|
if [ ! -f "${BASE_DIR}/logs/start.out" ]; then
|
|
|
|
|
touch "${BASE_DIR}/logs/start.out"
|
2019-01-04 14:16:15 +08:00
|
|
|
|
fi
|
2019-07-01 23:08:08 +08:00
|
|
|
|
# start
|
2021-08-27 09:33:47 +08:00
|
|
|
|
echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
|
|
|
|
|
|
|
|
|
|
if [[ "$JAVA_OPT_EXT_FIX" == "" ]]; then
|
|
|
|
|
nohup "$JAVA" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
|
|
|
|
|
else
|
|
|
|
|
nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
|
|
|
|
|
fi
|
|
|
|
|
|
2019-07-01 23:08:08 +08:00
|
|
|
|
echo "nacos is starting,you can check the ${BASE_DIR}/logs/start.out"
|