es7.80 集群部署(linux版本+Windows)


一 linux 搭建集群

1.1 软件下载

软件下载地址:https://www.elastic.co./cn/downloads/past-releases/elasticsearch-7-8-0

在这里插入图片描述

1.2 软件安装

1) 解压软件

将下载的软件解压缩

# 解压缩
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt/module
# 改名
mv elasticsearch-7.8.0 es-cluster

将软件分发到其他节点:linux2, linux3

  1. 创建用户

因为安全问题,Elasticsearch 不允许 root 用户直接运行,所以要在每个节点中创建新用

户,在 root 用户中创建新用户

useradd es #新增 es 用户

passwd es #为 es 用户设置密码

userdel -r es #如果错了,可以删除再加

chown -R es:es /opt/module/es-cluster #文件夹所有者

3) 修改配置文件

修改/config/elasticsearch.yml 文件,
分发其他节点:linux2, linux3

#集群名称
cluster.name: cluster-es
#节点名称,每个节点的名称不能重复
node.name: node-1
node.master: true
node.data: true
path.data: /opt/es-cluster/data
# 配置日志目录
path.logs: /opt/es-cluster/logs
#ip 地址,每个节点的地址不能重复
network.host: 0.0.0.0
http.port: 9200
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举 master
cluster.initial_master_nodes: ["node-1"]
discovery.seed_hosts: ["192.168.146.129", "192.168.146.130", "192.168.146.131"]
discovery.zen.minimum_master_nodes: 4
gateway.recover_after_nodes: 4

修改/etc/security/limits.conf ,分发文件

# 在文件末尾中增加下面内容
es soft nofile 65536
es hard nofile 65536

修改/etc/security/limits.d/20-nproc.conf,分发文件

# 在文件末尾中增加下面内容
es soft nofile 65536
es hard nofile 65536
* hard nproc 4096
# 注:* 带表 Linux 所有用户名称

修改/etc/sysctl.conf

# 在文件中增加下面内容
vm.max_map_count=655360

重新加载

sysctl -p 

1.3 启动软件

分别在不同节点上启动 ES 软件

cd /opt/module/es-cluster

\#启动

bin/elasticsearch

\#后台启动

bin/elasticsearch -d 

1.4 测试集群

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vCUc0KS8-1669087853460)(G:\笔记\Elasticsearch全文搜索引擎\img\image-20221108135215679.png)]

启动时,会动态生成文件,如果文件所属用户不匹配,会发生错误,需要重新进行修改用户和用户组

切换到root 用户更改 然后使用es重新启动
chown -R es:es /opt/module/es #文件夹所有者

、

关闭防火墙

#暂时关闭防火墙
systemctl stop firewalld
#永久关闭防火墙
systemctl enable firewalld.service #打开放货抢永久性生效,重启后不会复原
systemctl disable firewalld.service #关闭防火墙,永久性生效,重启后不会复原

二 Windows 搭建集群

2.1 部署集群

  1. 创建 elasticsearch-cluster 文件夹,
    在内部复制三个 elasticsearch 服务
    在这里插入图片描述

2.修改集群文件目录中每个节点的 config/elasticsearch.yml 配置文件

node-1001 节点

#节点 1 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1001
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1001
#tcp 监听端口
transport.tcp.port: 9301
#discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
#discovery.zen.fd.ping_timeout: 1m
#discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

node-1002 节点

#节点 2 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1002
node.master: true
node.data: true
network.host: localhost
#http 端口
http.port: 1002
#tcp 监听端口
transport.tcp.port: 9302
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

node-1003 节点

#节点 3 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1003
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1003
#tcp 监听端口
transport.tcp.port: 9303
#候选主节点的地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

2.2启动集群

1.启动前先删除每个节点中的 data 目录中所有内容(如果存在)
在这里插入图片描述

2.分别双击执行 bin/elasticsearch.bat, 启动节点服务器,启动后,会自动加入指定名称的集群

在这里插入图片描述

3.测试集群

2.3查看集群状态

node-1001 节点

在这里插入图片描述

node-1002 节点

在这里插入图片描述

node-1003 节点

在这里插入图片描述

在这里插入图片描述

向集群中的 node-1001 节点增加索引

在这里插入图片描述

向集群中的 node-1002 节点查询索引

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值