搭建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/ ,如正常訪問,成功完成搭建

 

 

 

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