前言
安裝啟動es的過程中遇到的坑這里就不說了,基本上網上都能搜到,這里說telnet端口不通的事。
阿里雲相關
阿里雲默認很多端口都是不開放的,必須去配置安全組才能訪問,但是有時候你配置了安全組仍然訪問不了,就可以按照這篇文章的思路來試着排查一下。
問題描述
centos7上安裝了es,啟動的時候沒有報錯,查看端口有監聽,進程存在。然后在阿里雲上配置安全組,給9200端口入的權限。這個時候奇葩的事情發生了,9200端口本地怎么訪問都不通,telnet也不通。
解決問題
先是在網上搜了一下,大多數都說的是防火牆的問題,主要是iptables和firewall-cmd。
我看了一下自己的情況,firewall-cmd沒運行,iptables一個攔截規則都沒有配置,所以肯定不是防火牆的問題。
繼續在網上各種搜,沒有結果。
最后沒有辦法,提了阿里雲的工單,阿里雲的小哥先是讓發一下這三個命令的截圖:
netstat -ntulp | grep 9200
iptables -nL
firewall-cmd --list-all
可以看到小哥的思路也是,先看一下端口是否被監聽,之后排查防火牆。
我給小哥發了執行命令的截圖,然后小哥給我的回復是:
"當前您截圖的9200端口似乎監聽在本地回環端口127.0.0.1 是不行的,您看下配置修改使其監聽在0.0.0.0 后您再測試看下。"
我瞬間就恍然大悟了,我沒有配置es的network.host。修改配置文件中的network.host: 0.0.0.0
重啟es,果然可以了。
回環地址
既然上面小哥哥說了一個名詞,本地回環地址,而我又是一個還算好學的小青年,自然要搞一波這個名詞。
先說定義:
127.0.0.1,通常被稱為本地回環地址(Loopback Address),不屬於任何一個有類別地址類。
在安裝網卡前就可以ping通這個本地回環地址。
127.0.0.1 vs 0.0.0.0
127.0.0.1 is normally the IP address assigned to the "loopback" or local-only interface. This is a "fake" network adapter that can only communicate within the same host. It's often used when you want a network-capable application to only serve clients on the same host. A process that is listening on 127.0.0.1 for connections will only receive local connections on that socket.
"localhost" is normally the hostname for the 127.0.0.1 IP address. It's usually set in /etc/hosts (or the Windows equivalent named "hosts" somewhere under %WINDIR%). You can use it just like any other hostname - try "ping localhost" to see how it resolves to 127.0.0.1.
0.0.0.0 has a couple of different meanings, but in this context, when a server is told to listen on 0.0.0.0 that means "listen on every available network interface". The loopback adapter with IP address 127.0.0.1 from the perspective of the server process looks just like any other network adapter on the machine, so a server told to listen on 0.0.0.0 will accept connections on that interface too.
大致的意思是,如果監聽的是 127.0.0.1, 那么只能本地訪問;如果監聽的是0.0.0.0,那么所有的其他ip都能訪問。