4.3.8. 执行 Elasticsearch 集群滚动重启

在更改 elasticsearch 配置映射或任何 elasticsearch-* 部署配置时,执行滚动重启。

此外,如果运行 Elasticsearch Pod 的节点需要重启,则建议滚动重启。

先决条件

  • 必须安装 OpenShift Logging 和 Elasticsearch。

流程

执行集群滚动重启:

  1. 进入 openshift-logging 项目:

    $ oc project openshift-logging
  2. 获取 Elasticsearch Pod 的名称:

    $ oc get pods | grep elasticsearch-
  3. 缩减 Fluentd pod,以便它们停止向 Elasticsearch 发送新日志:

    $ oc -n openshift-logging patch daemonset/logging-fluentd -p '{"spec":{"template":{"spec":{"nodeSelector":{"logging-infra-fluentd": "false"}}}}}'
  4. 使用 OpenShift Container Platform es_util 工具执行分片同步刷新,确保在关机之前没有等待写入磁盘的待定操作:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query="_flush/synced" -XPOST

    例如:

    $ oc exec -c elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6  -c elasticsearch -- es_util --query="_flush/synced" -XPOST

    输出示例

    {"_shards":{"total":4,"successful":4,"failed":0},".security":{"total":2,"successful":2,"failed":0},".kibana_1":{"total":2,"successful":2,"failed":0}}

  5. 使用 OpenShift Container Platform es_util 工具防止在有意关闭节点时进行分片平衡:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query="_cluster/settings" -XPUT -d '{ "persistent": { "cluster.routing.allocation.enable" : "primaries" } }'

    例如:

    $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query="_cluster/settings" -XPUT -d '{ "persistent": { "cluster.routing.allocation.enable" : "primaries" } }'

    输出示例

    {"acknowledged":true,"persistent":{"cluster":{"routing":{"allocation":{"enable":"primaries"}}}},"transient":

  6. 完成后,会在每个部署中都有一个 ES 集群:

    1. 默认情况下,OpenShift Container Platform Elasticsearch 集群会阻止向其节点推出部署。使用以下命令来允许推出部署并允许 Pod 获取更改:

      $ oc rollout resume deployment/<deployment-name>

      例如:

      $ oc rollout resume deployment/elasticsearch-cdm-0-1

      输出示例

      deployment.extensions/elasticsearch-cdm-0-1 resumed

      部署了一个新 Pod。当 Pod 具有就绪的容器后,就能继续进行下一部署。

      $ oc get pods | grep elasticsearch-

      输出示例

      NAME                                            READY   STATUS    RESTARTS   AGE
      elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6k    2/2     Running   0          22h
      elasticsearch-cdm-5ceex6ts-2-f799564cb-l9mj7    2/2     Running   0          22h
      elasticsearch-cdm-5ceex6ts-3-585968dc68-k7kjr   2/2     Running   0          22h

    2. 部署完成后,重置 Pod 以禁止推出部署:

      $ oc rollout pause deployment/<deployment-name>

      例如:

      $ oc rollout pause deployment/elasticsearch-cdm-0-1

      输出示例

      deployment.extensions/elasticsearch-cdm-0-1 paused

    3. 检查 Elasticsearch 集群是否处于 greenyellow 状态:

      $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query=_cluster/health?pretty=true
      注意

      如果您对先前命令中使用的 Elasticsearch Pod 执行了推出部署,该 Pod 将不再存在,并且此处需要使用新的 Pod 名称。

      例如:

      $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query=_cluster/health?pretty=true
      {
        "cluster_name" : "elasticsearch",
        "status" : "yellow", 1
        "timed_out" : false,
        "number_of_nodes" : 3,
        "number_of_data_nodes" : 3,
        "active_primary_shards" : 8,
        "active_shards" : 16,
        "relocating_shards" : 0,
        "initializing_shards" : 0,
        "unassigned_shards" : 1,
        "delayed_unassigned_shards" : 0,
        "number_of_pending_tasks" : 0,
        "number_of_in_flight_fetch" : 0,
        "task_max_waiting_in_queue_millis" : 0,
        "active_shards_percent_as_number" : 100.0
      }
      1
      在继续操作前,请确保此参数值为 green 或者 yellow
  7. 如果更改了 Elasticsearch 配置映射,请对每个 Elasticsearch Pod 重复这些步骤。
  8. 推出集群的所有部署后,重新启用分片平衡:

    $ oc exec <any_es_pod_in_the_cluster> -c elasticsearch -- es_util --query="_cluster/settings" -XPUT -d '{ "persistent": { "cluster.routing.allocation.enable" : "all" } }'

    例如:

    $ oc exec elasticsearch-cdm-5ceex6ts-1-dcd6c4c7c-jpw6 -c elasticsearch -- es_util --query="_cluster/settings" -XPUT -d '{ "persistent": { "cluster.routing.allocation.enable" : "all" } }'

    输出示例

    {
      "acknowledged" : true,
      "persistent" : { },
      "transient" : {
        "cluster" : {
          "routing" : {
            "allocation" : {
              "enable" : "all"
            }
          }
        }
      }
    }

  9. 扩展 Fluentd Pod,以便它们向 Elasticsearch 发送新日志。

    $ oc -n openshift-logging patch daemonset/logging-fluentd -p '{"spec":{"template":{"spec":{"nodeSelector":{"logging-infra-fluentd": "true"}}}}}'