Elasticsearch 学习之不停止服务,完成升级重启维护操作

摘要:
我们可以将集群的平衡参数设置为临时禁用平衡。具体步骤如下:1.如果可能,首先暂停数据添加和更新操作,这将提高集群恢复时间;2.禁用集群碎片平衡操作,直到集群被告知可以恢复平衡操作。禁用配置模式:PUT/_ Cluster/settings{“transient”:{“Cluster.routing.allocation.enable”:“none”}}注意:如果PUT操作不在集群中

我们可以设置集群的平衡参数来暂时禁用掉平衡,具体步骤如下:

1.如果可能的话,先暂停掉数据新增和更新操作,这样会提高集群恢复的时间; 
2.禁用集群分片平衡操作,直到告诉集群可以恢复平衡操作为止,禁用配置方式:

复制代码
PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.enable" : "none"
    }
}
复制代码

注意:put操作的时候,如果不是在集群节点上,需要加上完成的路径,如: 

复制代码
curl -XPUT http://192.168.1.2:9200/_cluster/settings -d’ 
{ 
“transient” : { 
“cluster.routing.allocation.enable” : “none” 
} 
}’ 
复制代码

3.关掉需要维护的节点; 
4.执行维护/升级; 
5.重启该节点,保证该节点顺利加入到集群中; 
6.重启平衡参数配置操作,修改配置方式:

复制代码
PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}
复制代码

注意:节点重启完成后,数据的平衡可能需要一段时间,需要等到到集群状态为绿色为止,在进行其他节点的操作; 
7.重复步骤2-6完成其他节点的维护操作; 
8.如果之前停掉了更新索引的操作,这个时候就可以恢复了。不过要等集群状态健康后,这样能使集群快速恢复健康;

滚动更新操作

IMPORTANT: No additional bug fixes or documentation updates will be released for this version. For the latest information, see the current release documentation.

Rolling upgrades

A rolling upgrade allows an Elasticsearch cluster to be upgraded one node at a time so upgrading does not interrupt service. Running multiple versions of Elasticsearch in the same cluster beyond the duration of an upgrade is not supported, as shards cannot be replicated from upgraded nodes to nodes running the older version.

It is best to upgrade the master-eligible nodes in your cluster after all of the other nodes. Once you have started to upgrade the master-eligible nodes they may form a cluster that nodes of older versions cannot join. If you upgrade the master-eligible nodes last then all the other nodes will not be running an older version and so they will be able to join the cluster.

Rolling upgrades are supported:

Upgrading directly to 7.0.1 from 6.6 or earlier requires a full cluster restart.

Preparing to upgrade

It is important to prepare carefully before starting an upgrade. Once you have started to upgrade your cluster to version 7.0.1 you must complete the upgrade. As soon as the cluster contains nodes of version 7.0.1 it may make changes to its internal state that cannot be reverted. If you cannot complete the upgrade then you should discard the partially-upgraded cluster, deploy an empty cluster of the version before the upgrade, and restore its contents from a snapshot.

Before you start to upgrade your cluster to version 7.0.1 you should do the following.

  1. Check the deprecation log to see if you are using any deprecated features and update your code accordingly.
  2. Review the breaking changes and make any necessary changes to your code and configuration for version 7.0.1.
  3. If you use any plugins, make sure there is a version of each plugin that is compatible with Elasticsearch version 7.0.1.
  4. Test the upgrade in an isolated environment before upgrading your production cluster.
  5. Back up your data by taking a snapshot!

Upgrading your cluster

To perform a rolling upgrade to 7.0.1:

  1. Disable shard allocation.

    When you shut down a node, the allocation process waits for index.unassigned.node_left.delayed_timeout (by default, one minute) before starting to replicate the shards on that node to other nodes in the cluster, which can involve a lot of I/O. Since the node is shortly going to be restarted, this I/O is unnecessary. You can avoid racing the clock by disabling allocation of replicas before shutting down the node:

    PUT _cluster/settings
    {
      "persistent": {
        "cluster.routing.allocation.enable": "primaries"
      }
    }
  2. Stop non-essential indexing and perform a synced flush. (Optional)

    While you can continue indexing during the upgrade, shard recovery is much faster if you temporarily stop non-essential indexing and perform a synced-flush.

    POST _flush/synced

    When you perform a synced flush, check the response to make sure there are no failures. Synced flush operations that fail due to pending indexing operations are listed in the response body, although the request itself still returns a 200 OK status. If there are failures, reissue the request.

  3. Temporarily stop the tasks associated with active machine learning jobs and datafeeds. (Optional)

    If your machine learning indices were created before 6.x, you must reindex the indices.

    If your machine learning indices were created in 6.x, you can:

    • Leave your machine learning jobs running during the upgrade. When you shut down a machine learning node, its jobs automatically move to another node and restore the model states. This option enables your jobs to continue running during the upgrade but it puts increased load on the cluster.
    • Temporarily halt the tasks associated with your machine learning jobs and datafeeds and prevent new jobs from opening by using the set upgrade mode API:

      POST _ml/set_upgrade_mode?enabled=true

      When you disable upgrade mode, the jobs resume using the last model state that was automatically saved. This option avoids the overhead of managing active jobs during the upgrade and is faster than explicitly stopping datafeeds and closing jobs.

    • Stop all datafeeds and close all jobs. This option saves the model state at the time of closure. When you reopen the jobs after the upgrade, they use the exact same model. However, saving the latest model state takes longer than using upgrade mode, especially if you have a lot of jobs or jobs with large model states.
  4. Shut down a single node.

    • If you are running Elasticsearch with systemd:

      sudo systemctl stop elasticsearch.service
    • If you are running Elasticsearch with SysV init:

      sudo -i service elasticsearch stop
    • If you are running Elasticsearch as a daemon:

      kill $(cat pid)
  5. Upgrade the node you shut down.

    To upgrade using a Debian or RPM package:

    • Use rpm or dpkg to install the new package. All files are installed in the appropriate location for the operating system and Elasticsearch config files are not overwritten.

    To upgrade using a zip or compressed tarball:

    1. Extract the zip or tarball to a new directory. This is critical if you are not using external config and data directories.
    2. Set the ES_PATH_CONF environment variable to specify the location of your external config directory and jvm.options file. If you are not using an external config directory, copy your old configuration over to the new installation.
    3. Set path.data in config/elasticsearch.yml to point to your external data directory. If you are not using an external data directory, copy your old data directory over to the new installation.

       

      If you use monitoring features, re-use the data directory when you upgrade Elasticsearch. Monitoring identifies unique Elasticsearch nodes by using the persistent UUID, which is stored in the data directory.

    4. Set path.logs in config/elasticsearch.yml to point to the location where you want to store your logs. If you do not specify this setting, logs are stored in the directory you extracted the archive to.
     

    When you extract the zip or tarball packages, the elasticsearch-n.n.n directory contains the Elasticsearch configdatalogs and plugins directories.

    We recommend moving these directories out of the Elasticsearch directory so that there is no chance of deleting them when you upgrade Elasticsearch. To specify the new locations, use the ES_PATH_CONF environment variable and the path.data and path.logs settings. For more information, see Important Elasticsearch configuration.

    The Debian and RPM packages place these directories in the appropriate place for each operating system. In production, we recommend installing using the deb or rpm package.

     

    You should leave cluster.initial_master_nodes unset while performing a rolling upgrade. Each upgraded node is joining an existing cluster so there is no need for cluster bootstrapping. You must configure either discovery.seed_hosts or discovery.seed_providers on every node.

  6. Upgrade any plugins.

    Use the elasticsearch-plugin script to install the upgraded version of each installed Elasticsearch plugin. All plugins must be upgraded when you upgrade a node.

  7. If you use Elasticsearch security features to define realms, verify that your realm settings are up-to-date. The format of realm settings changed in version 7.0, in particular, the placement of the realm type changed. See Realm settings.
  8. Start the upgraded node.

    Start the newly-upgraded node and confirm that it joins the cluster by checking the log file or by submitting a _cat/nodes request:

    GET _cat/nodes
  9. Reenable shard allocation.

    Once the node has joined the cluster, remove the cluster.routing.allocation.enable setting to enable shard allocation and start using the node:

    PUT _cluster/settings
    {
      "persistent": {
        "cluster.routing.allocation.enable": null
      }
    }
  10. Wait for the node to recover.

    Before upgrading the next node, wait for the cluster to finish shard allocation. You can check progress by submitting a _cat/health request:

    GET _cat/health?v

    Wait for the status column to switch from yellow to green. Once the node is green, all primary and replica shards have been allocated.

     

    During a rolling upgrade, primary shards assigned to a node running the new version cannot have their replicas assigned to a node with the old version. The new version might have a different data format that is not understood by the old version.

    If it is not possible to assign the replica shards to another node (there is only one upgraded node in the cluster), the replica shards remain unassigned and status stays yellow.

    In this case, you can proceed once there are no initializing or relocating shards (check the init and relo columns).

    As soon as another node is upgraded, the replicas can be assigned and the status will change to green.

    Shards that were not sync-flushed might take longer to recover. You can monitor the recovery status of individual shards by submitting a _cat/recovery request:

    GET _cat/recovery

    If you stopped indexing, it is safe to resume indexing as soon as recovery completes.

  11. Repeat

    When the node has recovered and the cluster is stable, repeat these steps for each node that needs to be updated.

  12. Restart machine learning jobs.

    If you temporarily halted the tasks associated with your machine learning jobs, use the set upgrade mode API to return them to active states:

    POST _ml/set_upgrade_mode?enabled=false

    If you closed all machine learning jobs before the upgrade, open the jobs and start the datafeeds from Kibana or with the open jobs and start datafeed APIs.

 

During a rolling upgrade, the cluster continues to operate normally. However, any new functionality is disabled or operates in a backward compatible mode until all nodes in the cluster are upgraded. New functionality becomes operational once the upgrade is complete and all nodes are running the new version. Once that has happened, there’s no way to return to operating in a backward compatible mode. Nodes running the previous major version will not be allowed to join the fully-updated cluster.

In the unlikely case of a network malfunction during the upgrade process that isolates all remaining old nodes from the cluster, you must take the old nodes offline and upgrade them to enable them to join the cluster.

If you stop half or more of the master-eligible nodes all at once during the upgrade then the cluster will become unavailable, meaning that the upgrade is no longer a rolling upgrade. If this happens, you should upgrade and restart all of the stopped master-eligible nodes to allow the cluster to form again, as if performing a full-cluster restart upgrade. It may also be necessary to upgrade all of the remaining old nodes before they can join the cluster after it re-forms.

Similarly, if you run a testing/development environment with only one master node, the master node should be upgraded last. Restarting a single master node forces the cluster to be reformed. The new cluster will initially only have the upgraded master node and will thus reject the older nodes when they re-join the cluster. Nodes that have already been upgraded will successfully re-join the upgraded master.

官网:

https://www.elastic.co/guide/en/elasticsearch/reference/7.0/rolling-upgrades.html

转自:https://blog.csdn.net/likui1314159/article/details/51728567

免责声明:文章转载自《Elasticsearch 学习之不停止服务,完成升级重启维护操作》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇二叉树的直径机器学习自动写诗-学习笔记下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Notification(Notification的通知栏常驻、Notification的各种样式、Notification点击无效)

所以Notification的使用,也在开发当中,使用的越来越频繁。今天我就来跟大家分享一下Notification的常用事项。最新的Notification的用法,是推荐使用V4包下的NotificationCompat.Builder,利用它,进行各种设置,具体的用法先别着急,我们慢慢道来。//Notification.DEFAULT_SOUND:系统默...

django的优缺点(非原创)

Django做了很多。使用它快速开发一些Web应用程序是很好的。因此,在一些人眼中,Django只不过是一种灵丹妙药,但对一些人来说,它也是一种毒药和剧毒。Django开发人员也讨论并试图支持SQLAlchemy,但最终放弃了。据估计,成本太高,很难与Django的其他模块集成。尽管Django的ORM不如SQLAlchemy强大,但它并不弱。Django的...

禅道从windows迁移到linux

windows下图片路径/zentao/www/data/upload/1备份到Linux下路径/opt/zbox/app/zentao/www/data/upload/1二、Linux下安装禅道注意一定要安装相同版本的禅道2.1、安装禅道有很多方法,禅道官网也有详细说明,这里主要讲linux用一键安装包及遇到的问题2.2、下载安装包禅道官网下载界面很乱,大...

移动通信网络中的 GTP 协议

在EPSUP中使用GTP的优点之一是GTP具有固有的可识别隧道机制和GTP可以为UE提供的移动性。注意:GTPv2-U协议不存在。GTP-C协议GTP-C是GTP的控制平面,使用UDP端口2123。在EPS中,GTPv2-C协议负责创建、维护和删除S1、S5/S8和其他接口上的GTP-U隧道。它是一种基于IP的隧道协议,允许在GTP UProtocolEnt...

【解决方法】ModuleNotFoundError: No module named 'flask._compat'

起源最近发下很多人在我的python课程下面提问,关于安装完扩展运行程序的时候出现如下的莫名其妙的错误Traceback(mostrecentcalllast):File"manage_web.py",line2,infromapplicationimportapp,managerFile"/data/www/private_deploy/python3_y...

nginx配置跨域(CORS)、防盗链(valid_referers)、缓存(expires)、压缩(gzip)

它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服AJAX只能同源使用的限制。服务器根据这个值,在许可范围内,则在头信息包含Access-Control-Allow-Origin。...