Linux Ping localhost Failed

在Centos上部署Kafka,启动Kafka服务的时候,经常出现如下的warnings (This problem hasn’t be solved!)

1
2
3
4
[2019-11-27 18:31:00,242] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2019-11-27 18:31:01,347] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2019-11-27 18:31:02,451] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2019-11-27 18:31:03,555] WARN [Controller id=0, targetBrokerId=0] Connection to node 0 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

而且无法通过localshot:9092连接这个broker,那到底是什么原因导致这样的问题呢?通过google如上的问题,得到如下的解决方法:

如上提到的方法都无法解决那个warning问题。

通过在多台服务器上部署对比发现,该机器上无法ping通localhost,下一步就是要解决如何ping通localhsot了。

首先看一下机器的hosts的配置,执行cat /etc/hosts

1
2
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

关于hosts文件详解可以参考这篇文章《linux环境下/etc/hosts文件详解》,可以发现hosts的配置没有问题,那到底是什么原因导致localhost ping不通呢?进一步分析问题。

然后就在Google上搜索关于ping localhost failed的问题,就找到如下的一些参考文章:

上面文章提到的,通过查看lo0接口是否配置成功以及是否启动,设置/proc/sys/net/ipv4/icmp_echo_ignore_all为0等方式,都无法解决ping不通的问题。

最后,通过对比能够pinglocalhost机器的iptables,发现了问题,ping不通localhost机器的iptables没有配置如下的内容:

1
-A INPUT -p icmp -j ACCEPT

添加上面到iptables,并且重启防火墙,就解决了ping不通的问题了。

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×