一、安装Elasticsearch
运行指令下载Elasticsearch
docker pull docker.io/elasticsearch:7.4.2 docker run -p 9200:9200 -p 9300:9300 -v /data/docker_host/es/data:/usr/share/elasticsearch/data -v /data/docker_host/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml --privileged=true --name elasticsearch1 elasticsearch:7.4.2
#集群名称 所有节点要相同 cluster.name: "mangues_es" #本节点名称 node.name: "es_01" #作为master节点 node.master: true #是否存储数据 node.data: true #head插件设置 http.cors.enabled: true http.cors.allow-origin: "*" #设置可以访问的ip 这里全部设置通过 network.bind_host: 0.0.0.0 #设置节点 访问的地址 设置master所在机器的ip #network.publish_host: 192.168.0.164 #将当前节点加入到组中,不设置此项在设置密码时会报错,此项的名称必须是node.name中定义的 cluster.initial_master_nodes: ["es_01"] #启用es访问权限 xpack.security.enabled: true
启用权限验证:
进入到容器:
3、设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system。(interactive 手动设置, auto 自动生成密码 )
- bin/elasticsearch-setup-passwords interactive
下面的方式是自动生成密码 , 自动生成相对安全
- bin/elasticsearch-setup-passwords auto
如果启动时提示:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;
解决:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
es遇到的问题及处理方法:
启用x-pack的密码验证 # 生成证书 [root@sz_kp_wanghong_dev01_18_92:/opt/es-node/elasticsearch-6.8.4]# bin/elasticsearch-certutil ca This tool assists you in the generation of X.509 certificates and certificate signing requests for use with SSL/TLS in the Elastic stack. The 'ca' mode generates a new 'certificate authority' This will create a new X.509 certificate and private key that can be used to sign certificate when running in 'cert' mode. Use the 'ca-dn' option if you wish to configure the 'distinguished name' of the certificate authority By default the 'ca' mode produces a single PKCS#12 output file which holds: * The CA certificate * The CA's private key If you elect to generate PEM format certificates (the -pem option), then the output will be a zip file containing individual files for the CA certificate and private key Please enter the desired output file [elastic-stack-ca.p12]: Enter password for elastic-stack-ca.p12 : [root@sz_kp_wanghong_dev01_18_92:/opt/es-node/elasticsearch-6.8.4]# ls bin config elastic-stack-ca.p12 lib LICENSE.txt logs modules NOTICE.txt plugins README.textile [root@sz_kp_wanghong_dev01_18_92:/opt/es-node/elasticsearch-6.8.4]# bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 This tool assists you in the generation of X.509 certificates and certificate signing requests for use with SSL/TLS in the Elastic stack. The 'cert' mode generates X.509 certificate and private keys. * By default, this generates a single certificate and key for use on a single instance. * The '-multiple' option will prompt you to enter details for multiple instances and will generate a certificate and key for each one * The '-in' option allows for the certificate generation to be automated by describing the details of each instance in a YAML file * An instance is any piece of the Elastic Stack that requires an SSL certificate. Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats may all require a certificate and private key. * The minimum required value for each instance is a name. This can simply be the hostname, which will be used as the Common Name of the certificate. A full distinguished name may also be used. * A filename value may be required for each instance. This is necessary when the name would result in an invalid file or directory name. The name provided here is used as the directory name (within the zip) and the prefix for the key and certificate files. The filename is required if you are prompted and the name is not displayed in the prompt. * IP addresses and DNS names are optional. Multiple values can be specified as a comma separated string. If no IP addresses or DNS names are provided, you may disable hostname verification in your SSL configuration. * All certificates generated by this tool will be signed by a certificate authority (CA). * The tool can automatically generate a new CA for you, or you can provide your own with the -ca or -ca-cert command line options. By default the 'cert' mode produces a single PKCS#12 output file which holds: * The instance certificate * The private key for the instance certificate * The CA certificate If you specify any of the following options: * -pem (PEM formatted output) * -keep-ca-key (retain generated CA key) * -multiple (generate multiple certificates) * -in (generate certificates from an input file) then the output will be be a zip file containing individual certificate/key files Enter password for CA (elastic-stack-ca.p12) : Please enter the desired output file [elastic-certificates.p12]: Enter password for elastic-certificates.p12 : Certificates written to /opt/es-node/elasticsearch-6.8.4/elastic-certificates.p12 This file should be properly secured as it contains the private key for your instance. This file is a self contained file and can be copied and used 'as is' For each Elastic product that you wish to configure, you should copy this '.p12' file to the relevant configuration directory and then follow the SSL configuration instructions in the product guide. For client applications, you may only need to copy the CA certificate and configure the client to trust this certificate. # 修改config/elasticsearch.yml配置 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/local/elasticsearch/config/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/local/elasticsearch/config/elastic-certificates.p12 # 配置密码 [es@sz_kp_wanghong_dev01_18_92:/opt/es-node/elasticsearch-6.8.4]$ bin/elasticsearch-setup-passwords interactive Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic] 密码:espass [es@sz_kp_wanghong_dev01_18_92:/opt/es-node/elasticsearch-6.8.4]$ curl --user elastic:espass -XGET 'http://10.10.18.92:9200/_cat/indices' green open channel_rel ZeeBbkogT5KtxzziUYtu_Q 2 1 459528 0 337.7mb 168.8mb green open .security-6 iQHndFBqRe2Ss2o7KMxyFg 1 1 6 0 38.3kb 19.1kb green open .kibana lY82G_-XSniyd_bnMOLuQg 1 1 15 1 292.6kb 146.3kb green open influecer RQtQWXKIRE2UYyZlCvv7bA 3 1 148526 48641 545.6mb 272.8mb green open channel vRFQoIhmT8WmSbDCfph0ag 3 1 53374 0 88.4mb 44.2mb green open channel_list 1dk8uH8bTeikez0lFR2mJg 3 1 5522172 78630 14gb 7gb green open video HNhyt9ioSEayAotGVXRCVg 2 1 798369 228155 3.3gb 1.6gb 升级方式2:完全重启集群升级 即配置好全新的elasticsearch7.4.2集群,然后把数据恢复到新集群中 下载地址:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz 老版本的配置 # cms elasticsearch [root@szyyelk01t opt]# egrep -v '^#|^$' elk-master/config/elasticsearch.yml cluster.name: cms-uat-elastic node.name: master path.data: /opt/elk-master/data/data01,/opt/elk-master/data/data02 path.logs: /opt/elk-master/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.10.18.90 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" [root@szyyelk01t elk-slave]# egrep -v '^$|^#' slave01/config/elasticsearch.yml cluster.name: cms-uat-elastic node.name: slave01 path.data: /opt/elk-slave/slave01/data/data01,/opt/elk-slave/slave01/data/data02 path.logs: /opt/elk-slave/slave01/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.10.18.90 http.port: 8200 discovery.zen.ping.unicast.hosts: ["10.10.18.90"] http.cors.enabled: true http.cors.allow-origin: "*" [root@szyyelk01t elk-slave]# egrep -v '^$|^#' slave02/config/elasticsearch.yml cluster.name: cms-uat-elastic node.name: slave02 path.data: /opt/elk-slave/slave02/data/data01,/opt/elk-slave/slave02/data/data02 path.logs: /opt/elk-slave/slave02/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.10.18.90 http.port: 8201 discovery.zen.ping.unicast.hosts: ["10.10.18.90"] http.cors.enabled: true http.cors.allow-origin: "*" # 已经升级的线上配置参考: [root@eus_filmora_db01:/usr/local/elasticsearch-7.4.1]# egrep -v '^$|^#' config/elasticsearch.yml cluster.name: UOS_CLUSTER_ES node.name: uos_node_1 path.data: /data/elasticsearch_data/data path.logs: /data/elasticsearch_data/logs bootstrap.memory_lock: true network.host: 172.20.103.199 http.port: 9200 transport.tcp.port: 9300 node.master: true node.data: true discovery.seed_hosts: ["172.20.103.199:9300", "172.20.73.200:9300", "172.20.73.212:9300"] cluster.initial_master_nodes: ["172.20.103.199", "172.20.73.200", "172.20.73.212"] gateway.recover_after_nodes: 2 transport.tcp.compress: true path.repo: ["/data/bak_es"] xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/local/elasticsearch/config/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/local/elasticsearch/config/elastic-certificates.p12 ############## cms 系统的 elasticsearch 6升级7.4.2 整体策略: 1.升级cms测试环境的es到7.4.2,然后做适配性的开发,再次升级内网的生产环境 --> cms海外环境(找海外业务不繁忙的时候操作,先和开发协商好) 测试环境其他人依赖进行测试,所以升级需要两套并存,新版本的es7.4.2使用自带的openjdk13.0 1.配置新版本的elasticsearch使用指定的jdk环境 # vim bin/elasticsear export JAVA_HOME=/opt/elk7_onenode/elasticsearch-7.4.2/jdk export PATH=$JAVA_HOME/bin:$PATH mkdir /opt/elk7_onenode/elasticsearch-7.4.2/data # 主节点配置 [elastic@szyyelk01t elasticsearch-7.4.2]$ more config/elasticsearch.yml cluster.name: cms-uat-elastic7 node.name: cms_node01 node.master: true node.data: true discovery.seed_hosts: ["10.10.18.90:19300", "10.10.18.117:19300"] cluster.initial_master_nodes: ["10.10.18.90"] path.data: /opt/cms_elk7/elasticsearch-7.4.2/data path.logs: /opt/cms_elk7/elasticsearch-7.4.2/logs discovery.zen.minimum_master_nodes: 1 bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.10.18.90 http.cors.enabled: true http.cors.allow-origin: "*" transport.tcp.compress: true path.repo: ["/opt/esback/"] gateway.recover_after_nodes: 1 # 增加新的参数head插件可以访问es http.port: 19200 transport.tcp.port: 19300 gateway.recover_after_time: 8m # 以下配置可以减少当es节点短时间宕机或重启时shards重新分布带来的磁盘io读写浪费 discovery.zen.fd.ping_timeout: 300s discovery.zen.fd.ping_retries: 8 discovery.zen.fd.ping_interval: 30s discovery.zen.ping_timeout: 180s # 启用安全认证 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12 # 第二个节点配置 [elastic@cms-test:/opt/cms_elk7/elasticsearch-7.4.2]$ more config/elasticsearch.yml cluster.name: cms-uat-elastic7 node.name: cms_node02 node.master: false node.data: true discovery.seed_hosts: ["10.10.18.90:19300", "10.10.18.117:19300"] cluster.initial_master_nodes: ["10.10.18.90"] path.data: /opt/cms_elk7/elasticsearch-7.4.2/data path.logs: /opt/cms_elk7/elasticsearch-7.4.2/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 10.10.18.117 http.cors.enabled: true http.cors.allow-origin: "*" transport.tcp.compress: true path.repo: ["/opt/esback/"] gateway.recover_after_nodes: 1 # 增加新的参数head插件可以访问es http.port: 19200 transport.tcp.port: 19300 gateway.recover_after_time: 8m # 以下配置可以减少当es节点短时间宕机或重启时shards重新分布带来的磁盘io读写浪费 discovery.zen.fd.ping_timeout: 300s discovery.zen.fd.ping_retries: 8 discovery.zen.fd.ping_interval: 30s discovery.zen.ping_timeout: 180s # 启用安全认证 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12 # 设置密码 # 启用安全认证,只添加这个选项 xpack.security.enabled: true #xpack.security.transport.ssl.enabled: true #xpack.security.transport.ssl.verification_mode: certificate #xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 #xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12 elastic密码: espass 在集群上配置TLS: 如果你在操作单节点ES则可以跳过本内容。 1.生成CA证书 : bin/elasticsearch-certutil ca 将产生新文件 elastic-stack-ca.p12。该 elasticsearch-certutil 命令还会提示你输入密码以保护文件和密钥,请保留该文件的副本并记住其密码,此处我们设置为空 2.为集群中的每个节点生成证书和私钥 bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 将产生新文件 elastic-certificates.p12。系统还会提示你输入密码,你可以输入证书和密钥的密码,也可以按Enter键将密码留空。默认情况下 elasticsearch-certutil 生成没有主机名信息的证书,这意味着你可以将证书用于集群中的每个节点,另外要关闭主机名验证。 将 elastic-certificates.p12 文件复制到每个节点上Elasticsearch配置目录中 无需将 elastic-stack-ca.p12 文件复制到此目录。 mkdir config/certs mv elastic-certificates.p12 config/certs/ 配置集群中的每个节点以使用其签名证书标识自身并在传输层上启用TLS 启用TLS并指定访问节点证书所需的信息,将以下信息添加到每个节点的 elasticsearch.yml 文件中: xpack.security.enabled: true 3.设置密码 # 报错 [elastic@szyyelk01t elasticsearch-7.4.2]$ bin/elasticsearch-setup-passwords interactive Failed to determine the health of the cluster running at http://10.10.18.90:19200 Unexpected response code [503] from calling GET http://10.10.18.90:19200/_cluster/health?pretty Cause: master_not_discovered_exception It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords. It is very likely that the password changes will fail when run against an unhealthy cluster. Do you want to continue with the password setup process [y/N]y Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Unexpected response code [503] from calling PUT http://10.10.18.90:19200/_security/user/apm_system/_password?pretty Cause: Cluster state has not been recovered yet, cannot write to the [null] index Possible next steps: * Try running this tool again. * Try running with the --verbose parameter for additional messages. * Check the elasticsearch logs for additional error details. * Use the change password API manually. ERROR: Failed to set password for user [apm_system]. [elastic@szyyelk01t elasticsearch-7.4.2]$ bin/elasticsearch-setup-passwords interactive Connection failure to: http://10.10.18.90:19200/_security/_authenticate?pretty failed: Connection refused ERROR: Failed to connect to elasticsearch at http://10.10.18.90:19200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running? [elastic@szyyelk01t elasticsearch-7.4.2]$ bin/elasticsearch-setup-passwords interactive Failed to determine the health of the cluster running at http://10.10.18.90:19200 Unexpected response code [503] from calling GET http://10.10.18.90:19200/_cluster/health?pretty Cause: master_not_discovered_exception It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords. It is very likely that the password changes will fail when run against an unhealthy cluster. Do you want to continue with the password setup process [y/N]^C[elastic@szyyelk01t elasticsearch-7.4.2]$ bin/elasticsearch-setup-passwords interactive Failed to determine the health of the cluster running at http://10.10.18.90:19200 Unexpected response code [503] from calling GET http://10.10.18.90:19200/_cluster/health?pretty Cause: master_not_discovered_exception It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords. It is very likely that the password changes will fail when run against an unhealthy cluster. Do you want to continue with the password setup process [y/N] 解决办法:只配置一个主节点:cluster.initial_master_nodes: ["10.10.18.90"] # 错误2处理 [2019-11-07T16:12:31,563][INFO ][o.e.c.c.JoinHelper ] [cms_node02] failed to join {cms_node01}{765pAegcS8S0Y3OrE9taMA}{Up16Gw9pQlyXg3n1wCHE8g}{10.10.18.90}{10.10.18.90:19300}{dilm}{ml.machine_memory=8362151936, ml.max_open_jobs=20, xpack.installed=true} with JoinRequest{sourceNode={cms_node02}{765pAegcS8S0Y3OrE9taMA}{ki1VVW27TnakEEFagCoDlg}{10.10.18.117}{10.10.18.117:19300}{dil}{ml.machine_memory=16853446656, xpack.installed=true, ml.max_open_jobs=20}, optionalJoin=Optional[Join{term=1, lastAcceptedTerm=0, lastAcceptedVersion=0, sourceNode={cms_node02}{765pAegcS8S0Y3OrE9taMA}{ki1VVW27TnakEEFagCoDlg}{10.10.18.117}{10.10.18.117:19300}{dil}{ml.machine_memory=16853446656, xpack.installed=true, ml.max_open_jobs=20}, targetNode={cms_node01}{765pAegcS8S0Y3OrE9taMA}{Up16Gw9pQlyXg3n1wCHE8g}{10.10.18.90}{10.10.18.90:19300}{dilm}{ml.machine_memory=8362151936, ml.max_open_jobs=20, xpack.installed=true}}]} org.elasticsearch.transport.RemoteTransportException: [cms_node01][10.10.18.90:19300][internal:cluster/coordination/join] Caused by: java.lang.IllegalArgumentException: can't add node {cms_node02}{765pAegcS8S0Y3OrE9taMA}{ki1VVW27TnakEEFagCoDlg}{10.10.18.117}{10.10.18.117:19300}{dil}{ml.machine_memory=16853446656, ml.max_open_jobs=20, xpack.installed=true}, found existing node {cms_node01}{765pAegcS8S0Y3OrE9taMA}{Up16Gw9pQlyXg3n1wCHE8g}{10.10.18.90}{10.10.18.90:19300}{dilm}{ml.machine_memory=8362151936, xpack.installed=true, ml.max_open_jobs=20} with the same id but is a different node instance at org.elasticsearch.cluster.node.DiscoveryNodes$Builder.add(DiscoveryNodes.java:618) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.coordination.JoinTaskExecutor.execute(JoinTaskExecutor.java:147) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.coordination.JoinHelper$1.execute(JoinHelper.java:119) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:702) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:324) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:219) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.MasterService.access$000(MasterService.java:73) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.MasterService$Batcher.run(MasterService.java:151) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:150) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:188) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:703) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:252) ~[elasticsearch-7.4.2.jar:7.4.2] at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:215) ~[elasticsearch-7.4.2.jar:7.4.2] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?] # 拷贝连着目录 都拷贝,删除 data 下面的所有文件重启即可 # 最终密码配置成功 [elastic@szyyelk01t elasticsearch-7.4.2]$ bin/elasticsearch-setup-passwords interactive Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic] # 查看集群状态 [elastic@szyyelk01t elasticsearch-7.4.2]$ curl -H "Content-Type: application/json" -u elastic:espass http://10.10.18.90:19200/_cluster/health?pretty { "cluster_name" : "cms-uat-elastic7", "status" : "green", "timed_out" : false, "number_of_nodes" : 2, "number_of_data_nodes" : 2, "active_primary_shards" : 1, "active_shards" : 2, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "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 } # 查看刚才创建所有索引的备份 # curl -H "Content-Type: application/json" -v -XPUT http://10.10.18.90:9200/_snapshot/my_backup/snapshot20191107 {"accepted":true} # 恢复全索引快照 #保证elasticsearch用户拥有快照目录的权限 chown -R elastic.elastic /opt/esback #创建仓库 curl -H "Content-Type: application/json" -XPUT -u elastic:espass http://10.10.18.90:19200/_snapshot/backup -d ' { "type":"fs", "settings":{"location":"/opt/esback"} }' #查询全索引快照备份 $ curl -XGET -u elastic:espass "http://10.10.18.90:19200/_snapshot/backup/_all" | python -m json.tool % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 700 100 700 0 0 160k 0 --:--:-- --:--:-- --:--:-- 170k { "snapshots": [ { "duration_in_millis": 2891, "end_time": "2019-11-07T01:35:03.702Z", "end_time_in_millis": 1573090503702, "failures": [], "include_global_state": true, "indices": [ "support_faq_categorys", "ticket_list", "templates_search", "site_page_search", "support", "templates_page_search", "support_new_articles", "article_version", "blocks_version", "search", "version", "article_search", "templates", "learn", "templates_version", "blocks_search", "templates_page_version" ], "shards": { "failed": 0, "successful": 71, "total": 71 }, "snapshot": "snapshot20191107", "start_time": "2019-11-07T01:35:00.811Z", "start_time_in_millis": 1573090500811, "state": "SUCCESS", "uuid": "0_4SOntVS1GH-7irHjKBMQ", "version": "6.3.2", "version_id": 6030299 } ] } #恢复全索引快照 [elastic@szyyelk01t elasticsearch-7.4.2]$ curl -XPOST -u elastic:espass 'http://10.10.18.90:19200/_snapshot/backup/snapshot20191107/_restore'?wait_for_completion=true {"snapshot":{"snapshot":"snapshot20191107","indices":["templates_page_search","article_search","blocks_version","learn","templates_page_version","templates","version","site_page_search","support_new_articles","support_faq_categorys","search","templates_search","blocks_search","ticket_list","article_version","support","templates_version"],"shards":{"total":71,"failed":0,"successful":71}}}
No Leanote account? Sign up now.