微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS7.9-ES7 部署,开机自启

CentOS7.9-ES7 部署

  1. 下载 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.2-linux-x86_64.tar.gz

  2. 解压

    tar -zxvf elasticsearch-7.11.2-linux-x86_64.tar.gz
    
  3. 移动目录

    mv elasticsearch-7.11.2 /usr/local/
    
  4. 修改es相关配置文件(重点配置)

    # vim config/elasticsearch.yml
    # 集群名
    cluster.name: es-cluster
    # 节点名
    node.name: node-master
    # 数据存放位置
    path.data: /usr/local/elasticsearch-7.11.2/data
    # 日志存放位置
    path.logs: /usr/local/elasticsearch-7.11.2/logs
    # bind 地址,0 表示任意
    network.host: 0.0.0.0
    # 认初始 master 节点
    cluster.initial_master_nodes: ["node-master"]
    
  5. 修改 jvm 相关配置

    # 重点配置堆内存大小, 本人为虚拟机只给 512m,请结合实际情况调优
    -xms512m
    -Xmx512m
    
  6. 因为 es 不允许使用 root, 所以添加 es 用户

    useradd esuser
    chown -R esuser:esuser /usr/local/elasticsearch-7.11.2/
    
  7. 运行时可能出现以下错误

    ERROR: [2] bootstrap checks Failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
    [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-7.11.2/logs/es-cluster.log
    
  8. 修改限制

    vim /etc/security/limits.conf
    # 输入如下参数
    * soft nofile 65536
    * hard nofile 131072
    * soft nproc 2048
    * hard nproc 4096
    
  9. 修改系统设置

    vim /etc/sysctl.conf
    vm.max_map_count=262145
    
    sysctl -p
    
  10. 配置开机自启

    vim /etc/init.d/elasticsearch
    
    #!/bin/bash
    #chkconfig: 345 63 37
    #description: elasticsearch
    #processname: elasticsearch-7.11.2
    
    export ES_HOME=/usr/local/elasticsearch-7.11.2
    
    case $1 in
            start)
                    su esuser<<!
                    cd $ES_HOME
                    ./bin/elasticsearch -d -p pid
                    exit
    !
                    echo "elasticsearch is started"
                    ;;
            stop)
                    pid=`cat $ES_HOME/pid`
                    kill -9 $pid
                    echo "elasticsearch is stopped"
                    ;;
            restart)
                    pid=`cat $ES_HOME/pid`
                    kill -9 $pid
                    echo "elasticsearch is stopped"
                    sleep 1
                    su esuser<<!
                    cd $ES_HOME
                    ./bin/elasticsearch -d -p pid
                    exit
    !
                    echo "elasticsearch is started"
            ;;
        *)
            echo "start|stop|restart"
            ;;
    esac
    exit 0
    
    chmod 777 elasticsearch
    chkconfig --add elasticsearch
    chkconfig elasticsearch on
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐