bingmous

欢迎交流,不吝赐教~

导航

ElasticSearch 7.17.20本地源码调试

使用本地安装gradle下载相关依赖(加速下载)

在gradle安装目录下的init.d目录中,创建初始化脚本init.gradle,添加如下脚本,将其中的maven仓库源全部换成国内镜像

allprojects{

    repositories {

        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'

        all { ArtifactRepository repo ->

            if(repo instanceof MavenArtifactRepository){

                def url = repo.url.toString()

                if (url.startsWith('https://repo.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {

                    project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."

                    remove repo

                }

            }

        }

        maven {

            url REPOSITORY_URL

        }

    }

}

gradle :distribution:archives:no-jdk-linux-tar:assemble编译linux版本

本地编译

github下载最新的源码,https://github.com/elastic/elasticsearch/tree/v7.17.20

修改wrapper.properties的gradle源:https://mirrors.cloud.tencent.com/gradle/gradle-8.5-all.zip

注意:必须是当前主分支最新的代码,否则旧版本可能有些依赖已经无法下载,导致无法编译。

gradlew :distribution:archives:no-jdk-linux-tar:assemble编译linux版本

编译完成后会在\elasticsearch-7.17.20\distribution\archives\no-jdk-linux-tar\build\distributions下生成tar.gz

本地调试

在当前目录下创建es home目录:myes

启动配置:

-Des.path.home=./myes
-Des.path.conf=./myes/config
-Dlog4j2.disable.jmx=true
-Djava.security.policy=./myes/config/elasticsearch.policy

unsuppored transport.type问题、log4j2文件缺失问题
本地编译一下windows版本,将编译结果目录中的log4j2.properties配置放入myes/config目录。将编译结果中的modules目录内容放入myes

access denied问题
config目录下创建文件elasticsearch.policy,添加如下内容:

grant {
    permission javax.management.MBeanTrustPermission "register";
    permission java.lang.RuntimePermission "createClassLoader";
    permission java.lang.RuntimePermission "setContextClassLoader";
	permission java.lang.RuntimePermission "accessDeclaredMembers";
    permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup";
};

Unknown codebases问题
将server资源中0\server\src\main\resources\org\elasticsearch\bootstrap\security.policyUnknown codebases的注释掉:

/*
grant codeBase "${codebase.elasticsearch-secure-sm}" {
  permission java.security.AllPermission;
};
*/

/*
grant codeBase "${codebase.elasticsearch}" {
  // needed for loading plugins which may expect the context class loader to be set
  permission java.lang.RuntimePermission "setContextClassLoader";
  // needed for SPI class loading
  permission java.lang.RuntimePermission "accessDeclaredMembers";
};
/*

/*
grant codeBase "${codebase.elasticsearch-plugin-classloader}" {
  // needed to create the classloader which allows plugins to extend other plugins
  permission java.lang.RuntimePermission "createClassLoader";
};
*/

启动类在server模块下:org.elasticsearch.bootstrap.Elasticsearch

浏览器localhsot:9200访问

posted on 2024-04-22 12:38  Bingmous  阅读(156)  评论(0编辑  收藏  举报