注意:非 集群环境不需要设置副本,以及切片数可以设置少点 5(或者更少,测试环境数量不多,切片需要在代码中设置,副本也可以,同时副本还可以在api 处设置,单机环境副本信息可以设置成0)
连接的时候可以看能不能http://ip:9300 和 http://ip:9200 访问通,可能会存在 http 访问通,trnasport 访问不通的情况,如果不打印日志的话看不到报错信息,但是es 代码运行写不进去数据,防火墙问题:默认程序和es 放在同一台机器上的话可以访问通,不在同一台需要设置防火墙
1、查看es 信息
curl -XGET http://ip:9300
result:
{
"name" : "node-1",
"cluster_name" : "order6",
"cluster_uuid" : "8JeHWu_dRSCcbfXfvnw7iQ",
"version" : {
"number" : "6.2.1",
"build_hash" : "7299dc3",
"build_date" : "2018-02-07T19:34:26.990113Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
2、因为副本在同一个节点上不明确显示yellow 解决方案:(最终 green)
设置服本数为0
curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/_all/_settings" -d' { "number_of_replicas" : 0 } '
curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/_all/_settings" -d' { "number_of_shards" : 3 } '
3、查看集群状态
curl 'http://ip:9200/_cat/health?v'
result:
[root@host-172-16-32-209 ~]# curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
"cluster_name" : "order6",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 15,
"active_shards" : 15,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 10,
"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" : 60.0
}
4、查看各个索引状态
curl -k -u admin:admin 'http://localhost:9200/_cat/indices' | grep order-*
5、es6.2 不支持程序setting. 中 .put(“index.number_of_shards”,“5”) 设置
修改副本数量为0
解决方案:
步骤1: curl -XPOST 'http://localhost:9200/order-*/_close'
{"acknowledged":true}%
步骤2: PUT _template/default. (http://localhost:9200/_template/default)
{
"index_patterns": ["*"],
"order": -1,
"settings": {
"number_of_shards": “4”,
"number_of_replicas": “0”
}
}
步骤3:: curl -XPOST 'http://localhost:9200/order-*/_open'