【elasticsearch】数据节点扩容

1.app应用程序包准备 

[esadmin@oracle1 esapp]$ mkdir -p esapp9205 /esdb/eslog/eslog9205
[esadmin@oracle1 esapp]$ mkdir -p /esdb/esdata/esdata9205

[esadmin@oracle1 esapp]$ scp -r esapp9201/* esapp9205/    */
[esadmin@oracle1 esapp]$ ll
total 0
drwxrwxr-x  9 esadmin esadmin 180 Jun 27 10:55 esapp9201
drwxrwxr-x  9 esadmin esadmin 180 Jun 27 10:55 esapp9202
drwxrwxr-x  9 esadmin esadmin 180 Jun 27 10:55 esapp9203
drwxrwxr-x  9 esadmin esadmin 180 Jun 27 15:05 esapp9204
drwxrwxr-x 14 esadmin esadmin 265 Jun 27 15:15 esapp9205

2.修改ES启动配置文件

--协调节点配置文件
cd /esdb/esapp/esapp9205/config
vi elasticsearch.yml  

3.jvm配置 

vi jvm.options 


[esadmin@oracle1 esapp9204]$ pwd
/esdb/esapp/esapp9205
[esadmin@oracle1 esapp9204]$ cat elasticsearch-env 

4.停止数据分片

curl -XPUT http://192.168.1.7:9204/_cluster/settings -H 'Content-Type:application/json' -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "none"
}
}'

5.启动ES5;

 /esdb/esapp/esapp9205/bin/elasticsearch 
[2024-06-27T15:19:24,954][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [esdb-node-5] Active license is now [BASIC]; Security is disabled
[2024-06-27T15:19:25,167][INFO ][o.e.h.AbstractHttpServerTransport] [esdb-node-5] publish_address {192.168.1.7:9205}, bound_addresses {192.168.1.7:9205}
[2024-06-27T15:19:25,168][INFO ][o.e.n.Node               ] [esdb-node-5] started

--检查节点信息
[esadmin@oracle1 ~]$ curl '192.168.1.7:9205/_cat/nodes?v'
ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.1.7           65          98  18    2.23    1.59     1.27 dilmt     -      esdb-node-3
192.168.1.7           53          98  18    2.23    1.59     1.27 il        -      esdb-node-4
192.168.1.7           47          98  18    2.23    1.59     1.27 dilmt     -      esdb-node-1
192.168.1.7           37          98  94    2.23    1.59     1.27 dilt      -      esdb-node-5
192.168.1.7           33          98  18    2.23    1.59     1.27 dilmt     *      esdb-node-2
esdb-node-5 是数据节点:dilt:是数据节点。

6.检查集群状态

[esadmin@oracle1 ~]$ curl http://192.168.1.7:9203/_cat/health?pretty -H 'Content-Type: application/json'
1719472181 07:09:41 escluster1 green 4 3 41 19 0 0 0 0 - 100.0%

7.批量写入数据 

vi document.json 



--内存不足,扩容内存:
重新启动集群后,数据自动平衡到:5号节点了。

--批量插入json文档中的数据。
curl -XPOST 192.168.1.7:9201/_bulk?pretty -H 'Content-Type: application/json' --data-binary @document.json 

--查询所有数据 :match_all
curl -XGET '192.168.1.7:9201/myindex1/_search?pretty' -H 'Content-Type: application/json' 

--新的数据节点已经自动平衡了。
[esadmin@oracle1 ~]$ curl http://192.168.1.7:9201/_cat/shards?v |grep esdb-node-5
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3671  100  3671    0     0  77211      0 --:--:-- --:--:-- --:--:-- 78106
xsq1       4     p      STARTED    2  11kb 192.168.1.7 esdb-node-5
xsq1       3     r      STARTED    0  208b 192.168.1.7 esdb-node-5
xsq1       2     r      STARTED    0  208b 192.168.1.7 esdb-node-5
xsq3       4     p      STARTED    1 6.3kb 192.168.1.7 esdb-node-5
xsq3       3     r      STARTED    2 6.6kb 192.168.1.7 esdb-node-5
xsq3       0     p      STARTED    4 7.1kb 192.168.1.7 esdb-node-5
xsq-你好 4     p      STARTED    0  208b 192.168.1.7 esdb-node-5
xsq-你好 2     p      STARTED    0  208b 192.168.1.7 esdb-node-5
xsq-index  4     r      STARTED    1 5.6kb 192.168.1.7 esdb-node-5
xsq-index  3     p      STARTED    0  208b 192.168.1.7 esdb-node-5
xs1        0     p      STARTED    1 5.6kb 192.168.1.7 esdb-node-5
mydb1      2     r      STARTED    1 5.6kb 192.168.1.7 esdb-node-5
mydb1      1     p      STARTED    0  208b 192.168.1.7 esdb-node-5

--查询整个索引的数据。
curl -XGET '192.168.1.7:9205/xsq3/_search?pretty' -H 'Content-Type: application/json' 
{
  "took" : 283,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 11,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "name" : "xsq003",
          "city" : "北京",
          "course" : "sqlserver",
          "teacher" : "大哥哥 1号",
          "pxdate" : "20200825"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "id" : 5,
          "name" : "xsq005",
          "city" : "杭州",
          "course" : "开源数据库",
          "teacher" : "大哥大师",
          "pxdate" : "20200827"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "id" : 9,
          "name" : "xsq009",
          "city" : "上海",
          "course" : "db2",
          "teacher" : "大哥达达",
          "pxdate" : "20180229"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : 1.0,
        "_source" : {
          "id" : 11,
          "name" : "xsq011",
          "city" : "上海",
          "course" : "国产数据库",
          "teacher" : "大哥哥 2 号",
          "pxdate" : "20200402"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "id" : 4,
          "name" : "xsq004",
          "city" : "上海",
          "course" : "postgrestsql",
          "teacher" : "大哥哥 3 号",
          "pxdate" : "20200828"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "7",
        "_score" : 1.0,
        "_source" : {
          "id" : 7,
          "name" : "xsq007",
          "city" : "武汉",
          "course" : "redis",
          "teacher" : "大哥车车",
          "pxdate" : "20200210"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "8",
        "_score" : 1.0,
        "_source" : {
          "id" : 8,
          "name" : "xsq008",
          "city" : "北京",
          "course" : "mongodb",
          "teacher" : "大哥师傅",
          "pxdate" : "20190529"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 1.0,
        "_source" : {
          "id" : 10,
          "name" : "xsq010",
          "city" : "广州",
          "course" : "国产数据库",
          "teacher" : "大哥哥 1 号",
          "pxdate" : "20200302"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "id" : 2,
          "name" : "xsq002",
          "city" : "深圳",
          "course" : "mysql",
          "teacher" : "大哥哥 2 号",
          "pxdate" : "20200826"
        }
      },
      {
        "_index" : "xsq3",
        "_type" : "_doc",
        "_id" : "6",
        "_score" : 1.0,
        "_source" : {
          "id" : 6,
          "name" : "xsq006",
          "city" : "成都",
          "course" : "greenplum",
          "teacher" : "大哥大侠",
          "pxdate" : "20200729"
        }
      }
    ]
  }
}

8.总结 

es默认启动后,自动开启自动数据平衡功能。我原本打算,扩容后开启自动平衡。没想到重启集群后数据自动平衡了。少了步骤数据平衡到新加的数据节点。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值