一、ElasticSearch安裝

ElasticSearch安裝

安裝

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

 

image.png

解決:修改elasticsearch.yml

取消註釋保留一個節點cluster.initial_master_nodes: ["node-1"]

image.png

以前臺啓動/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

image.png

解決:修改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 image.png

解決:根據提示在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

image.png

原因:

這是在因爲Centos6不支持SecComp,而ES5.2.0默認bootstrap.system_call_filter爲true進行檢測,所以導致檢測失敗,失敗後直接導致ES不能啓動。

解決辦法:

在elasticsearch.yml配置文件中加入以下配置

bootstrap.memory_lock: false

bootstrap.system_call_filter: false

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章