筆者安裝的是elasticsearch7版本的,安裝環境爲centos7,配置的java爲jdk11。
一、elasticsearch外網訪問
這個問題困擾筆者許久,查閱相關資料才發現那人正在燈火闌珊處
解決方案如下:
- 相關配置文件的修改
修改安裝的elasticsearch文件下的config/elasticsearch.yml
文件。添加:
network.http: 0.0.0.0 #任意的IP地址均可以訪問本機es
&
network.http: 196.128.31.133 #僅輸入本機的IP地址訪問本機es
- centos防火牆設置
- 方案一:外網訪問es需要關閉es所在機子的防火牆。
centos7 防火牆狀態查看、關閉、打開命令:
firewall-cmd --state #防火牆狀態查看
systemctl stop firewalld.service #防火牆關閉
systemctl start firewalld.service #打開防火牆
- 方案二:開啓9200端口
# 查詢9200端口是否開放
firewall-cmd --query-port=9200/tcp
# 開放9200端口
firewall-cmd --permanent --add-port=9200/tcp
# 移除9200端口
firewall-cmd --permanent --remove-port=9200/tcp
# 重啓防火牆(修改配置後要重啓防火牆)
firewall-cmd --reload
二、ElasticSearch頻繁報503錯誤
我報503錯誤的地方有兩處:
- elasticsearch head連接不上elasticsearch;
- python的elasticsearch模塊連接elasticsearch會報503錯誤。
這些問題的源頭主要體現在config/elasticsearch.yml
文件的配置問題。
解決方案如下:
- es配置文件添加
# 開啓跨域訪問支持,默認爲false
http.cors.enabled: true
# 跨域訪問允許的域名地址
http.cors.allow-origin: "*"
# 通過爲 cluster.initial_master_nodes 參數設置符合主節點條件的節點的 IP 地址來引導啓動集羣
cluster.initial_master_nodes: ["node-1"]
備註:重點是node.name
和cluster.initial_master_nodes
- 筆者的
config/elasticsearch.yml
配置文件
筆者的認定master機子的IP地址不在下列discovery.zen.ping.unicast.hosts
配置中。
cluster.name: supermarket
node.name: node-main
http.port: 9200
node.master: true
node.data: true
path.data: /home/software/elasticsearch/data
path.logs: /home/software/elasticsearch/logs
# discovery.zen.minimum_master_nodes: 2
# discovery.zen.ping_timeout: 3000s
# discovery.zen.ping.unicast.hosts: ["192.168.31.137","192.168.31.138"]
cluster.initial_master_nodes: ["node-main"]
transport.tcp.port: 9300
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.memory_lock: false
bootstrap.system_call_filter: false