• elasticsearch 包安装方式单点启动多服务


    elasticsearch 包安装方式单点启动多服务

    搞调研分别以rpm包的形式布署了es官方版和亚马逊分发版

    https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

    https://opendistro.github.io/for-elasticsearch-docs/

    集群拓扑需要单主机起多个node服务,多服务需要多项不同的配置

    但可惜的是rpm安装方式以systemd方式启动,再好不过

    https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#sysconfig

    Sysconfig fileedit
    When using the RPM or Debian packages, system settings and environment variables can be specified in the system configuration file, which is located in:
    RPM
    /etc/sysconfig/elasticsearch
    
    Debian
    /etc/default/elasticsearch
    

    但是systemd内的EnvironmentFile=-/etc/sysconfig/elasticsearch 并不生效,只能唯一更改/etc/default/elasticsearch

    个人设置EnvironmentFile=-/etc/sysconfig/elasticsearchEnvironmentFile=-/etc/sysconfig/elasticsearch-node1,配置并不生效,实际还是会以/etc/sysconfig/elasticsearch方式执行

    [Unit]
    Description=Elasticsearch
    Documentation=https://www.elastic.co
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    Type=notify
    RuntimeDirectory=elasticsearch
    PrivateTmp=true
    Environment=ES_HOME=/usr/share/elasticsearch
    Environment=ES_PATH_CONF=/etc/elasticsearch
    Environment=PID_DIR=/var/run/elasticsearch
    Environment=ES_SD_NOTIFY=true
    #EnvironmentFile=-/etc/sysconfig/elasticsearch
    EnvironmentFile=-/etc/sysconfig/elasticsearch-node1
    
    WorkingDirectory=/usr/share/elasticsearch
    
    User=elasticsearch
    Group=elasticsearch
    
    ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet
    
    # StandardOutput is configured to redirect to journalctl since
    # some error messages may be logged in standard output before
    # elasticsearch logging system is initialized. Elasticsearch
    # stores its logs in /var/log/elasticsearch and does not use
    # journalctl by default. If you also want to enable journalctl
    # logging, you can simply remove the "quiet" option from ExecStart.
    StandardOutput=journal
    StandardError=inherit
    
    # Specifies the maximum file descriptor number that can be opened by this process
    LimitNOFILE=65535
    
    # Specifies the maximum number of processes
    LimitNPROC=4096
    
    # Specifies the maximum size of virtual memory
    LimitAS=infinity
    
    # Specifies the maximum file size
    LimitFSIZE=infinity
    
    # Disable timeout logic and wait until process is stopped
    TimeoutStopSec=0
    
    # SIGTERM signal is used to stop the Java process
    KillSignal=SIGTERM
    
    # Send the signal only to the JVM rather than its control group
    KillMode=process
    
    # Java process is never killed
    SendSIGKILL=no
    
    # When a JVM receives a SIGTERM signal it exits with code 143
    SuccessExitStatus=143
    
    # Allow a slow startup before the systemd notifier module kicks in to extend the timeout
    TimeoutStartSec=75
    
    [Install]
    WantedBy=multi-user.target
    
    # Built for packages-7.10.2 (packages)
    
    

    那要布署多节点就不能用rpm包安装和systemd安装的方案了?

    直接用jar包,或docker,都可以解决,如果都用docker了,也考虑能不能上k8s,直接云原生es

    但对强存储的服务云原生,还是不放心,想通过裸机部署,裸机部署需要用systemd来管理,需要systemd的启动多节点的解决办法

    既然外在表现是更改EnvironmentFile=-/etc/sysconfig/elasticsearch-node1不生效,那是因为es启动脚本一定有强制加载/etc/sysconfig/elasticsearch的地方,找找看

    grep '/etc/sysconfig/elasticsearch' /usr/share/elasticsearch/bin/*

    /usr/share/elasticsearch/bin/elasticsearch-env:source /etc/sysconfig/elasticsearch

    果然

    # check the Java version
    "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
    export HOSTNAME=$HOSTNAME
    source /etc/sysconfig/elasticsearch
    
    if [ -z "$ES_PATH_CONF" ]; then
      echo "ES_PATH_CONF must be set to the configuration path"
      exit 1
    fi
    

    source /etc/sysconfig/elasticsearch这一行里写死了加载/etc/sysconfig/elasticsearch,所以systemd 配置里EnvironmentFile=-/etc/sysconfig/elasticsearch 并不生效,调整测试

    • 首先 source /etc/sysconfig/elasticsearch 更改为source $ES_SYSCONFIG,从ES_SYSCONFIG 加载真实的配置文件路径
    #source /etc/sysconfig/elasticsearch
    source $ES_SYSCONFIG
    
    • 修改systemd 配置,添加传入ES_SYSCONFIG,指定相应配置文件的参数

    EnvironmentFile=ES_SYSCONFIG=/etc/sysconfig/elasticsearch-node1

    # /usr/lib/systemd/system/elasticsearch.service
    [Unit]
    Description=Elasticsearch
    Documentation=https://www.elastic.co
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    Type=notify
    RuntimeDirectory=elasticsearch
    PrivateTmp=true
    Environment=ES_HOME=/usr/share/elasticsearch
    Environment=ES_PATH_CONF=/etc/elasticsearch
    Environment=PID_DIR=/var/run/elasticsearch
    Environment=ES_SD_NOTIFY=true
    #EnvironmentFile=-/etc/sysconfig/elasticsearch
    EnvironmentFile=-/etc/sysconfig/elasticsearch-node1
    EnvironmentFile=ES_SYSCONFIG=/etc/sysconfig/elasticsearch-node1
    

    启动服务,测试生效,问题解决

    另可能会有些es权限相关的问题,对需要读写的目录添加授权

    chown elasticsearch:elasticsearch /etc/sysconfig/elasticsearch-node1

    哪些目录漏掉了,会因为权限问题es启动失败,可以通过es的日志定位到具体目录

    End
  • 相关阅读:
    [CentOS]Centos设置网卡
    [C#]创建Windows用户及组
    [C#]读取指定路径的配置文件[转]
    [C#]安装WindowsService的关键步骤
    [C#]如何解决修改注册表受限问题(转)
    [C#]DES再一例(转)
    [C#]获取当前程序运行路径的方法集合(转)
    [Postgres]Postgres复制表
    [Postgres]postgresql.conf : Permission denied处理一法
    【转】/proc/sysrq-trigger 详解
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/14916222.html
Copyright © 2020-2023  润新知