背景: 目前ES集群的版本还是6.4,最新的ES版本已经到了7.8了,是时候更新迭代了,先把测试环境下的更新了。
通过官方文档了解到有2种升级方案https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html 1.滚动升级 首先升级到6.8再升级到7.8,这个好处是不用中断业务,一台一台升级 2.全新集群升级 这个在升级的过程中是会要关闭集群的,对业务有一定的影响
考虑到公司存储的只是普通的业务数据,定期7天删除,少量数据丢失也没啥影响。也可以暂时关闭相关业务程序,业务数据先堆积在rmq中,正常后再重启,这样数据就不会丢失了。 官方文档在此:https://www.elastic.co/guide/en/elasticsearch/reference/current/restart-upgrade.html
操作步骤如下: 1.在其中一个节点上执行以下内容 #禁用分片分配 curl -H “Content-Type: application/json” -XPUT ‘http://localhost:9200/_cluster/settings’ -d ‘{“persistent”:{“cluster.routing.allocation.enable”:“primaries”}}’ #索引编制并执行同步刷新 curl -XPOST ‘http://localhost:9200/_flush/synced’
2.在各个节点上执行 rpm -e elasticsearch (之前是用rpm包安装的。) 下载7.8版本的rpm包 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-x86_64.rpm 下载成功后再安装 rpm -ivh elasticsearch-7.8.0-x86_64.rpm 修改elasticsearch.yml配置文件 由于7.8版本的配置文件与6.4的还是有区别,不能直接沿用之前的,所以根据自己的实现情况进行修改,path.data还是之前的存储路径不变。如果有敏感数据的,事先备份一下,免得要删库跑路了。 配置内容如下: 节点1: cluster.name: elasticSearch_cluster node.name: node1 node.master: true node.data: true path.data: /data path.logs: /var/log/elasticsearch network.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: [“10.34.43.55”,“10.34.43.56”] discovery.zen.minimum_master_nodes: 2 cluster.initial_master_nodes: [“node1”] http.cors.enabled: true http.cors.allow-origin: “" indices.fielddata.cache.size: 4G 节点2: cluster.name: elasticSearch_cluster node.name: node2 node.master: false node.data: true path.data: /data path.logs: /var/log/elasticsearch network.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: [“10.34.43.55”,“10.34.43.56”] discovery.zen.minimum_master_nodes: 2 cluster.initial_master_nodes: [“node1”] http.cors.enabled: true http.cors.allow-origin: "” indices.fielddata.cache.size: 4G
这里需要重点介绍三个配置字段 discovery.seed_hosts: 填上各个节点的信息 discovery.zen.minimum_master_nodes:主要是为了防止裂变,算法为总集群数/2+1.如果有10节点,此外填6 cluster.initial_master_nodes:填上master的节点信息
修改jvm.options配置文件 原先默认的是 -Xms1g -Xmx1g 我的内存是8G的 故改成 -Xms4g -Xmx4g
3.重启服务 在节点上执行 service elasticsearch start 查看状态 curl ‘http://localhost:9200/_cat/health’ 没有报错则重启另外一台 再次查看状态正常后最后则启用分片分配 curl -H “Content-Type: application/json” -XPUT ‘http://localhost:9200/_cluster/settings’ -d ‘{“persistent”:{“cluster.routing.allocation.enable”:null}}’
最后浏览一下数据看看是否正常,还有最重要的一步是相关项目涉及到操作ES的,都要看看是否正常,因为新版本返回的json结构有些与原先的不太一样。