现象描述

我们在阿里云上有 12 台服务器,其中 2 台服务器是部署了 doris 服务,内网IP(172.21.212.227,172.21.212.225),还有一台后台服务器内网IP(172.18.20.233),目前发现后台服务器和那两台 doris 服务器互相 ping 不通,其余的服务器都能和 doris 互相 ping 通。这说明肯定是后台服务器的设置问题。

问题排查

IP 可以看到两台 doris 服务和后台服务器的网段不一样,一个是 21,一个是 18

先使用 route -n 看一下路由表

1
2
3
4
5
6
7
8
9
10
11
[root@iZbp15ykl21vqt34uyqcolZ ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.18.31.253 0.0.0.0 UG 0 0 0 eth0
10.174.215.0 0.0.0.0 255.255.255.0 U 0 0 0 zt4gtrv3qc
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.16.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-369b6c9500eb
172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-82b231ecd0f4
172.21.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-c4032e08166c

发现 172.21 网段并不是走的 eth0 网卡,而是走的 br-c4032e08166c 网卡,这就是为什么 ping 不通的问题所在。

我们手动来添加两条路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@iZbp15ykl21vqt34uyqcolZ ~]# route add -host 172.21.212.227  gw 172.18.31.253 dev eth0
[root@iZbp15ykl21vqt34uyqcolZ ~]# route add -host 172.21.212.225 gw 172.18.31.253 dev eth0
[root@iZbp15ykl21vqt34uyqcolZ ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.18.31.253 0.0.0.0 UG 0 0 0 eth0
10.174.215.0 0.0.0.0 255.255.255.0 U 0 0 0 zt4gtrv3qc
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.16.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-369b6c9500eb
172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-82b231ecd0f4
172.21.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-c4032e08166c
172.21.212.225 172.18.31.253 255.255.255.255 UGH 0 0 0 eth0
172.21.212.227 172.18.31.253 255.255.255.255 UGH 0 0 0 eth0

这个时候在去 ping 两台 doris 服务,发现就没问题了。

服务器重启后 route 丢失

刚才执行的 route add 当服务器重启后就需要重新执行了,有多种方法可以将该命令持久化保存,我选择了使用 crontab 来监听服务器重启的事件,先使用 crontab -e 打开定时任务配置文件,然后添加如下内容:

1
2
@reboot route add -host 172.21.212.227 gw 172.18.31.253 dev eth0
@reboot route add -host 172.21.212.225 gw 172.18.31.253 dev eth0

以上在服务器重启后就会自动把这两条路由加上