ES运维(四)扩容方式迁移
1 迁移概述
本次模拟es在线迁移方式:集群扩容-->数据迁移-->老节点下线-->服务重启刷新配置。 中间master替换的时候会有短暂的不可用。 另外业务测需注意:老节点下线前,要进行配置修改,讲业务中使用到的IP端口替换为新节点的IP端口
1.2 当前信息说明
[es@cdh01 elasticsearch-7.8.1]$ curl cdh01:9200/_cat/nodes 172.16.105.194 42 99 1 0.00 0.09 0.13 dilmrt * node-1 172.16.105.93 12 71 30 0.54 0.18 0.10 dilmrt - node-3 172.16.105.18 30 68 1 0.09 0.09 0.07 dilmrt - node-2 [es@cdh01 elasticsearch-7.8.1]$ curl cdh01:9200/_cluster/health?pretty { "cluster_name" : "my-application", "status" : "green", "timed_out" : false, "number_of_nodes" : 3, "number_of_data_nodes" : 3, "active_primary_shards" : 0, "active_shards" : 0, "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 }
2 ES集群扩容
2.1 基础安装包(所有新扩容节点)
yum install -y epel-release yum install -y yum-axelget yum groupinstall -y "Development Tools"
2.2 java环境
es自带jdk,不用额外配置
2.3 普通用户设置(所有新扩容节点)
elasticsearch需要普通用户启动,修改数据目录,日志目录,包目录为普通用户权限。 useradd es
2.4 上传安装包
把老集群的安装包压缩传到新机器所有节点 压缩: tar -czvf elasticsearch-7.8.1.gz elasticsearch-7.8.1 解压: tar -zxvf elasticsearch-7.8.1.gz 修改属组&权限: [root@cdh01 app]# chown es:es elasticsearch-7.8.1 -R [root@cdh01 app]# chmod 755 elasticsearch-7.8.1 -R
2.5 修改limits参数
#root用户修改 vim /etc/security/limits.conf # 在最后面追加下面内容 es hard nofile 65536 es soft nofile 65536
2.6 修改limit配置(这里服务器默认的,不用修改)
#root用户修改 进入limits.d下的配置文件:vim /etc/security/limits.d/20-nproc.conf ,修改配置如下: * soft nproc 4096 root soft nproc unlimited
2.7 修改sysctl参数
#root用户修改 修改sysctl文件:vim /etc/sysctl.conf ,增加下面配置项 增加改行配置:vm.max_map_count=655360 保存退出后,执行: sysctl -p
2.7 修改配置文件
node.name: node-X path.data: /data/es/data path.logs: /data/es/logs network.host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["172.16.105.194", "172.16.105.18", "172.16.105.93","172.16.105.229","172.16.105.101","172.16.105.43"] cluster.initial_master_nodes: ["node-1","node-4"] http.host: 0.0.0.0 http.cors.enabled: true http.cors.allow-origin: "*" node.master: true node.data: true
2.8 启动es加入集群
[es@ipa01 bin]$ ./elasticsearch -d
扩容后shard会自动均衡
3 在线迁移
3.1 迁移shard
## 去掉迁移的节点:指定ip不会存放shard PUT /_cluster/settings { "transient" : { "cluster.routing.allocation.exclude._ip" : "172.16.105.194,172.16.105.18,172.16.105.93" } }
3.2 更改ES客户端配置
data.elasticsearch.cluster-nodes 这里记得要改成新机房集群的地址和端口
3.3 下线老集群节点
先停掉老机房非Master节点,后停Master节点
索引分布正常
数据量正常
3.4 刷新新集群配置
都改成新机房节点的 discovery.seed_hosts: ["172.16.105.229","172.16.105.101","172.16.105.43"] cluster.initial_master_nodes: ["node-4"] 逐个重启data节点,副master节点,最后重启master节点
3.5 去除shard分配限制
PUT /_cluster/settings { "transient" : { "cluster.routing.allocation.exclude._ip" : "" } } 查看: GET _cluster/settings
附
测试索引数据生成
##创建索引 PUT /test01 { "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "properties": { "age": { "type": "integer" }, "name": { "type": "keyword" } } } } ##插入数据 POST /test01/_doc { "age": "7", "name": "九月" } ## 获取索引上的字段信息 GET /_cat/indices/test01?v ##获取索引数据 GET /test01/_search { "query": { "match_all": {} } }