Skip to main content

Elasticsearch 单节点

服务器IP主机角色
192.168.10.10Elasticsearch Server

Elasticsearch Node01

  1. 下载 elasticsearch 安装包

    wget http://pdpublic.mingdao.com/private-deployment/offline/common/elasticsearch-8.5.3-linux-x86_64.tar.gz
  2. 下载 elasticsearch-ik 插件包

    wget http://pdpublic.mingdao.com/private-deployment/offline/common/elasticsearch-analysis-ik-8.5.2.zip
  3. 解压 elasticsearch 至安装目录

    tar xf elasticsearch-8.5.3-linux-x86_64.tar.gz
    mv elasticsearch-8.5.3 /usr/local/elasticsearch
  4. 解压 elasticsearch-ik 插件至安装目录

    mkdir /usr/local/elasticsearch/plugins/elasticsearch-analysis-ik
    unzip elasticsearch-analysis-ik-8.5.2.zip -d /usr/local/elasticsearch/plugins/elasticsearch-analysis-ik/
    sed -i 's/8.5.2/8.5.3/g' /usr/local/elasticsearch/plugins/elasticsearch-analysis-ik/plugin-descriptor.properties
  5. 系统环境参数调整

    echo 'vm.max_map_count=262144' >> /etc/sysctl.conf
    echo 'vm.swappiness=1' >> /etc/sysctl.conf
    echo 'net.ipv4.tcp_retries2=5' >> /etc/sysctl.conf
    sysctl -p

    echo "* soft nofile 65536" >> /etc/security/limits.conf
    echo "* hard nofile 65536" >> /etc/security/limits.conf
    ulimit -n 65536
  6. 修改 elasticsearch 配置文件

    cat > /usr/local/elasticsearch/config/elasticsearch.yml <<EOF
    cluster.name: md-elasticsearch-private
    node.name: elasticsearch-1
    node.roles: [master,data]
    network.host: 0.0.0.0
    http.port: 9200
    transport.port: 9300
    path.data: /data/elasticsearch/data
    path.logs: /data/elasticsearch/logs
    ingest.geoip.downloader.enabled: false
    xpack.security.enabled: true
    xpack.security.http.ssl.enabled: false
    xpack.security.transport.ssl.enabled: false
    cluster.max_shards_per_node: 20000
    discovery.type: single-node
    EOF
  7. 修改 elasticsearch jvm 内存限制为4g

    sed -ri "s/##[, ]*(-Xm[s|x])[0-9]g/\14g/g" /usr/local/elasticsearch/config/jvm.options
  8. 创建数据目录

    mkdir -p /data/elasticsearch/{data,logs}
  9. 创建 elasticsearch 用户并授权目录权限

    useradd -M -s /sbin/nologin elasticsearch
    chown -R elasticsearch:elasticsearch /data/elasticsearch /usr/local/elasticsearch
  10. 配置 systemd 管理

    cat > /etc/systemd/system/elasticsearch.service <<EOF
    [Unit]
    Description=Elasticsearch
    [Service]
    User=elasticsearch
    Group=elasticsearch
    LimitNOFILE=102400
    ExecStart=/usr/local/elasticsearch/bin/elasticsearch
    ExecStop=/usr/bin/kill \$MAINPID
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF
  11. 启动 elasticsearch 服务并加入开机自启动

    systemctl start elasticsearch
    systemctl enable elasticsearch
  12. 配置认证

    /usr/local/elasticsearch/bin/elasticsearch-reset-password -u elastic -i

    # 密码 123456 输入后终端不会显示,正常黏贴或敲入即可

    # 或者非交互配置,需要先确保服务是启动状态
    ss -lnt|grep 9200

    elastic_pwd=123456
    echo -e 'y\n'$elastic_pwd'\n'$elastic_pwd'' | /usr/local/elasticsearch/bin/elasticsearch-reset-password -u elastic -i