首页 > 数据库 > 数据库开发技术 > elasticsearch8.1源码编译笔记
idea 设置JDK17idea 设置gradle JVM为Project JVMgradle 设置aliyun加速(可选),有时设置了不如不设置更好idea open项目下的build.gradle,等待编译结束8.1版本的发行包
这一步会下载所需的依赖jdk,如果报错可以多尝试几次,或者切换网络,执行该命令时,注意终端jdk环境./gradlew localDistro
home文件夹下,文件结构如下├── elasticsearch
│ ├── BUILDING.md
│ ├── CONTRIBUTING.md
│ ├── LICENSE.txt
│ ├── NOTICE.txt
│ ├── README.asciidoc
│ ├── README.md
│ ├── TESTING.asciidoc
│ ├── Vagrantfile
│ ├── benchmarks
│ ├── build
│ ├── build-conventions
│ ├── build-tools
│ ├── build-tools-internal
│ ├── build.gradle
│ ├── ccr
│ ├── checkstyle_ide.xml
│ ├── client
│ ├── dev-tools
│ ├── distribution
│ ├── docs
│ ├── gradle
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── libs
│ ├── licenses
│ ├── modules
│ ├── plugins
│ ├── qa
│ ├── rest-api-spec
│ ├── server
│ ├── settings.gradle
│ ├── test
│ └── x-pack
├── home
│ ├── LICENSE.txt
│ ├── NOTICE.txt
│ ├── README.asciidoc
│ ├── bin
│ ├── config
│ ├── data
│ ├── jdk.app
│ ├── lib
│ ├── logs
│ ├── modules
└── └── plugins
Elasticsearch.java 运行main方法ERROR: the system property [es.path.conf] must be set-Des.path.conf=/cxt/codework/github/elasticsearch/8.1/home/config
path.home is not configured-Des.path.home=/cxt/codework/github/elasticsearch/8.1/home
main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")java.policy,内容如下(完整内容在末尾获取)grant {
permission javax.management.MBeanTrustPermission "register";
};
运行时指定
-Djava.security.policy=/cxt/codework/github/elasticsearch/8.1/home/config/java.policy
access denied ("java.lang.RuntimePermission" "createClassLoader")刚才的java.policy文件中增加如下(完整内容在末尾获取) permission java.lang.RuntimePermission "createClassLoader";
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setContextClassLoader")刚才的java.policy文件中增加如下(完整内容在末尾获取) permission java.lang.RuntimePermission "setContextClassLoader";
access denied ("org.elasticsearch.secure_sm.ThreadPermission" "modifyArbitraryThreadGroup")刚才的java.policy文件中增加如下(完整内容在末尾获取) permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup";
Caused by: java.lang.IllegalArgumentException: Unknown codebases [codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm] in policy file [file:/cxt/codework/github/elasticsearch/8.1/elasticsearch/server/out/production/resources/org/elasticsearch/bootstrap/security.policy]
解决如下,找到 server/src/main/resources/org/elasticsearch/bootstrap/security.policy,注释掉一下三个[codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm]
//grant codeBase "${codebase.elasticsearch-plugin-classloader}" {
// needed to create the classloader which allows plugins to extend other plugins
//permission java.lang.RuntimePermission "createClassLoader";
//};
//grant codeBase "${codebase.elasticsearch-secure-sm}" {
// permission java.security.AllPermission;
//};
//// Elasticsearch core:
//// These are only allowed inside the server jar, not in plugins
//grant codeBase "${codebase.elasticsearch}" {
// needed for loading plugins which may expect the context class loader to be set
// permission java.lang.RuntimePermission "setContextClassLoader";
//};
-Des.path.conf=/cxt/codework/github/elasticsearch/8.1/home/config
-Des.path.home=/cxt/codework/github/elasticsearch/8.1/home
-Djava.security.policy=/cxt/codework/github/elasticsearch/8.1/home/config/java.policy
-Dlog4j2.disable.jmx=true
也可以在Elasticsearch.main方法执行前通过代码的形式指定环境变量(可选)
System.setProperty("es.path.conf","/cxt/codework/github/elasticsearch/8.1/home/config");
System.setProperty("es.path.home", "/cxt/codework/github/elasticsearch/8.1/home");
System.setProperty("log4j2.disable.jmx", "true"); System.setProperty("java.security.policy","/cxt/codework/github/elasticsearch/8.1/home/config/java.policy");
java.policy文件如下grant {
permission javax.management.MBeanTrustPermission "register";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "setContextClassLoader";
permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup";
};
原文作者:醉鱼Java;如有侵权,请联系管理员删除。