搭建elasticsearch7.11.2的源码环境

一、首先下载elasticsearch源码,从github上下载,本次下载版本为7.11.2,地址为https://github.com/elastic/elasticsearch.git

二、下载软件elasticsearch软件,本次版本为7.11.2,配置gradle,版本最好是6.1以上,本次版本为6.8.3,然后配置gradle环境变量GRADLE_HOME(gradle的软件目录),GRADLE_USER_HOME(gradle项目依赖的lib包下载目录)

三、elasticsearch目录

1、新建一个elasticsearch目录,放置data文件和config文件的地方,将在官方上下载的elasticsearch压缩文件解压几个目录config、modules和plugins,解压到刚刚新建的elasticsearch下,在elasticsearch目录下,再新建data和logs文件夹

2、修改config文件夹里面的elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#根据自己随便配置
cluster.name: my-es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#根据自己随便配置
node.name: es-node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#根据自己随便配置,数据存储目录
path.data: C:\elasticsearch7.11.2\data
#
# Path to log files:
#
#根据自己随便配置,日志保存目录
path.logs: C:\elasticsearch7.11.2\logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["es-node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
xpack.ml.enabled: false

其中参数参考搭建elasticsearch的内容

四、elasticsearch源码

1、打开elasticsearch源码目录,修改elasticsearch-7.11.2\buildSrc\build.gradle文件,查找JavaVersion,注掉以下内容

2、修改elasticsearch-7.11.2\server\src\main\resources\org\elasticsearch\bootstrap\security.policy文件,将grant codeBase内容都注掉,如下:

再在文件最后,添加以下内容:

  permission javax.management.MBeanTruxtPermission "register";
  permission javax.management.MBeanServerPermission "createMBeanServer";
  permission java.lang.RuntimePermission "createClassLoader";
  permission java.lang.RuntimePermission "setContextClassLoader";
  permission java.lang.RuntimePermission "accessDeclaredMembers";

3、用idea打开elasticsearch源码,配置好idea中的gradle内容(如果之前已经配置,可忽略)

配置项目的jdk版本,最好用15版本,本次使用open jdk14

4、下载依赖包

5、经过漫长的下载过程(主要拼网速),然后找到org.elasticsearch.bootstrap.Elasticsearch这个类,里面有个main方法,配置下vm参数

-Des.path.conf=D:\elasticsearch7.11.2\config
-Des.path.home=D:\elasticsearch7.11.2
-Dlog4j2.disable.jmx=true
-Xms3g
-Xmx3g

第一行是本文第二步新建的config目录,根据实际修改,第二行也是如此,第二步新建的elasticsearch目录

最后二行根据实例配置,必须要配置不小于2G内存,建议是4G

6、执行org.elasticsearch.bootstrap.Elasticsearch#main(java.lang.String[])方法

7、在浏览器上,输入地址 http://127.0.0.1:9200/ ,如正常访问,成功完成搭建

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章