Centos7 安裝ElasticSearch7 及其Kibana環(huán)境安裝

1,打開網(wǎng)址 https://www.elastic.co/cn/

點(diǎn)擊產(chǎn)品選擇ElasticSearch+kibana


image.png

點(diǎn)擊了解詳情


image.png

點(diǎn)擊下載
image.png

點(diǎn)擊選擇歷史版本


image.png

選擇7.3.0
image.png

選擇對應(yīng)的系統(tǒng)版本(注Kibana下載和es 一樣 要求ElasticSeach的版本一致 )
image.png

下載后上傳到服務(wù)器

啟動es
./elasticsearch
會遇到


image.png

不能用root權(quán)限啟動
1誊锭,創(chuàng)建用戶elasticsearch
adduser elasticsearch
2蚯姆,創(chuàng)建用戶密碼,需要輸入兩次
passwd elasticsearch
3,將對應(yīng)的文件夾權(quán)限賦給該用戶
chown -R elasticsearch elasticsearch-7.3.0
4,切換到elasticsearch用戶
su elasticsearch
5么抗,進(jìn)入啟動目錄啟動
elasticsearch-7.3.0/bin 使用后臺啟動方式:./elasticsearch -d

報(bào)java環(huán)境不兼容的錯(cuò)誤

elasticsearch-7.3.0 要求用jdk11 但是是開發(fā)環(huán)境是jdk11需要手動隔離

image.png

1下載jdk11的包
https://www.oracle.com/java/technologies/javase-jdk11-downloads.html#license-lightbox
2解壓到指定位置
tar -xzvf jdk-11.0.6_linux-x64_bin.tar.gz /data/softwear/es
3,修改配置文件
cd dao elasticsearch/bin
vi elasticsearch

#配置自己的jdk11
export JAVA_HOME=/data/softweare/jdk-11.0.6
export PATH=$JAVA_HOME/bin:$PATH

#添加jdk判斷
if [ -x "$JAVA_HOME/bin/java" ]; then
        JAVA="/data/softweare/jdk-11.0.6/bin/java"
else
        JAVA=`which java`
fi

完整的代碼


#配置自己的jdk11
export JAVA_HOME=/data/softweare/jdk-11.0.6
export PATH=$JAVA_HOME/bin:$PATH



source "`dirname "$0"`"/elasticsearch-env

if [ -z "$ES_TMPDIR" ]; then
  ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi

ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
ES_JAVA_OPTS="${JVM_OPTIONS//\$\{ES_TMPDIR\}/$ES_TMPDIR}"

#添加jdk判斷
if [ -x "$JAVA_HOME/bin/java" ]; then
        JAVA="/data/softweare/jdk-11.0.6/bin/java"
else
        JAVA=`which java`
fi

# manual parsing to find out, if process should be detached
if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
  exec \
    "$JAVA" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@"
else
  exec \
    "$JAVA" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@" \
    <&- &
  retval=$?
  pid=$!
  [ $retval -eq 0 ] || exit $retval
  if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
    sleep $ES_STARTUP_SLEEP_TIME
  fi
  if ! ps -p $pid > /dev/null ; then
    exit 1
  fi
  exit 0
fi

exit $?

啟動es

[esuser@localhost bin]$ ./elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-08-02T15:33:27,994][INFO ][o.e.e.NodeEnvironment    ] [node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [32.6gb], net total_space [35.7gb], types [rootfs]
[2019-08-02T15:33:28,014][INFO ][o.e.e.NodeEnvironment    ] [node-1] heap size [1015.6mb], compressed ordinary object pointers [true]
[2019-08-02T15:33:28,017][INFO ][o.e.n.Node               ] [node-1] node name [node-1], node ID [8zGCWQhBS3OpVShqjSgU-w], cluster name [es-application]
[2019-08-02T15:33:28,017][INFO ][o.e.n.Node               ] [node-1] version[7.2.0], pid[1545], build[default/tar/508c38a/2019-06-20T15:54:18.811730Z], OS[Linux/3.10.0-862.el7.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/11.0.1/11.0.1+13]
[2019-08-02T15:33:28,017][INFO ][o.e.n.Node               ] [node-1] JVM home [/opt/jdk-11.0.1]
[2019-08-02T15:33:28,018][INFO ][o.e.n.Node               ] [node-1] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch-5247006010869253587, -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, -Djava.locale.providers=COMPAT, -Dio.netty.allocator.type=unpooled, -XX:MaxDirectMemorySize=536870912, -Des.path.home=/usr/local/src/elasticsearch, -Des.path.conf=/usr/local/src/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]

到這里我們又看到另一個(gè)警告

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
這是提醒你 cms 垃圾收集器在 jdk9 就開始被標(biāo)注為 @deprecated

看下JDK11支持的垃圾回收器
HotSpot Virtual Machine Garbage Collection Tuning Guide

修改jvm.options
-XX:+UseConcMarkSweepGC
改為:-XX:+UseG1GC
完整配置如下

## 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

################################################################
## 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
## 原有的注釋了盲厌,添加了G1回收器
## -XX:+UseConcMarkSweepGC
-XX:+UseG1GC
-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:InitiatingHeapOccupancyPercent=75

## 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

# 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

重新啟動
bin/elasticsearch -d
然而沒成功依然報(bào)錯(cuò)


image.png

solutions:
先要切換到root用戶岩馍;
然后可以執(zhí)行以下命令粱檀,設(shè)置 vm.max_map_count ,但是重啟后又會恢復(fù)為原值迫像。

sysctl -w vm.max_map_count=262144

持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 參數(shù):

sysctl -p

然后重啟 還是報(bào)錯(cuò)

[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
取消注釋保留一個(gè)節(jié)點(diǎn)
cluster.initial_master_nodes: ["node-1"]
這個(gè)的話劈愚,這里的node-1是上面一個(gè)默認(rèn)的記得打開就可以了

繼續(xù)重啟 重啟成功但9200訪問不了
修改yml
network.host: 0.0.0.0
http.port: 9200

# ----------------------------------- 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.

再次重啟 重啟不了發(fā)現(xiàn)服務(wù)已經(jīng)重啟 lsof -i:9200也沒東西
ps -ef|grep elastic
kill -9 所有的進(jìn)程
然后再su elasticsearch下

./elasticsearch -d 成功啟動

//訪問9200


image.png

設(shè)置ES的密碼

1設(shè)置elasticsearch.yml 添加如下

cluster.name: esbest
node.name: node127-9200
node.master: true
path.data: /data/softweare/es/elasticsearch-7.3.0/data
path.logs: /data/softweare/es/elasticsearch-7.3.0/logs

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

http.port: 9200
transport.tcp.port: 9300

network.host: 0.0.0.0
discovery.type: single-node

xpack.security.enabled: true


重啟es
cd 到bin 目錄下執(zhí)行
./elasticsearch-setup-passwords interactive (有可能提示java不兼容參考上邊的解決辦法) 記下你設(shè)置的密碼

設(shè)置es最大分頁限制

PUT /productinfokeypro/_settings
{ "index.max_result_window" :"1000000"}

簡直吐血的經(jīng)歷!N偶恕>稹!

2020-09-07更新

優(yōu)化es性能
報(bào)這樣的錯(cuò)誤type=circuit_breaking_exception, reason=[parent] Data too large, data for [<http_request>] would be [1663333912/1.5gb], which is larger than the limit of [1662202675/1.5gb], real usage: [1659250080/1.5gb], new bytes reserved: [4083832/3.8mb], usages [request=1359872/1.2mb, fielddata=0/0b, in_flight_requests=17784334/16.9mb, accounting=551349/538.4kb]]]
在jvm.options 里設(shè)置


image.png

在 elasticsearch.yml 里設(shè)置

# 避免發(fā)生OOM由缆,發(fā)生OOM對集群影響很大的
indices.breaker.total.limit: 60%
# 有了這個(gè)設(shè)置注祖,最久未使用(LRU)的 fielddata 會被回收為新數(shù)據(jù)騰出空間
indices.fielddata.cache.size: 40%
# fielddata 斷路器默認(rèn)設(shè)置堆的  作為 fielddata 大小的上限。
indices.breaker.fielddata.limit: 60%
# request 斷路器估算需要完成其他請求部分的結(jié)構(gòu)大小均唉,例如創(chuàng)建一個(gè)聚合桶是晨,默認(rèn)限制是堆內(nèi)存
indices.breaker.request.limit: 60%
# 父級斷路器是否應(yīng)考慮實(shí)際內(nèi)存使用情況(true)或僅考慮子級斷路器保留的數(shù)量(false)。默認(rèn)為true
# 整個(gè)父級斷點(diǎn)器的啟動限制舔箭,如果indices.breaker.total.use_real_memory: false 默認(rèn)為JVM堆的70% of the JVM heap., 否則為95% of the JVM heap
indices.breaker.total.use_real_memory: false
#關(guān)閉circuit檢查:
#indices.breaker.type: none
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末罩缴,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子层扶,更是在濱河造成了極大的恐慌箫章,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,222評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件镜会,死亡現(xiàn)場離奇詭異檬寂,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)戳表,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,455評論 3 385
  • 文/潘曉璐 我一進(jìn)店門桶至,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人匾旭,你說我怎么就攤上這事镣屹。” “怎么了季率?”我有些...
    開封第一講書人閱讀 157,720評論 0 348
  • 文/不壞的土叔 我叫張陵野瘦,是天一觀的道長描沟。 經(jīng)常有香客問我飒泻,道長鞭光,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,568評論 1 284
  • 正文 為了忘掉前任泞遗,我火速辦了婚禮惰许,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘史辙。我一直安慰自己汹买,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,696評論 6 386
  • 文/花漫 我一把揭開白布聊倔。 她就那樣靜靜地躺著晦毙,像睡著了一般。 火紅的嫁衣襯著肌膚如雪耙蔑。 梳的紋絲不亂的頭發(fā)上见妒,一...
    開封第一講書人閱讀 49,879評論 1 290
  • 那天,我揣著相機(jī)與錄音甸陌,去河邊找鬼须揣。 笑死,一個(gè)胖子當(dāng)著我的面吹牛钱豁,可吹牛的內(nèi)容都是我干的耻卡。 我是一名探鬼主播,決...
    沈念sama閱讀 39,028評論 3 409
  • 文/蒼蘭香墨 我猛地睜開眼牲尺,長吁一口氣:“原來是場噩夢啊……” “哼卵酪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起谤碳,我...
    開封第一講書人閱讀 37,773評論 0 268
  • 序言:老撾萬榮一對情侶失蹤凛澎,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后估蹄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體塑煎,經(jīng)...
    沈念sama閱讀 44,220評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,550評論 2 327
  • 正文 我和宋清朗相戀三年臭蚁,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了最铁。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,697評論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡垮兑,死狀恐怖冷尉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情系枪,我是刑警寧澤雀哨,帶...
    沈念sama閱讀 34,360評論 4 332
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響雾棺,放射性物質(zhì)發(fā)生泄漏膊夹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,002評論 3 315
  • 文/蒙蒙 一捌浩、第九天 我趴在偏房一處隱蔽的房頂上張望放刨。 院中可真熱鬧,春花似錦尸饺、人聲如沸进统。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,782評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽螟碎。三九已至,卻和暖如春迹栓,著一層夾襖步出監(jiān)牢的瞬間抚芦,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,010評論 1 266
  • 我被黑心中介騙來泰國打工迈螟, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留叉抡,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,433評論 2 360
  • 正文 我出身青樓答毫,卻偏偏與公主長得像褥民,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子洗搂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,587評論 2 350

推薦閱讀更多精彩內(nèi)容