ElasticSearch升級指南

背景

舊版本ElasticSearch為6.4.0,升級到官網(wǎng)最新版本7.3.1。

升級步驟

  1. ElasticSearch官網(wǎng)下載最新7.3.1版本,下載地址https://www.elastic.co/cn/downloads/elasticsearch;

  2. 解壓tar.gz文件,進(jìn)入config目錄,設(shè)置elasticsearch.yml文件,具體設(shè)置如下:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: zhangfang
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/lib/elastic
#
# Path to log files:
#
path.logs: /data/log/elastic
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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: 172.28.25.52
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["172.28.25.54:9300", "172.28.25.55:9300","172.28.25.52:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

其中,node.name,path.data,path.logs,network.host,discovery.zen.ping.unicast.hosts根據(jù)實(shí)際情況配置;

  1. 配置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

-Xms2g
-Xmx2g

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

## 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=/data/tmp/elastic

## 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/lib/elastic

## JDK 8 GC logging

8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:/data/log/elastic/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=/data/log/elastic/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

其中 -Xms -Xmx視機(jī)器實(shí)際情況而定;

  1. 禁用分片自動分配,執(zhí)行以下命令:
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster.routing.allocation.enable": "primaries"
  }
}
'
  1. 停止索引并執(zhí)行同步刷新,執(zhí)行以下命令:
curl -X POST "localhost:9200/_flush/synced?pretty"

執(zhí)行同步刷新時,請檢查響應(yīng)以確保沒有失敗。失敗時雖然請求本身仍返回200 OK狀態(tài),但響應(yīng)正文中會列出由于掛起的索引操作而導(dǎo)致的失敗條目。如果有失敗,需要重新發(fā)出請求。

  1. 停止原集群所有節(jié)點(diǎn)的ElasticSearch進(jìn)程,使用kill的方式執(zhí)行;

  2. 啟動新版的ElasticSearch

bin/elasticsearch -Ecluster.initial_master_nodes=node-1,node-2,node-3 -d

注意到啟動命令中有-Ecluster.initial_master_nodes=node-1,node-2,node-3,是因?yàn)樾掳姹臼状螁?,需要制定備選master列表。另外,也可以在elasticsearch.yml文件中添加以下配置:

cluster.initial_master_nodes:
  - node-1
  - node-2
  - node-3

如果是非首次啟動,則無需添加-Ecluster.initial_master_nodes=node-1,node-2,node-3參數(shù)。

  1. 啟動后,通過
curl -X GET "localhost:9200/_cat/health?pretty"
curl -X GET "localhost:9200/_cat/nodes?pretty"

命令查看集群健康度和節(jié)點(diǎn)情況,如果health已為yellow說明集群已啟動。

  1. 恢復(fù)分片分配
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster.routing.allocation.enable": null
  }
}
'

此時,查看集群健康度會發(fā)現(xiàn)健康百分比會慢慢升高,直至100%,status會變?yōu)間reen,至此升級完成。

  1. 本升級因?yàn)樽儎虞^大,根據(jù)官方文檔要求是全量升級,如果是小幅升級,可參考官方文檔進(jìn)行滾動升級。滾動升級時無需集群所有節(jié)點(diǎn)都停止服務(wù),逐臺升級即可。另外,本次升級未考慮ElasticSearch plugin的升級,如有需求,請參考官方文檔。

參考文檔

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容