1.Elasticsearch安装配置

作者: 风云雄霸天下123456 | 来源:发表于2018-05-16 18:03 被阅读6次

参考:

  1. Elasticsearch官方文章

说明

  • 系统:CentOS Linux release 7.3.1611 (Core)
  • elasticsearch版本
    elasticsearch-6.2.4(当前最新版)
  • elasticsearch运行用户、组:
    • 用户: elasticsearch
    • 组: elasticsearch
  • 目录:
    /data/soft/elasticsearch-6.2.4
  • 工具:
    aria2c多线程下载

前置说明:

  1. 需要单独安装配置java环境

安装

  1. 下载elasticsearch6.2.4
    aria2c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
  2. 解压
    tar -zxvf elasticsearch-6.2.4.tar.gz

创建用户、用户组

  1. 创建用户组
    groupadd elasticsearch
  2. 创建用户
    useradd -s /sbin/nologin -g elasticsearch elasticsearch
  3. 将elasticsearch6.2.4目录属主设置成elasticsearch
    chown -R elasticsearch: elasticsearch-6.2.4

配置

  • elasticsearch.yml

    # config
    cluster.name: ai-log
    node.name: node1
    
    # 绑定ip
    network.host: 10.0.0.1
    http.port: 9200
    
    # 配置目录
    path.data: /data/soft/elasticsearch-6.2.4/data
    path.logs: /data/soft/elasticsearch-6.2.4/logs
    
    # 发现节点
    # discovery.zen.ping.unicast.hosts:
    #     - 10.0.0.2:9300
    
    # 最低master节点数
    discovery.zen.minimum_master_nodes: 1
    
    # 主节点+数据节点
    node.master: true
    node.data: true
    
    # 设置队列长度
    thread_pool.bulk.queue_size: 2000
    thread_pool.index.queue_size: 2000
    
    # 支持跨域
    http.cors.allow-origin: "*"
    http.cors.enabled: true
    http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
    http.cors.allow-credentials: true
    
  • jvm.options

    • 设置jvm内存,请根据本机内存设置
      -Xms4g
      -Xmx4g
      

配置systemctl管理

  1. 修改系统参数vm.max_map_count

    • 创建文件/usr/lib/sysctl.d/elasticsearch.conf
      vm.max_map_count=262144
      
    • 加载配置文件
      sysctl -p /usr/lib/sysctl.d/elasticsearch.conf
    • 查看参数
      sysctl -a | grep vm.max_map_count,如果修改成功则ok
  2. 添加systemctl配置文件

    • 创建文件/usr/lib/systemd/system/elasticsearch.service
      [Unit]
      Description=Elasticsearch
      Documentation=http://www.elastic.co
      Wants=network-online.target
      After=network-online.target
      
      [Service]
      RuntimeDirectory=elasticsearch
      Environment=ES_HOME=/data/soft/elasticsearch-6.2.4
      Environment=ES_PATH_CONF=/data/soft/elasticsearch-6.2.4/config
      Environment=PID_DIR=/var/run/elasticsearch
      EnvironmentFile=-/etc/sysconfig/elasticsearch
      
      WorkingDirectory=/data/soft/elasticsearch-6.2.4
      
      User=elasticsearch
      Group=elasticsearch
      
      ExecStart=/data/soft/elasticsearch-6.2.4/bin/elasticsearch -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=65536
      
      # 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
      
      [Install]
      WantedBy=multi-user.target
      
  3. systemctl管理
    systemctl start elasticsearch.service
    systemctl stop elasticsearch.service
    systemctl restart elasticsearch.service
    systemctl status elasticsearch.service


注意事项

  1. elasticsearch不能使用root用户启动
  2. 如果使用elasticsearch用户启动,请确保elasticsearch用户对 elasticsearch6.2.4目录有权限
  3. 注意系统参数有未修改成功,比如:vm.max_map_count
  4. jvm.options配置文件里的-Xms4g、-Xmx4g参数根据自己机器内存设置成合适的值

相关文章

网友评论

    本文标题:1.Elasticsearch安装配置

    本文链接:https://www.haomeiwen.com/subject/gwuvzttx.html