elasticsearch指定jdk
1.修改/elasticsearch-7.8.0/bin目录下elasticsearch配置文件,添加如下配置
#配置自己的jdk11
export JAVA_HOME=/opt/elasticsearch-7.8.0/jdk
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/elasticsearch-7.8.0/jdk/bin/java"
else
JAVA=`which java`
fi
2.完整elasticsearch配置文件
#!/bin/bash
# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
# ES_PATH_CONF -- Path to config directory
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
#配置自己的jdk11
export JAVA_HOME=/opt/elasticsearch-7.8.0/jdk
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/elasticsearch-7.8.0/jdk/bin/java"
else
JAVA=`which java`
fi
source "`dirname "$0"`"/elasticsearch-env
CHECK_KEYSTORE=true
DAEMONIZE=false
for option in "$@"; do
case "$option" in
-h|--help|-V|--version)
CHECK_KEYSTORE=false
;;
-d|--daemonize)
DAEMONIZE=true
;;
esac
done
if [ -z "$ES_TMPDIR" ]; then
ES_TMPDIR=`"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi
# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if [[ $CHECK_KEYSTORE = true ]]
&& bin/elasticsearch-keystore has-passwd --silent
then
if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
echo "Failed to read keystore password on console" 1>&2
exit 1
fi
fi
# The JVM options parser produces the final JVM options to start Elasticsearch.
# It does this by incorporating JVM options in the following way:
# - first, system JVM options are applied (these are hardcoded options in the
# parser)
# - second, JVM options are read from jvm.options and jvm.options.d/*.options
# - third, JVM options from ES_JAVA_OPTS are applied
# - fourth, ergonomic JVM options are applied
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`
# manual parsing to find out, if process should be detached
if [[ $DAEMONIZE = false ]]; then
exec
"$JAVA"
"$XSHARE"
$ES_JAVA_OPTS
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-Des.bundled_jdk="$ES_BUNDLED_JDK"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@" <<<"$KEYSTORE_PASSWORD"
else
exec
"$JAVA"
"$XSHARE"
$ES_JAVA_OPTS
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-Des.bundled_jdk="$ES_BUNDLED_JDK"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@"
<<<"$KEYSTORE_PASSWORD" &
retval=$?
pid=$!
[ $retval -eq 0 ] || exit $retval
if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
sleep $ES_STARTUP_SLEEP_TIME
fi
if ! ps -p $pid > /dev/null ; then
exit 1
fi
exit 0
fi
exit $?
3.创建es账号并赋权
由于es新版本不允许使用root启动,需要重新创建账号。文章来源:https://www.toymoban.com/news/detail-608628.html
useradd es #创建用户es
passwd es #给已创建的用户es设置密码
chown -R es elasticsearch-7.8.0/ #文件赋权
4.切换账户并启动elasticsearch。
su es #切换到es
cd elasticsearch-7.8.0/bin #进去es的bin目录下
./elasticsearch -d #后台启动
如果启动出现elasticsearch-env << 符号异常,修改elasticsearch-env文件,第112行:文章来源地址https://www.toymoban.com/news/detail-608628.html
done < < <(env) 修改为 done <<<'env'
到了这里,关于elasticsearch指定jdk的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!