Notes
  • Introduce
  • Go
    • Grammar
      • Basic
      • Goroutines & Channels
      • Test
    • System Library
      • Module
      • sync
      • context
      • net
    • Concurrency in Go
    • The Go Memory Model
    • Code Snippet
  • Rust
    • The Rust Programming Language
    • Rust by Example
  • JAVA
    • Preface
    • Grammar
      • Basic
      • Data Types
      • Operator
      • Exceptions
    • Class Libraries
      • Collection
      • Stream
      • IO
      • NIO
      • RMI
    • Concurrency
      • Preface
      • JMM
      • Synchronized & CAS
      • Deadlock
      • Thread
      • Lock & Condition
      • Utility Class
      • Thread-safe Collection
      • Atomic Class
      • Fork/Join
      • Concurrency Design Patterns
        • Immutable
        • Copy-on-Write
        • ThreadLocal
        • Multitheading If
        • Division
    • JVM
      • Class & Instance Initialization
      • Runtime Data Area
      • Garbage Collection
    • Web Container
      • Tomcat Architecture
      • Jetty Architecture
    • Spring
    • Tuning
      • Programming
  • Computer Science
    • Computer Organization
    • Algorithm
      • Complexity
      • Linear List
      • Sort
      • Binary Search
      • Skip List
      • Hash Table
      • Tree
      • Graph
      • String Matching
      • Bloom Filter
      • Greedy Algorithm
      • Divide and Conquer
      • Back Tracking
      • Dynamic Programming
    • Network Protocol
      • Pysical Layer
      • Data Link Layer
      • Network Layer
      • Transport Layer
      • Application layer
      • HTTP
      • HTTP/2 in Action
    • Operating System
      • Basic
      • System Initialization
      • Diagnostic Tools
      • CPU Diagnosis
      • Memory Diagnosis
      • Disk Diagnosis
      • Network Diagnosis
      • Monitor System
    • Design Patterns
      • UML
      • OOP
      • Principle
      • Refactoring & Specification
      • Creational
        • Singleton
        • Factory
        • Builder
        • Prototype
      • Structural
        • Proxy
        • Bridge
        • Decorator
        • Adapter
        • Facade
        • Composite
        • FlyWeight
      • Behavioral
        • Observer
        • Template Method
        • Strategy
        • State
        • Iterator
        • Chain of Responsibility
    • Distributed System
      • Protocol & Algorithm
      • Transcation
      • Theory
      • Resource Management
      • Scheduling
      • Computing
      • Message Queue
      • Cache
      • Consistent Hashing
  • database
    • InfluxDB
      • In-Memory Index
      • Meta
    • MySQL
      • SQL
      • Architecture
      • Log
      • Transaction
      • Indexing
      • Lock
      • Storage
    • Redis
    • Elasticsearch
      • Local Debug
    • HBase
    • Kafka
    • ZooKeeper
  • Reading
    • RocketMQ
    • 演说之禅
    • So Good They Can't Ignore You
    • 学会提问
    • Lecture
  • Other
    • v2ray
    • Kubernetes
    • Git
    • Maven
    • Anaconda And Conda
    • Fuck! Shit!
      • Remove Final by Reflection
      • Ingress Host
      • ExecuterService submit
  • Open source contribution
Powered by GitBook
On this page
  • 环境
  • clone 源码
  • 导入 idea 环境
  • 启动方式一
  • 启动方式二

Was this helpful?

  1. database
  2. Elasticsearch

Local Debug

PreviousElasticsearchNextHBase

Last updated 5 years ago

Was this helpful?

环境

  • 系统操作:macOS Mojave

  • JDK:1.12,export JAVA_HOME=$(/usr/libexec/java_home -v 1.12)

  • Elasticsearch版本:7.3.1

clone 源码

cd ~/es_data
git clone https://github.com/elastic/elasticsearch.git
cd elasticsearch
git checkout -b test v7.3.1

导入 idea 环境

./gradlew idea

Import Project => 选择 elasticsearch 目录 => Import project from external model (Gradle) => Use auto-import

启动方式一

# 这一步网络下载可能很慢,必要时使用代理  
# export http_proxy=http://127.0.0.1:1087
# export https_proxy=http://127.0.0.1:1087;
./gradlew run --debug-jvm

等运行到如下界面,就可以用 idea 执行 Run => Attach to process:

缺点:

  • 启动很慢,第一次需要下载 jdk 等依赖文件;

  • 日志窗口在 terminal,不在 debug 的 console 窗口;

优点:操作简单

启动方式二

Elasticsearch 启动类:server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch,继承EnvironmentAwareCommand。

public abstract class EnvironmentAwareCommand extends Command {
    @Override
    protected void execute(Terminal terminal, OptionSet options) throws Exception {
        putSystemPropertyIfSettingIsMissing(settings, "path.data", "es.path.data");
        putSystemPropertyIfSettingIsMissing(settings, "path.home", "es.path.home");
        putSystemPropertyIfSettingIsMissing(settings, "path.logs", "es.path.logs");
    }
    
    protected Environment createEnv(final Map<String, String> settings) throws UserException {
        final String esPathConf = System.getProperty("es.path.conf");
    }
}

可以看出我们需要配置以上四个配置:

cd ~/es_data
mkdir config data logs home

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-darwin-x86_64.tar.gz
tar zxvf elasticsearch-7.3.1-darwin-x86_64.tar.gz
cp -R elasticsearch-7.3.1/modules home/
cp -R elasticsearch-7.3.1/plugins home/

cp -R elasticsearch/distribution/src/config/* config/

vi config/elasticsearch.yml
cluster.name: my-application
node.name: node-1
#${path.data}
#${path.logs}

vi config/elasticsearch.policy
grant {
  permission java.lang.RuntimePermission "createClassLoader";
};

然后在 idea 做如下配置后,运行 Elasticsearch 的 main 方法即可:

-Des.path.data=~/es_idea/data
-Des.path.home=~/es_idea/home
-Des.path.logs=~/es_idea/logs
-Des.path.conf=~/es_idea/config
-Djava.security.policy=~/es_idea/config/elasticsearch.policy
-Dlog4j2.disable.jmx=true