1,打開網(wǎng)址 https://www.elastic.co/cn/
點(diǎn)擊產(chǎn)品選擇ElasticSearch+kibana
點(diǎn)擊了解詳情
點(diǎn)擊下載
點(diǎn)擊選擇歷史版本
選擇7.3.0
選擇對應(yīng)的系統(tǒng)版本(注Kibana下載和es 一樣 要求ElasticSeach的版本一致 )
下載后上傳到服務(wù)器
啟動es
./elasticsearch
會遇到
不能用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需要手動隔離
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ò)
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
設(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è)置
在 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