ElasticSearch安装
安装【Linux版】
1. 使用root用户创建一个其他用户,(elasticsearch不能在root账户下安装)
# 添加一个名字是es工作组
groupadd es
# 添加用户es设置密码elasticsearch并设置工作组es
useradd es -g es -p elasticsearch
#切换到es用户下
su - es
#输入密码elasticsearch进入es用户
2. 下载elasticsearch包
https://www.elastic.co/cn/downloads/past-releases 这是elasticsearch的历史版本下载地址
注意:ES依赖JKD,不同版本依赖不同版本的JKD,所以在选择ES版本的时候要注意这个地方
由于我是在centos上安装的,我直接用wget下载,我选择的是7.4.2版本
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz
3. 安装启动
1) 下载好之后是个tar.gz压缩包,解压
# 解压缩包
tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz
2)进入elasticsearch-7.4.2目录
可以先大体看一下bin和config目录中的配置和脚本,我们只需要运行bin目录下的elasticsearch脚本就能启动我们的ES,但是这样启动是前台启动,如果想要后台启动需要加上-d
#注意,启动elasticsearch需要依赖jdk环境变量,需提前配置好,否则报错
#前台启动
./elasticsearch
#后台启动
./elasticsearch -d
#查看启动是否成功以及健康状态信息
curl localhost:9200/_cat/health?v
[root@localhost ~]# curl localhost:9200/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1592801415 04:50:15 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
[root@localhost ~]#
安装过程中遇到的问题汇总
问题一:外网无法访问
安装完成之后发现远程无法访问,我们需要在config/elasticsearch.yml配置文件中添加network.host: 0.0.0.0
但是在添加了这个之后会冒出来这么个错误
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决:修改elasticsearch.yml
取消注释保留一个节点cluster.initial_master_nodes: ["node-1"]
以前台启动/bin/elasticsearch以便查看报错信息
./elasticsearch
#如果为发现报错信息则使用curl验证是否启动成功
curl localhost:9200[或当前节点IP:9200]/_cat/health?v
[root@localhost ~]# curl localhost[IP]:9200/_cat/health?v epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1592802566 05:09:26 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
#如果本地访问通过,则证明启动成功,可以远程访问elasticsearch:IP:9200/_cat/health?v
[root@localhost ~]# curl localhost[IP]:9200/_cat/health?v epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1592802566 05:09:26 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
问题二:Cannot allocate memory
解决:修改vm.yml文件,把以下两个配置调小
## 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
#-Xms1g
#-Xmx1g
-Xms500m
-Xmx500m
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
## G1GC Configuration
# NOTE: G1GC is only supported on JDK version 10 or later.
# To use G1GC uncomment the lines below.
# 10-:-XX:-UseConcMarkSweepGC
# 10-:-XX:-UseCMSInitiatingOccupancyOnly
# 10-:-XX:+UseG1GC
# 10-:-XX:G1ReservePercent=25
# 10-:-XX:InitiatingHeapOccupancyPercent=30
## DNS cache policy
# cache ttl in seconds for positive DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.ttl; set to -1 to cache forever
-Des.networkaddress.cache.ttl=60
# cache ttl in seconds for negative DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.negative ttl; set to -1 to cache
# forever
-Des.networkaddress.cache.negative.ttl=10
## optimizations
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# explicitly set the stack size
-Xss1m
# set to headless, just in case
-Djava.awt.headless=true
# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8
# use our provided JNA always versus the system one
-Djna.nosys=true
# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow
# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
-Dio.netty.allocator.numDirectArenas=0
# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Djava.io.tmpdir=${ES_TMPDIR}
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
# time/date parsing will break in an incompatible way for some date patterns and locals
9-:-Djava.locale.providers=COMPAT
问题三:X-Pack is not supported and Machine Learning is not available for
解决:根据提示在config/elasticsearch.yml中添加一条配置xpack.ml.enabled: false
问题四:system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因:
这是在因为Centos6不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。
解决办法:
在elasticsearch.yml配置文件中加入以下配置
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
安装【Windows版】
Elasticsearch win下载
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.0-windows-x86_64.zip
解压:
注意:es7 windows版本不支持机器学习,所以config/elasticsearch.yml中添加如下几个参数:
#设置节点名称
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
#解决不支持机器学习功能
xpack.ml.enabled: false
#解决跨域问题
http.cors.enabled: true
http.cors.allow-origin: /.*/
启动Elasticsearch:bin\elasticsearch.bat
Kibana win下载
https://artifacts.elastic.co/downloads/kibana/kibana-7.3.0-windows-x86_64.zip
解压:
修改配置:
i18n.locale: "zh-CN"