因工作的需要,要使用elasticsearch,安裝完了,啟動也成功了之后,發(fā)現(xiàn)公網(wǎng)無法訪問elasticsearch的服務,于是開始在CSDN里四處尋找問題原因。我自己是使用的阿里云服務器,系統(tǒng)是cento7。
第一種方法是直接關(guān)閉防火墻:
(非root用戶記得命令前加sudo,沒有sudo權(quán)限可以vim /etc/sudoers,在root ? ?ALL=(ALL) ? ? ? ALL下面加上:你的用戶名 ALL=(ALL:ALL) ? ALL )
# 暫時關(guān)閉防火墻,重新開機后防火墻還是會啟動
systemctl stop firewalld? ?
#看一下防火墻狀態(tài)是不是dead??
systemctl status firewalld? ?
# 當然你也可以永久關(guān)閉防火墻,開機防火墻也不會啟動
systemctl disable firewalld
第二種方法是給elasticsearch的9200端口設置訪問權(quán)限:
# 開啟防火墻
systemctl start firewalld? ?
#看一下防火墻狀態(tài)是不是active(running)
systemctl status firewalld? ?
#永久開放9200端口
firewall-cmd --permanent --zone=public --add-port=9200/tcp? ?
#重啟防火墻
firewall-cmd --reload? ?
#測試9200是否開放,yes為開放
sudo firewall-cmd --permanent --query-port=9200/tcp? ?
第三種方法是在 /etc/elasticsearch/elasticsearch.yml (默認安裝位置是這個,具體的elasticsearch.yml文件位置以你自己實際安裝情況為準)中修改Elasticsearch的X-Pack安全功能的設置:
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false (改為false)
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false (改為false)
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
# cluster.initial_master_nodes: ["iZbp1fo2y5vjf68zt51hpsZ"]
# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0
# Allow other nodes to join the cluster from anywhere
# Connections are encrypted and mutually authenticated
#transport.host: 0.0.0.0
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
-
xpack.security.enabled: false
:這個設置項禁用了Elasticsearch的X-Pack安全功能。如果設置為true
,Elasticsearch將啟用用戶認證、角色權(quán)限管理、HTTPS加密等安全特性。 -
xpack.security.enrollment.enabled: false
:這個設置項禁用了自動節(jié)點加入集群的安全驗證過程。如果設置為true
,新加入的節(jié)點在加入集群時需要提供有效的證書和密碼。 -
xpack.security.http.ssl:
:這部分配置是關(guān)于HTTP API客戶端連接(如Kibana、Logstash和Agents)的SSL/TLS加密設置。-
enabled: false
:這個設置項禁用了HTTP API客戶端連接的SSL/TLS加密。 -
keystore.path: certs/http.p12
:如果啟用了SSL/TLS加密,這個設置項指定了包含HTTPS證書和私鑰的PKCS12格式的密鑰庫文件的位置。
-
-
xpack.security.transport.ssl:
:這部分配置是關(guān)于集群節(jié)點間通信的SSL/TLS加密和相互認證設置。-
enabled: false
:這個設置項禁用了集群節(jié)點間通信的SSL/TLS加密。 -
verification_mode: certificate
:如果啟用了SSL/TLS加密,這個設置項指定了節(jié)點間通信的證書驗證模式。在這個例子中,設置為certificate
表示需要進行嚴格的證書驗證。
-
請注意,這些配置可能會對Elasticsearch的安全性和性能產(chǎn)生影響。在生產(chǎn)環(huán)境中,建議啟用X-Pack安全功能并正確配置SSL/TLS加密以保護數(shù)據(jù)的安全和隱私。在調(diào)整這些設置時,請確保理解其含義并根據(jù)你的具體需求進行配置。
另外看到有人說需要更改network.host: 0.0.0.0為自己的外網(wǎng)ip,這個不需要的哈。0.0.0.0會自動適配你的服務器ip。
在前面三種方法都沒辦法解決后,我開始思考可能不是服務器自身的問題,而是阿里云的配置問題。因為服務器里 curl 私網(wǎng)ip地址:9200 是能返回響應的,但是curl 公網(wǎng)ip地址:9200是無法返回的。
私網(wǎng)IP地址可以訪問:
所以考慮可能是公網(wǎng)ip的端口號沒有開放,之前開放的都是私網(wǎng)ip的端口號。云服務器中,私網(wǎng)ip就是你 ifconfig 后服務器返回的ip地址,但是公網(wǎng)ip端口號的管理是需要到云服務器控制頁面去操作的。
于是進入阿里云的云服務器管理控制臺,嘗試去尋找答案。
第四種方法是修改云服務器的安全組配置:
https://ecs.console.aliyun.com/? ?阿里云ECS云服務器管理網(wǎng)址
1、點擊實例
2、點擊更多-網(wǎng)絡和安全組-安全組配置
3、點擊服務器實例名稱
4、點擊手動添加,添加公網(wǎng)允許的端口
5、我為了省事直接把所有的端口號都加上了(1/65535)
6、最后訪問公網(wǎng)訪問成功!文章來源:http://www.zghlxwxcb.cn/news/detail-767343.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-767343.html
到了這里,關(guān)于終于解決!ElasticSearch公網(wǎng)無法訪問的問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!