• 四、ElasticSearch节点启动


    节点启动流程

    在debug源码之前先看一下ES启动的日志,日志中概括了ES节点的启动流程

    [2020-05-12T21:28:28,560][INFO ][o.e.n.Node               ] [] initializing ...
    [2020-05-12T21:28:29,488][INFO ][o.e.e.NodeEnvironment    ] [utTANpE] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [7gb], net total_space [27.4gb], types [ext4]
    [2020-05-12T21:28:29,490][INFO ][o.e.e.NodeEnvironment    ] [utTANpE] heap size [981.5mb], compressed ordinary object pointers [true]
    [2020-05-12T21:28:29,513][INFO ][o.e.n.Node               ] node name [utTANpE] derived from node ID [utTANpEYTuCZuJUTRC1MTA]; set [node.name] to override
    [2020-05-12T21:28:29,515][INFO ][o.e.n.Node               ] version[6.1.2-SNAPSHOT], pid[42101], build[Unknown/Unknown], OS[Linux/5.3.0-46-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_191/25.191-b12]
    [2020-05-12T21:28:29,517][INFO ][o.e.n.Node               ] JVM arguments [-Des.path.conf=/home/shwang/Documents/eshome/config, -Des.path.home=/home/shwang/Documents/eshome, -Djava.security.policy=/home/shwang/Documents/eshome/config/elasticsearch.policy, -Dlog4j2.disable.jmx=true, -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=39783, -Xms1g, -Xmx1g, -Dfile.encoding=UTF-8, -Duser.country=US, -Duser.language=en, -Duser.variant]
    [2020-05-12T21:28:29,519][WARN ][o.e.n.Node               ] version [6.1.2-SNAPSHOT] is a pre-release version of Elasticsearch and is not suitable for production
    [2020-05-12T21:30:06,725][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [aggs-matrix-stats]
    [2020-05-12T21:30:06,726][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [analysis-common]
    [2020-05-12T21:30:06,727][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [ingest-common]
    [2020-05-12T21:30:06,729][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [lang-expression]
    [2020-05-12T21:30:06,730][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [lang-mustache]
    [2020-05-12T21:30:06,731][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [lang-painless]
    [2020-05-12T21:30:06,731][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [mapper-extras]
    [2020-05-12T21:30:06,732][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [parent-join]
    [2020-05-12T21:30:06,733][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [percolator]
    [2020-05-12T21:30:06,734][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [reindex]
    [2020-05-12T21:30:06,735][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [repository-url]
    [2020-05-12T21:30:06,736][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [transport-netty4]
    [2020-05-12T21:30:06,737][INFO ][o.e.p.PluginsService     ] [utTANpE] loaded module [tribe]
    [2020-05-12T21:30:06,742][INFO ][o.e.p.PluginsService     ] [utTANpE] no plugins loaded
    [2020-05-12T21:30:08,025][INFO ][i.n.u.i.PlatformDependent] Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability.
    [2020-05-12T21:30:26,108][INFO ][o.e.d.DiscoveryModule    ] [utTANpE] using discovery type [zen]
    [2020-05-12T21:30:34,491][INFO ][o.e.n.Node               ] initialized
    [2020-05-12T21:30:34,492][INFO ][o.e.n.Node               ] [utTANpE] starting ...
    [2020-05-12T21:30:36,438][INFO ][o.e.t.TransportService   ] [utTANpE] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
    [2020-05-12T21:30:36,618][WARN ][o.e.b.BootstrapChecks    ] [utTANpE] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    [2020-05-12T21:31:11,758][INFO ][o.e.c.s.MasterService    ] [utTANpE] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {utTANpE}{utTANpEYTuCZuJUTRC1MTA}{dqniYcn1Ry6BLte0xA1d3w}{127.0.0.1}{127.0.0.1:9300}
    [2020-05-12T21:31:11,864][INFO ][o.e.c.s.ClusterApplierService] [utTANpE] new_master {utTANpE}{utTANpEYTuCZuJUTRC1MTA}{dqniYcn1Ry6BLte0xA1d3w}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {utTANpE}{utTANpEYTuCZuJUTRC1MTA}{dqniYcn1Ry6BLte0xA1d3w}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
    [2020-05-12T21:31:41,619][INFO ][o.e.g.GatewayService     ] [utTANpE] recovered [0] indices into cluster_state
    [2020-05-12T21:31:41,618][INFO ][o.e.h.n.Netty4HttpServerTransport] [utTANpE] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
    [2020-05-12T21:31:43,789][INFO ][o.e.n.Node               ] [utTANpE] started
    
    • 解析命令行和配置文件参数
    • 检查JVM、操作系统环境
    • 初始化内部模块
    • 启动子模块和keepalive

    1、启动脚本

    source "`dirname "$0"`"/elasticsearch-env
    
    ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
    JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
    ES_JAVA_OPTS="${JVM_OPTIONS//${ES_TMPDIR}/$ES_TMPDIR} $ES_JAVA_OPTS"
    
    cd "$ES_HOME"
    # manual parsing to find out, if process should be detached
    if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
      exec 
        "$JAVA" 
        $ES_JAVA_OPTS 
        -Des.path.home="$ES_HOME" 
        -Des.path.conf="$ES_PATH_CONF" 
        -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" 
        -Des.distribution.type="$ES_DISTRIBUTION_TYPE" 
        -cp "$ES_CLASSPATH" 
        org.elasticsearch.bootstrap.Elasticsearch 
        "$@"
    else
      exec 
        "$JAVA" 
        $ES_JAVA_OPTS 
        -Des.path.home="$ES_HOME" 
        -Des.path.conf="$ES_PATH_CONF" 
        -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" 
        -Des.distribution.type="$ES_DISTRIBUTION_TYPE" 
        -cp "$ES_CLASSPATH" 
        org.elasticsearch.bootstrap.Elasticsearch 
        "$@" 
        <&- &
      retval=$?
      pid=$!
      [ $retval -eq 0 ] || exit $retval
      if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
        sleep $ES_STARTUP_SLEEP_TIME
      fi
      if ! ps -p $pid > /dev/null ; then
        exit 1
      fi
      exit 0
    fi
    
    exit $?
    

    2、实例化ElasticSearch

    2.1、实例化ElasticSearch中用到的设计模式(命令模式)

    • 客户端角色(Client):创建一个具体命令(ConcreteCommand)对象并确定其接收者
    • 命令角色(Command):声明了一个给所有具体命令类的抽象接口或抽象类
    • 具体命令角色(ConcreteCommand):定义一个接收者和行为之间的弱耦合
    • 请求者角色(Invoker):负责调用命令对象执行请求,相关的方法叫做行动方法
    • 接收者角色(Receiver):负责具体实施和执行一个请求

      Elasticsearch在启动时接收不同的参数,来控制 Elasticsearch 的启动后的行为;使用使命模式让请求和执行模块解耦,

    
    

    3、加载安全配置

    elasticsearch.keystore
    

    4、检查内部环境

    5、检测外部环境

    6、启动内部模块

    7、启动keepalive线程

    【引用】
    图1引用自https://www.easyice.cn/archives/media/15108012015913/15153811722455.jpg

  • 相关阅读:
    create-react-app搭建的项目中添加bootstrap
    用es6的Array.reduce()方法计算一个字符串中每个字符出现的次数
    为Docker配置阿里加速器,系统为Debian8
    基于Spring Boot,使用JPA动态调用Sql查询数据
    基于Spring Boot,使用JPA调用Sql Server数据库的存储过程并返回记录集合
    基于Spring Boot,使用JPA操作Sql Server数据库完成CRUD
    ES6,Array.includes()函数的用法
    【编程风格】c++命名约定
    【转】吴恩达的视频课程做成了文字版 ~~~
    【专业学习】常用的技术网站
  • 原文地址:https://www.cnblogs.com/shwang/p/12655651.html
Copyright © 2020-2023  润新知