欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

elasticsearch热更新-mysql远程实现异常处理

时间:2023-06-15

一.报错异常:

Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setContextClassLoader")

二.开发环境:

elasticsearch 7.15.2 

java 1.8.0.291

mysql 8.0.26

具体异常如下:

fatal error in thread [elasticsearch[ZBMac-C02ZQ3T41.local][clusterApplierService#updateTask][T#1]], exitingjava.lang.ExceptionInInitializerErrorat java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:375)at com.mysql.cj.jdbc.NonRegisteringDriver.(NonRegisteringDriver.java:98)at java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:375)at org.wltea.analyzer.dic.Dictionary.(Dictionary.java:106)at org.wltea.analyzer.cfg.Configuration.(Configuration.java:40)at org.elasticsearch.index.analysis.IkTokenizerFactory.(IkTokenizerFactory.java:15)at org.elasticsearch.index.analysis.IkTokenizerFactory.getIkSmartTokenizerFactory(IkTokenizerFactory.java:23)at org.elasticsearch.index.analysis.AnalysisRegistry.buildMapping(AnalysisRegistry.java:433)at org.elasticsearch.index.analysis.AnalysisRegistry.buildTokenizerFactories(AnalysisRegistry.java:275)at org.elasticsearch.index.analysis.AnalysisRegistry.build(AnalysisRegistry.java:203)at org.elasticsearch.index.IndexModule.newIndexService(IndexModule.java:429)at org.elasticsearch.indices.IndicesService.createIndexService(IndicesService.java:671)at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:574)at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:175)at org.elasticsearch.indices.cluster.IndicesClusterStateService.createIndices(IndicesClusterStateService.java:468)at org.elasticsearch.indices.cluster.IndicesClusterStateService.applyClusterState(IndicesClusterStateService.java:227)at org.elasticsearch.cluster.service.ClusterApplierService.callClusterStateAppliers(ClusterApplierService.java:500)at org.elasticsearch.cluster.service.ClusterApplierService.callClusterStateAppliers(ClusterApplierService.java:490)at org.elasticsearch.cluster.service.ClusterApplierService.applyChanges(ClusterApplierService.java:461)at org.elasticsearch.cluster.service.ClusterApplierService.runTask(ClusterApplierService.java:408)at org.elasticsearch.cluster.service.ClusterApplierService.access$000(ClusterApplierService.java:57)at org.elasticsearch.cluster.service.ClusterApplierService$UpdateTask.run(ClusterApplierService.java:152)at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:678)at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:259)at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:222)at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)at java.base/java.lang.Thread.run(Thread.java:833)Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setContextClassLoader")at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:485)at java.base/java.security.AccessController.checkPermission(AccessController.java:1068)at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:416)at java.base/java.lang.Thread.setContextClassLoader(Thread.java:1525)at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.lambda$static$0(AbandonedConnectionCleanupThread.java:77)at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.(ThreadPoolExecutor.java:630)at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1353)at java.base/java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:721)at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.(AbandonedConnectionCleanupThread.java:80)..、30 more

三.解决方案:

方案一:修改jdk 安全策略,即修改 java.policy文件。部分版本不支持,会修改无效,因此建议第二种。 

方案二:修改es下的安全策略,进入es目录 config下新建 policy.policy文件

方案一明细:

        1.进入jdk安装目录(mac 环境)

/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre/lib/security

不知道自己mac 的jdk安装在哪的,使用下面命令

/usr/libexec/java_home -V

 2.找到java.policy文件,在最下面增加

permission java.net.SocketPermission "*:*","connect,resolve";permission java.lang.RuntimePermission "getClassLoader"; permission java.lang.RuntimePermission "setContextClassLoader";

如果没有权限修改java.policy文件的话,需要赋权(右键文件-显示简介-给当前用户增加权限)

3、重启es即可。 

方案二明细:

1、es安装目录 config 下新建 policy.policy文件,添加如下内容

grant {permission java.net.SocketPermission "*:*","connect,resolve";permission java.lang.RuntimePermission "getClassLoader"; permission java.lang.RuntimePermission "setContextClassLoader"; };

2.修改jvm.option文件增加

-Djava.security.policy=你的es安装目录/config/policy.policy

3.重启es即可。

版权声明:本文为博主原创文章,转载请注明本页地址。https://mp.csdn.net/mp_blog/creation/editor/122866648

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。