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 来加密节点间的通信,以保护数据的安全。

相关推荐
JAVA学习通2 小时前
SpringOJ竞赛项目----组件ElasticSearch
大数据·elasticsearch·搜索引擎
xxxxxxllllllshi2 小时前
Java中Elasticsearch完全指南:从零基础到实战应用
java·开发语言·elasticsearch·面试·职场和发展·jenkins
失散1313 小时前
分布式专题——47 ElasticSearch搜索相关性详解
java·分布式·elasticsearch·架构
铭毅天下16 小时前
Elasticsearch 到 Easysearch 数据迁移 5 种方案选型实战总结
大数据·elasticsearch·搜索引擎·全文检索
Elastic 中国社区官方博客20 小时前
Elasticsearch 推理 API 增加了开放的可定制服务
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
yumgpkpm1 天前
华为鲲鹏 Aarch64 环境下多 Oracle 数据库汇聚操作指南 CMP(类 Cloudera CDP 7.3)
大数据·hive·hadoop·elasticsearch·zookeeper·big data·cloudera
Elastic 中国社区官方博客1 天前
AI Agent 评估:Elastic 如何测试代理框架
大数据·人工智能·elasticsearch·搜索引擎
Elasticsearch1 天前
在 Elasticsearch 中解析 JSON 字段
elasticsearch
望获linux1 天前
【实时Linux实战系列】使用 u-trace 或 a-trace 进行用户态应用剖析
java·linux·前端·网络·数据库·elasticsearch·操作系统
dessler1 天前
Elasticsearch(ES)-Logstash
linux·运维·elasticsearch