我在自己电脑Win10上装了个Elasticsearch7.8,可能因为版本过高,导致es对jdk要求也很高,而我电脑上jdk也只是1.8版本的,然后启动的时候就报下面的警告:
Warning: with JDK 8 on Windows, Elasticsearch may be unable to derive correct
ergonomic settings due to a JDK issue (JDK-8074459). Please use a newer
version of Java.
Warning: MaxDirectMemorySize may have been miscalculated due to JDK-8074459.
Please use a newer version of Java or set MaxDirectMemorySize explicitly.
这虽然只是个警告,一般情况下访问es也不会有什么问题,但是我用多线程频繁访问的时候就会报“远程主机强迫关闭了一个连接”错误。解决方式就是在配置文件中让它用自己的jdk,而不是用我们配好的环境变量的jdk。在bin/elasticsearch-env.bat文件中将if "%JAVA_HOME%" == "" (和它后面的else整个内容注释掉(es的配置中在每行的前面加rem,我也很奇怪用这么奇怪的注释方式),然后将if中的内容提取出来就好了。下面是我的配置。
set SCRIPT=%0
rem determine Elasticsearch home; to do this, we strip from the path until we
rem find bin, and then strip bin (there is an assumption here that there is no
rem nested directory under bin also named bin)
for %%I in (%SCRIPT%) do set ES_HOME=%%~dpI
:es_home_loop
for %%I in ("%ES_HOME:~1,-1%") do set DIRNAME=%%~nxI
if not "%DIRNAME%" == "bin" (
for %%I in ("%ES_HOME%..") do set ES_HOME=%%~dpfI
goto es_home_loop
)
for %%I in ("%ES_HOME%..") do set ES_HOME=%%~dpfI
rem now set the classpath
set ES_CLASSPATH=!ES_HOME!\lib\*
set HOSTNAME=%COMPUTERNAME%
if not defined ES_PATH_CONF (
set ES_PATH_CONF=!ES_HOME!\config
)
rem now make ES_PATH_CONF absolute
for %%I in ("%ES_PATH_CONF%..") do set ES_PATH_CONF=%%~dpfI
set ES_DISTRIBUTION_FLAVOR=default
set ES_DISTRIBUTION_TYPE=zip
set ES_BUNDLED_JDK=true
cd /d "%ES_HOME%"
rem now set the path to java, pass "nojava" arg to skip setting JAVA_HOME and JAVA
if "%1" == "nojava" (
exit /b
)
rem compariing to empty string makes this equivalent to bash -v check on env var
rem and allows to effectively force use of the bundled jdk when launching ES
rem by setting JAVA_HOME=
rem if "%JAVA_HOME%" == "" (
rem set JAVA="%ES_HOME%\jdk\bin\java.exe"
rem set JAVA_HOME="%ES_HOME%\jdk"
rem set JAVA_TYPE=bundled jdk
rem ) else (
rem set JAVA="%JAVA_HOME%\bin\java.exe"
rem set JAVA_TYPE=JAVA_HOME
rem )
set JAVA="%ES_HOME%\jdk\bin\java.exe"
set JAVA_HOME="%ES_HOME%\jdk"
set JAVA_TYPE=bundled jdk
if not exist !JAVA! (
echo "could not find java in !JAVA_TYPE! at !JAVA!" >&2
exit /b 1
)
rem do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
if defined JAVA_TOOL_OPTIONS (
echo warning: ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%
set JAVA_TOOL_OPTIONS=
)
rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
rem warn them that we are not observing the value of %JAVA_OPTS%
if defined JAVA_OPTS (
(echo|set /p=warning: ignoring JAVA_OPTS=%JAVA_OPTS%; )
echo pass JVM parameters via ES_JAVA_OPTS
)
rem check the Java version
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
如果是linux上也报这种警告,也在类似的配置文件中作相似的修改,我还没有部署到linux上,就暂时不此问题的解决方案,需要的朋友可以自己试试。