手把手的教你安装elasticsearch

linux版本:centos7

一,ES 目录介绍

  • bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等
  • config:配置文件目录
  • JDK:java环境
  • lib:依赖的jar,类库
  • logs:日志文件
  • modules:es相关的模块
  • plugins:可以自己开发的插件
  • data:这个目录没有,自己新建一下,后面要用 -> mkdir data,这个作为索引目录

二,es核心配置文件

▽
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-7.4.2/data
#
# Path to log files:
#
#path.logs: /usr/local/elasticsearch-7.4.2/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
                                                                

三,es的启动与关闭

停止es

如果是前台启动,直接ctrl+c就可以停止
后台启动:
./elasticsearch -d
停止杀进程:

//查看端口号
jps
//杀端口号
kill 端口号
启动es

进入到es的安装路径下的bin下面
./elasticsearch

四,安装步骤:

  1. 将文件上传的服务器上

  2. 解压缩文件tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz

  3. 将解压后的文件夹移动到local下好管理mv elasticsearch-7.4.2 /usr/local

  4. 进入到local文件夹下cd /usr/local

  5. 修改核心配置文件

    • 修改集群名称,默认是elasticsearch,虽然目前是单机,但是也会有默认的
      在这里插入图片描述

    • 为当前的es节点取个名称,名称随意,如果在集群环境中,都要有相应的名字
      在这里插入图片描述

    • 修改data数据保存地址
      在这里插入图片描述

      扫描二维码关注公众号,回复: 11262577 查看本文章
    • 修改日志数据保存地址
      在这里插入图片描述

    • 绑定es网络ip,原理同redis默认端口号,可以自定义修改(0.0.0.0代表所有ip都可以访问)
      在这里插入图片描述

    • 集群节点,名字可以先改成之前的那个节点名称
      [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-i0T9RhSR-1588756150085)(en-resource://database/1506:0)]

  6. 添加用户 ES不允许使用root操作es,需要添加用户,操作如下:

useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2
su esuser
whoami
  1. 进入到/bin目录下,启动es./elasticsearch
  2. 启动成功后访问IP:9200
    在这里插入图片描述

注意:如果启动失败请往下看!!!

五,启动失败原因与解决办法

1. 用的虚拟机或服务启的内存太小,导致启动失败
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)

解决办法:
注:如果你的安装步骤和我一样,那么这个配置文件就在这个目录下面,如果不一样,请到你自己的es安装目录下修改这个配置文件

  1. vim /usr/.local/elasticsearch-7.4.2/config/jvm.options
  2. 默认jvm的大小是1G,可以改成128m
    在这里插入图片描述
2. vm.max_map_count设置过小报错
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决办法:

  1. 修改配置文件vim /etc/sysctl.conf

  2. 在配置文件中添加vm.max_map_count=262145
    在这里插入图片描述

  3. sysctl -p刷新一下

3. 用root用户启动es
Caused by: java.lang.RuntimeException: can not run elasticsearch as root

解决办法:新建一个用户,切换到新建用户下启动

useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2
su esuser
whoami
4.配置文件设置太小

在这里插入图片描述

解决办法:

  1. 修改配置文件vim /etc/security/limits.conf
  2. 在配置文件最后添加
* soft nofile 65536 
* hard nofile 131072 
* soft nproc 2048 
* hard nproc 4096
5.启动没有异常,但是页面进不去

解决办法:云服务器记得添加安全组配置,虚拟机把防火墙关掉

猜你喜欢

转载自blog.csdn.net/qq_38446413/article/details/105955106