elasticsearch由单节点部署成3节点的集群

环境:
OS:Centos 7
ES:6.8.5
目前拓扑:单节点的ES(带密码验证)
当前节点ip:
192.168.1.105

新增节点ip:
192.168.1.106
192.168.1.107

 

########################当前节点的配置情况##########################

1.配置参数文件
[elasticsearch@hadoop-slave1 config]$ more elasticsearch.yml

复制代码
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.63
http.port: 19200
path.repo: /home/elasticsearch/esbak

##安全认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

##第三方中间件配置参数,看情况需要
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
复制代码

 

2.数据情况

[elasticsearch@localhost config]$ curl -u elastic:elastic -X GET 'http://192.168.1.105:19200/_cat/indices?v'         health status index           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   app_message_all E3S-HXeZTX6BuTbRlw31Pw   5   1     300000            0    222.4mb        222.4mb
yellow open   db_customer     n3-RkwCxTK6-qjORZIs0Dg   5   1          1            0      4.5kb          4.5kb
green  open   .security-6     Y_fF1tkBRKa2mAo2H78ozg   1   0          6            0     19.5kb         19.5kb

 

################当前节点上的操作#################################

在192.168.1.105上操作
1.生成ca证书(tsl方式)
参考如下连接操作
https://www.cnblogs.com/hxlasky/p/14784423.html

 

2.修改当前节点的配置
vi /usr/local/services/elasticsearch/config/elasticsearch.yml

复制代码
##集群名称和节点名称
cluster.name: my-cluster
node.name: node-1

##安全认证部分
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

##集群部分
discovery.zen.ping.unicast.hosts: ["192.168.1.105", "192.168.1.106","192.168.1.107"]
discovery.zen.minimum_master_nodes: 2
复制代码

 

注意:
这个时候先不重启该节点,等另外2个节点都配置好了启动后再重启动

 

################新增节点1(192.168.1.106)上的操作#################################

1.节点上安装es
安装路径与现有节点保持一致

 

2.这里新加入基本参数,确保es能够启动
##集群名称和节点名称(注意每个节点的node.name参数不一致,其他都是一样的)

复制代码
cluster.name: my-cluster
node.name: node-2
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.106
http.port: 19200
path.repo: /home/elasticsearch/esbak
复制代码

 

3.确保通过上面的基本配置能够启动es

复制代码
-bash-4.2$ curl http://192.168.1.106:19200/?pretty
{
  "name" : "DnTDbU_",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "fzzwm0OdRLGpLZYvBY2noA",
  "version" : {
    "number" : "6.8.5",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "78990e9",
    "build_date" : "2019-11-13T20:04:24.100411Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.2",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
复制代码

 

4.关闭es
-bash-4.2$ kill -9 2109

 

5.将上面节点生成的证书拷贝到相应的目录

192.168.1.105 上操作
[root@localhost config]# cd /usr/local/services/elasticsearch/config
scp elastic-stack-ca.p12 root@192.168.1.106:/usr/local/services/elasticsearch/config/
scp elastic-certificates.p12 root@192.168.1.106:/usr/local/services/elasticsearch/config/

 

另外一台机器

scp elastic-stack-ca.p12 root@192.168.1.107:/usr/local/services/elasticsearch/config/
scp elastic-certificates.p12 root@192.168.1.107:/usr/local/services/elasticsearch/config/


拷贝过去后注意要修改权限
[root@localhost home]# cd /usr/local/services
[root@localhost services]# chown -R elasticsearch:elasticsearch ./elasticsearch

 

6.修改配置文件,加入如下项:
su - elasticsearch
vi /usr/local/services/elasticsearch/config/elasticsearch.yml

复制代码
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
discovery.zen.ping.unicast.hosts: ["192.168.1.105", "192.168.1.106","192.168.1.107"]
discovery.zen.minimum_master_nodes: 2
复制代码

 

################新增节点1(192.168.1.107)上的操作#################################
该节点上的操作与上面的节点操作一致

 

################启动集群#################################

1.停掉原有节点的ES
[root@localhost config]# kill -9 1979

 

2.启动三个节点
每个节点都执行如下操作
[root@localhost config]# su - elasticsearch
[elasticsearch@localhost bin]$ cd /usr/local/services/elasticsearch/bin
[elasticsearch@localhost bin]$ ./elasticsearch -d

 

3.集群验证

复制代码
[elasticsearch@localhost bin]$ curl -u elastic:elastic 'http://192.168.1.105:19200/_cat/nodes?pretty'
192.168.1.106 3 95 68 1.87 0.63 0.26 mdi - node-2
192.168.1.107 3 93 84 1.66 0.53 0.26 mdi - node-3
192.168.1.105 3 97 39 1.16 0.47 0.21 mdi * node-1

[elasticsearch@localhost bin]$ curl -u elastic:elastic 'http://192.168.1.105:19200/_cat/health?v'
epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1691482056 08:07:36  my-cluster green           3         3     32  16    0    0        0             0                  -                100.0%
复制代码

 

4.验证数据情况

复制代码
节点1:
[elasticsearch@localhost bin]$ curl -u elastic:elastic -X GET 'http://192.168.1.105:19200/_cat/indices?v'
health status index           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .security-6     U8MPlehwRFWYSQY2cgh8mw   1   1          6            0     39.1kb         19.5kb
green  open   db_customer     n3-RkwCxTK6-qjORZIs0Dg   5   1          1            0        9kb          4.5kb
green  open   app_message_all E3S-HXeZTX6BuTbRlw31Pw   5   1     300000            0    444.9mb        222.4mb
green  open   db_customer01   MZ54EHsBQY-teVmJTKf1kA   5   1          1            0        9kb          4.5kb


节点2:
[elasticsearch@localhost bin]$ curl -u elastic:elastic -X GET 'http://192.168.1.106:19200/_cat/indices?v'
health status index           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .security-6     U8MPlehwRFWYSQY2cgh8mw   1   1          6            0     39.1kb         19.5kb
green  open   db_customer     n3-RkwCxTK6-qjORZIs0Dg   5   1          1            0        9kb          4.5kb
green  open   app_message_all E3S-HXeZTX6BuTbRlw31Pw   5   1     300000            0    444.9mb        222.4mb
green  open   db_customer01   MZ54EHsBQY-teVmJTKf1kA   5   1          1            0        9kb          4.5kb

节点3:
[elasticsearch@localhost bin]$ curl -u elastic:elastic -X GET 'http://192.168.1.107:19200/_cat/indices?v'
health status index           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .security-6     U8MPlehwRFWYSQY2cgh8mw   1   1          6            0     39.1kb         19.5kb
green  open   db_customer     n3-RkwCxTK6-qjORZIs0Dg   5   1          1            0        9kb          4.5kb
green  open   app_message_all E3S-HXeZTX6BuTbRlw31Pw   5   1     300000            0    444.9mb        222.4mb
green  open   db_customer01   MZ54EHsBQY-teVmJTKf1kA   5   1          1            0        9kb          4.5kb
复制代码

 

可以看到之前单节点的数据都自动同步到其他另外的2个节点了.

 

说明:
集群模式的备份目录必须是每个节点都能访问的公共目录,实现的方式有:
1.通过将一个节点的的备份目录通过nfs挂载到另外的2台机器;
2.若是采用云服务的话,可以购买一个nas服务,分别挂载到每个节点;

 

posted @   slnngk  阅读(243)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-08-08 postgresql大表加字段
点击右上角即可分享
微信分享提示