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

相关推荐
Elastic 中国社区官方博客2 小时前
使用真实 Elasticsearch 进行高级集成测试
大数据·数据库·elasticsearch·搜索引擎·全文检索·jenkins·集成测试
画船听雨眠aa9 小时前
gitlab云服务器配置
服务器·git·elasticsearch·gitlab
risc12345614 小时前
【Elasticsearch 】悬挂索引(Dangling Indices)
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客15 小时前
使用 Ollama 和 Kibana 在本地为 RAG 测试 DeepSeek R1
大数据·数据库·人工智能·elasticsearch·ai·云原生·全文检索
zfj32115 小时前
学技术学英语:elasticsearch硬件相关的配置&优化技巧
网络·elasticsearch·全文检索·内存·cpu·磁盘
字节全栈_vBr1 天前
面试之Solr&Elasticsearch
elasticsearch·面试·solr
risc1234561 天前
【Elasticsearch】中数据流需要配置索引模板吗?
大数据·elasticsearch·jenkins
JackieZhengChina1 天前
新一代搜索引擎,是 ES 的15倍?
大数据·elasticsearch·搜索引擎
是小崔啊1 天前
Spring Boot - 数据库集成06 - 集成ElasticSearch
数据库·spring boot·elasticsearch
Elastic 中国社区官方博客1 天前
Elastic Cloud Serverless 获得主要合规认证
大数据·数据库·elasticsearch·搜索引擎·云原生·serverless·全文检索