多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## elastic search集群故障切换测试 ### 测试环境说明 - windows server2016 64位 - java version 1.8 - elasticserach 版本:6.6.2 (添加中文分词插件ik) ### 测试方法说明 - 安装es,解压后运行bin目录中的脚本直接启动。 - 安装head插件连接es节点,监控集群状态和添加以及查询数据。 - 同时启动三个es节点,设置不同的端口区分。启用集群,不做特殊的主从节点区分,使三个节点同时具有主节点、从节点、协调节点的功能。 - 在集群中任意连接一个节点,建立索引,新建数据。 - 依次停止节点1,节点2,接着在剩余的节点中查询数据,根据是否返回所有的数据来判断数据是否正常的转移到了从节点。 - 从head工具上检查主节点是否进行了重新选举。 #### 节点状态意义说明 状态 | 意义 ---|--- green| 所有主分片和从分片都可用 yellow| 所有主分片可用,但存在不可用的从分片 red| 存在不可用的主要分片 #### 测试过程和结果 1. 初始查询集群健康状态为green,节点为3个,分别连接3个节点,分别写入数据。 2. 关闭节点1,从head上看到节点2被选为主节点master,连接到节点2和节点3,查询数据正常,返回了所有数据。 3. 再次关闭节点2,节点3被选为master,查询数据正常。 4. 同时集群健康状态为yellow。 5. 然后单独在节点3中加入数据,再分别启动节点1,节点2,集群健康状态恢复为green,节点1和节点2变成了从节点。 6. 接着分别在节点1和2中查询节点3中增加的数据,数据正常返回。查询所有的数据也正常的返回了。 7. 说明数据转移正常,故障转移能力正常。 #### 使用的操作 查看集群健康状况: ``` GET /_cluster/health { "cluster_name": "my-test", "status": "green", "timed_out": false, "number_of_nodes": 3, "number_of_data_nodes": 3, "active_primary_shards": 5, "active_shards": 10, "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 } ``` 添加数据: ``` PUT /megacorp/employee/1 { "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] } PUT /megacorp/employee/2 { "first_name" : "Jane", "last_name" : "Smith", "age" : 32, "about" : "I like to collect rock albums", "interests": [ "music" ] } PUT /megacorp/employee/3 { "first_name" : "Douglas", "last_name" : "Fir", "age" : 35, "about": "I like to build cabinets", "interests": [ "forestry" ] } ``` 查询数据: ``` 查询单个 GET /megacorp/employee/1 查询全部 GET /megacorp/employee/_search ``` #### 配置 节点1: ``` cluster.name: my-test node.name: node-1 network.host: 0.0.0.0 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" transport.tcp.port: 9400 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9400", "127.0.0.1:9401", "127.0.0.1:9402"] ``` 节点2: ``` cluster.name: my-test node.name: node-2 network.host: 0.0.0.0 http.port: 9201 http.cors.enabled: true http.cors.allow-origin: "*" transport.tcp.port: 9401 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9400", "127.0.0.1:9401", "127.0.0.1:9402"] ``` 节点3: ``` cluster.name: my-test node.name: node-3 network.host: 0.0.0.0 http.port: 9202 http.cors.enabled: true http.cors.allow-origin: "*" transport.tcp.port: 9402 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9400", "127.0.0.1:9401", "127.0.0.1:9402"] ```