024 elasticsearch集群

文章目录

bash 复制代码
cp elasticsearch-7.10.2 escloud -R
bash 复制代码
cd escloud/
bash 复制代码
rm -rf data
bash 复制代码
cd logs/
bash 复制代码
rm -rf *
bash 复制代码
tar zcf escloud.tar.gz escloud
bash 复制代码
tar zxf escloud.tar.gz
bash 复制代码
mv escloud a
bash 复制代码
mv escloud b
bash 复制代码
mv escloud c
bash 复制代码
cd config
bash 复制代码
vim elasticsearch.yml
bash 复制代码
curl ifconfig.me
bash 复制代码
netstat -tulnp | grep 9300
bash 复制代码
Test-NetConnection -ComputerName [服务器的IP地址或域名] -Port [端口号]
bash 复制代码
sudo yum install telnet -y
bash 复制代码
telnet <目标IP地址> <端口号>

搭建集群

http.publish_host 和 transport.publish_host 是 Elasticsearch 配置文件中的两个重要参数,它们用于指定 Elasticsearch 节点对外发布的 HTTP 和传输层(Transport)地址。

http.publish_host:这个参数用于指定 Elasticsearch 节点在 HTTP 层面上对外发布的地址。当客户端(如 Kibana、Logstash 或其他应用程序)尝试通过 HTTP 协议连接到 Elasticsearch 时,它们会使用这个地址。如果未设置,Elasticsearch 会自动选择一个合适的地址。

transport.publish_host:这个参数用于指定 Elasticsearch 节点在集群内部通信(即传输层通信)时对外发布的地址。Elasticsearch 集群中的节点通过传输层协议相互通信,以协调集群状态、分发索引数据等。如果未设置,Elasticsearch 同样会自动选择一个合适的地址。

当你有三个 Elasticsearch 节点,并且它们都不在同一个内网中时,要使它们组成一个集群,你需要确保这些节点能够通过某种方式相互通信。这通常涉及到配置节点的网络设置,以便它们能够识别并连接到彼此。

在这种情况下,http.publish_host 和 transport.publish_host 可以帮助你指定每个节点应该使用哪个地址来对外发布其服务。然而,更重要的是确保这些地址在网络上是可达的,并且没有防火墙或安全组规则阻止节点间的通信。

以下是一个简化的配置示例,假设你有三个 Elasticsearch 节点,分别位于不同的内网中,但它们都有公网 IP 地址,并且你可以通过配置 NAT 或 VPN 来使它们相互通信:

节点1(位于内网A,公网IP为1.1.1.1)

yaml 复制代码
http.cors.enabled: true
http.cors.allow-origin: "*"

cluster.name: my-cross-network-cluster  
node.name: node1  
network.host: 0.0.0.0  # 监听所有网络接口  
http.port: 9200  
transport.tcp.port: 9300  
http.publish_host: 1.1.1.1  # 对外发布的HTTP地址  
transport.publish_host: 1.1.1.1  # 对外发布的传输层地址  
discovery.seed_hosts: ["2.2.2.2:9300", "3.3.3.3:9300"]  # 其他节点的公网地址和端口  
cluster.initial_master_nodes: ["node1", "node2", "node3"]  # 初始主节点列表
节点2(位于内网B,公网IP为2.2.2.2)
yaml 复制代码
http.cors.enabled: true
http.cors.allow-origin: "*"

cluster.name: my-cross-network-cluster  
node.name: node2  
network.host: 0.0.0.0  
http.port: 9200  
transport.tcp.port: 9300  
http.publish_host: 2.2.2.2  
transport.publish_host: 2.2.2.2  
discovery.seed_hosts: ["1.1.1.1:9300", "3.3.3.3:9300"]  
cluster.initial_master_nodes: ["node1", "node2", "node3"]
节点3(位于内网C,公网IP为3.3.3.3)
yaml 复制代码
http.cors.enabled: true
http.cors.allow-origin: "*"

cluster.name: my-cross-network-cluster  
node.name: node3  
network.host: 0.0.0.0  
http.port: 9200  
transport.tcp.port: 9300  
http.publish_host: 3.3.3.3  
transport.publish_host: 3.3.3.3  
discovery.seed_hosts: ["1.1.1.1:9300", "2.2.2.2:9300"]  
cluster.initial_master_nodes: ["node1", "node2", "node3"]

在这个配置中,每个节点都使用其公网 IP 地址作为 http.publish_host 和 transport.publish_host。这样,无论客户端还是集群中的其他节点,都可以通过这些公网 IP 地址来访问和通信。

然而,请注意以下几点:

确保所有节点的公网 IP 地址都是可达的,并且没有防火墙或安全组规则阻止它们之间的通信。

如果你的网络环境使用了 NAT 或 VPN,请确保它们正确配置,以便节点间的通信能够顺利进行。

考虑到安全性和性能,你可能不希望将 Elasticsearch 节点直接暴露在公网上。在这种情况下,你可以考虑使用反向代理、负载均衡器或 VPN 来更安全地管理对 Elasticsearch 服务的访问。

在生产环境中,强烈建议使用 SSL/TLS 来加密节点间的通信,以保护数据的安全。

相关推荐
彧azz9 小时前
Git 入门实操实例:从安装到远程仓库全流程
大数据·笔记·git·学习·elasticsearch
醉颜凉10 小时前
Canal 与 Elasticsearch 实时同步:增量索引更新、删除处理与全量重建方案
elasticsearch·canal·数据同步·增量更新·全量重建
无风听海17 小时前
深入解析 Elasticsearch 的 match_phrase_prefix与 match_bool_prefix
大数据·elasticsearch·mybatis
天天喝旺仔18 小时前
Elasticsearch 全文检索实战:Lucene 倒排索引与 NoSQL 文档检索落地
elasticsearch·搜索引擎·全文检索·nosql·lucene
浅念-1 天前
一文吃透Git:本地操作|冲突处理|远程协作|GitFlow工作流详解
大数据·git·elasticsearch·搜索引擎·gitflow
vx-程序开发1 天前
【计算机毕设】基于Spring Boot的古城景区管理系统88564
java·数据库·spring boot·后端·spring·elasticsearch·课程设计
czhc11400756631 天前
2026-09-11 一日综合:树的父链、git 概念、三方死锁、静默失败
大数据·git·elasticsearch
Elastic 中国社区官方博客3 天前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
大数据·运维·数据库·elasticsearch·搜索引擎·ai·全文检索
Elasticsearch3 天前
将 Vercel 数据导入 Elastic:无需安装任何东西的无服务器可观测性
elasticsearch