es学习(一):linux下安装es

本篇文章主要讲解centos7下es的安装

下载安装包

直接访问es官网,下载

上传安装包到虚拟机并解压

  1. 上传到/home/software/

  2. 解压压缩包

tar -zxvf elasticsearch-7.5.1-linux-x86_64.tar.gz 
  1. 移动解压后的es文件夹
mv elasticsearch-7.5.1 /usr/local/

es 目录介绍

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

修改核心配置文件elasticearch.yml

  1. 修改集群名称
  2. 修改当前的es节点名称
  3. 修改data数据保存地址和日志数据保存地址
  4. 绑定es网络ip
  5. 集群节点修改为之前的节点名称


修改jvm参数

打开 jvm.options 文件
这里使用的是虚拟机

## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

# 修改这里的配置
-Xms128m
-Xmx128m

添加用户

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

useradd esuser
chown -R esuser:esuser /usr/local/elasticsearch-7.5.1
su esuser

启动es

./elasticsearch
如果出现如下错误:

ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [esuser] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

需要切换到root用户修改配置

  • 修改/etc/security/limits.conf 文件

增加下面内容

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

  • 修改 /etc/sysctl.conf 增加 vm.max_map_count=262145
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

vm.max_map_count=262145

修改完后 sysctl -p 刷新一下

再次切换到esuser 进行启动

启动与暂停

启动方式1

运行 ./elasticsearch
看到运行结果

[2020-02-02T01:09:51,843][INFO ][o.e.h.AbstractHttpServerTransport] [es-node0] publish_address {192.168.247.8:9200}, bound_addresses {[::]:9200}
[2020-02-02T01:09:51,844][INFO ][o.e.n.Node               ] [es-node0] started
[2020-02-02T01:09:52,199][INFO ][o.e.l.LicenseService     ] [es-node0] license [9614ee2b-6350-4f99-ad43-5ec0d632f93c] mode [basic] - valid
[2020-02-02T01:09:52,200][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [es-node0] Active license is now [BASIC]; Security is disabled
[2020-02-02T01:09:52,222][INFO ][o.e.g.GatewayService     ] [es-node0] recovered [0] indices into cluster_state

访问 192.168.247.8:9200 这里换成你的ip

访问结果

{
  "name": "es-node0",
  "cluster_name": "kevin-elasticsearch",
  "cluster_uuid": "sSzLTAt-SDiCbQ57WMPqlg",
  "version": {
    "number": "7.5.1",
    "build_flavor": "default",
    "build_type": "tar",
    "build_hash": "3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96",
    "build_date": "2019-12-16T22:57:37.835892Z",
    "build_snapshot": false,
    "lucene_version": "8.3.0",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

当前启动方式时前端启动。停止服务的话直接ctrl+c 就好了

启动方式2

我们可以后端启动

./elasticsearch -d

稍等片刻,再次访问地址,还是相同结果

此时,如果想关闭服务

[esuser@localhost bin]$ ps -ef|grep elasticsearch
esuser     3318   3007  0 Feb01 pts/1    00:00:00 vi elasticsearch.yml
esuser     3856      1 21 01:15 pts/0    00:00:18 /usr/local/elasticsearch-7.5.1/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms128m -Xmx128m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-9874251960424438570 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=67108864 -Des.path.home=/usr/local/elasticsearch-7.5.1 -Des.path.conf=/usr/local/elasticsearch-7.5.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.5.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
esuser     3871   3856  0 01:15 pts/0    00:00:00 /usr/local/elasticsearch-7.5.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
esuser     3921   3521  0 01:16 pts/0    00:00:00 grep --color=auto elasticsearch
[esuser@localhost bin]$ jps
3856 Elasticsearch
3922 Jps
[esuser@localhost bin]$ kill 3856
[esuser@localhost bin]$ jps
3940 Jps
[esuser@localhost bin]$ 

原文地址:https://www.cnblogs.com/zhenghengbin/p/12250234.html