Intellij 에서 elasticsearch 빌드 및 디버그 환경 구성하기.
- 사전 준비
- IntelliJ
- JDK 15 or high
- 소스 다운로드 및 빌드
# 편의상 저는 제 홈의 Temp에서 작업하겠습니다.
$ cd ~/Temp # (/Users/mars1/Temp)
$ git clone https://github.com/elastic/elasticsearch.git
$ cd elasticsearch
$ git checkout 7.12
# 아래 명령으로 필요한 라이브러리들을 다운받습니다. openjdk를 다운받는데 LG망에서 한참 걸려서 KT망에서 하니 금방 받네용.
$ ./gradlew localDistro
3. Intellij 에서 해당 프로젝트를 열기
File -> Open -> elasticsearch 를 다운받은 폴더를 선택합니다. ( /Users/mars1/Temp/elasticsearch)
4. 빌드하기
Build -> Build Project
5. 실행
server프로젝트의 src/main/java/org/elasticsearch/bootstrap/Elasticsearch 의 main 클래스를 실행하면 됩니다.
하지만 그냥 실행하면 몇가지 오류를 만나게 됩니다.
ERROR: the system property [es.path.conf] must be set
-> es의 설정파일 있는 경로를 지정하지 않았기 때문에 vm 옵션에
-Des.path.config=/Users/mars1/Temp/elasticsearch/build/distribution/local/elasticsearch-7.12.1-SNAPSHOT/config"
Exception in thread "main" java.lang.IllegalStateException: path.home is not configured
-> es의 홈 경로가 설정되지 않아서 발생하는 오류
-Des.path.home=/Users/mars1/Temp/elasticsearch/build/distribution/local/elasticsearch-7.12.1-SNAPSHOT
Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
-> log4j2 jmx 관련 오류
-Dlog4j2.disable.jmx=true
[2021-04-19T16:37:18,684][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: Unknown codebases [codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm] in policy file [file:/Users/mars1/Temp/elasticsearch/server/out/production/resources/org/elasticsearch/bootstrap/security.policy]
Available codebases: [codebase.jna-5.7.0-1.jar, codebase.lucene-grouping, codebase.t-digest-3.2.jar, codebase.joda-time, codebase.lucene-sandbox-8.8.0.jar, codebase.lucene-backward-codecs, codebase.lucene-spatial-extras-8.8.0.jar, codebase.lucene-misc-8.8.0.jar, codebase.lucene-highlighter, codebase.log4j-api-2.11.1.jar, codebase.lucene-memory, codebase.lucene-core-8.8.0.jar, codebase.jopt-simple, codebase.jts-core, codebase.hppc, codebase.jna, codebase.hppc-0.8.1.jar, codebase.lucene-queryparser-8.8.0.jar, codebase.lucene-highlighter-8.8.0.jar, codebase.spatial4j-0.7.jar, codebase.lucene-join, codebase.log4j-api, codebase.lucene-memory-8.8.0.jar, codebase.lucene-analyzers-common-8.8.0.jar, codebase.HdrHistogram, codebase.jackson-dataformat-cbor, codebase.lucene-core, codebase.spatial4j, codebase.log4j-core-2.11.1.jar, codebase.snakeyaml-1.26.jar, codebase.lucene-queries-8.8.0.jar, codebase.snakeyaml, codebase.lucene-grouping-8.8.0.jar, codebase.jackson-dataformat-yaml-2.10.4.jar, codebase.joda-time-2.10.4.jar, codebase.HdrHistogram-2.1.9.jar, codebase.t-digest, codebase.lucene-analyzers-common, codebase.jackson-dataformat-cbor-2.10.4.jar, codebase.lucene-spatial-extras, codebase.lucene-queryparser, codebase.jts-core-1.15.0.jar, codebase.jackson-core-2.10.4.jar, codebase.lucene-backward-codecs-8.8.0.jar, codebase.jackson-dataformat-yaml, codebase.lucene-spatial3d-8.8.0.jar, codebase.jackson-core, codebase.log4j-core, codebase.lucene-join-8.8.0.jar, codebase.lucene-queries, codebase.lucene-suggest-8.8.0.jar, codebase.lucene-sandbox, codebase.lucene-suggest, codebase.idea_rt.jar, codebase.jackson-dataformat-smile, codebase.jopt-simple-5.0.2.jar, codebase.lucene-misc, codebase.lucene-spatial3d, codebase.jackson-dataformat-smile-2.10.4.jar]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:172) ~[classes/:?]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:159) ~[classes/:?]
.
.
.
중략
-> Java Security Manager 관련 오류. jar로 만들었을때는 잘 되지만 intellij 에서 클래스로 실행하면 난다. java.security.policy 로 vm옵션을 지정하면 해당 옵션이 먹어야 하는데 잘 안먹힌다. 그래서 에러 로그에 나오는 파일에 직접 넣어준다.
[file:/Users/mars1/Temp/elasticsearch/server/out/production/resources/org/elasticsearch/bootstrap/security.policy]
// file start
grant {
permission java.lang.RuntimePermission "createClassLoader";
permission javax.management.MBeanTruxtPermission "register";
permission javax.management.MBeanServerPermission "createMBeanServer";
permission java.security.AllPermission;
permission java.lang.RuntimePermission "setContextClassLoader";
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
// java 9 "package"
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.ref";
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
// NOTE: also needed for RAMUsageEstimator size calculations
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.nio.file.LinkPermission "hard";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.vm.annotation";
permission org.elasticsearch.SpecialPermission;
// Allow host/ip name service lookups
permission java.net.SocketPermission "*", "resolve";
// Allow reading and setting socket keepalive options
permission jdk.net.NetworkPermission "getOption.TCP_KEEPIDLE";
permission jdk.net.NetworkPermission "setOption.TCP_KEEPIDLE";
permission jdk.net.NetworkPermission "getOption.TCP_KEEPINTERVAL";
permission jdk.net.NetworkPermission "setOption.TCP_KEEPINTERVAL";
permission jdk.net.NetworkPermission "getOption.TCP_KEEPCOUNT";
permission jdk.net.NetworkPermission "setOption.TCP_KEEPCOUNT";
// Allow read access to all system properties
permission java.util.PropertyPermission "*", "read";
// TODO: clean all these property writes up, and don't allow any more in. these are all bogus!
// LuceneTestCase randomization (locale/timezone/cpus/ssd)
// TODO: put these in doPrivileged and move these to test-framework.policy
permission java.util.PropertyPermission "user.language", "write";
permission java.util.PropertyPermission "user.timezone", "write";
permission java.util.PropertyPermission "lucene.cms.override_core_count", "write";
permission java.util.PropertyPermission "lucene.cms.override_spins", "write";
// messiness in LuceneTestCase: do the above, or clean this up, or simply allow to fail if its denied
permission java.util.PropertyPermission "solr.solr.home", "write";
permission java.util.PropertyPermission "solr.data.dir", "write";
permission java.util.PropertyPermission "solr.directoryFactory", "write";
// set by ESTestCase to improve test reproducibility
// TODO: set this with gradle or some other way that repros with seed?
permission java.util.PropertyPermission "processors.override", "write";
// TODO: these simply trigger a noisy warning if its unable to clear the properties
// fix that in randomizedtesting
permission java.util.PropertyPermission "junit4.childvm.count", "write";
permission java.util.PropertyPermission "junit4.childvm.id", "write";
// needed by Settings
permission java.lang.RuntimePermission "getenv.*";
// thread permission for the same thread group and ancestor groups
// (this logic is more strict than the JDK, see SecureSM)
permission java.lang.RuntimePermission "modifyThread";
permission java.lang.RuntimePermission "modifyThreadGroup";
// needed by ExceptionSerializationTests and RestTestCase for
// some hackish things they do. otherwise only needed by groovy
// (TODO: clean this up?)
permission java.lang.RuntimePermission "getProtectionDomain";
// needed by HotThreads and potentially more
// otherwise can be provided only to test libraries
permission java.lang.RuntimePermission "getStackTrace";
// needed by JMX instead of getFileSystemAttributes, seems like a bug...
permission java.lang.RuntimePermission "getFileStoreAttributes";
// needed for jimfs and NewPathForShardsTests
// otherwise can be provided only to test libraries
permission java.lang.RuntimePermission "fileSystemProvider";
// needed by jvminfo for monitoring the jvm
permission java.lang.management.ManagementPermission "monitor";
// needed by JDKESLoggerTests
permission java.util.logging.LoggingPermission "control";
// load averages on Linux
permission java.io.FilePermission "/proc/loadavg", "read";
// read max virtual memory areas
permission java.io.FilePermission "/proc/sys/vm/max_map_count", "read";
// OS release on Linux
permission java.io.FilePermission "/etc/os-release", "read";
permission java.io.FilePermission "/usr/lib/os-release", "read";
permission java.io.FilePermission "/etc/system-release", "read";
// io stats on Linux
permission java.io.FilePermission "/proc/self/mountinfo", "read";
permission java.io.FilePermission "/proc/diskstats", "read";
// control group stats on Linux
permission java.io.FilePermission "/proc/self/cgroup", "read";
permission java.io.FilePermission "/sys/fs/cgroup/cpu", "read";
permission java.io.FilePermission "/sys/fs/cgroup/cpu/-", "read";
permission java.io.FilePermission "/sys/fs/cgroup/cpuacct", "read";
permission java.io.FilePermission "/sys/fs/cgroup/cpuacct/-", "read";
permission java.io.FilePermission "/sys/fs/cgroup/memory", "read";
permission java.io.FilePermission "/sys/fs/cgroup/memory/-", "read";
// system memory on Linux systems affected by JDK bug (#66629)
permission java.io.FilePermission "/proc/meminfo", "read";
permission java.lang.management.ManagementPermission "monitor";
};
// file end