linux overlay网络,Docker使用overlay网络遇到的问题

一般我们使用Overlay网络都是涉及到多台主机中的Docker容器通信问题。

Docker Overlay 一切准备就绪后,使用docker-compose 启动容器。

在一个业务服务的容器日志里面发现无法连接的Zookeeper,错误是:

java.net.NoRouteToHostException: No route to host

复制代码

在容器中尝试ping 10.0.0.3 容器,发现不通:

PING zookeeper (10.0.0.3) 56(84) bytes of data.

From 85789ac6e6a8 (10.0.0.8) icmp_seq=1 Destination Host Unreachable

From 85789ac6e6a8 (10.0.0.8) icmp_seq=2 Destination Host Unreachable

From 85789ac6e6a8 (10.0.0.8) icmp_seq=3 Destination Host Unreachable

复制代码

刚开始查询了一些资料后,以为是防火墙(CentOS7)问题,于是查看了防火墙状态:

firewall-cmd --state

复制代码

结果防火墙压根没开:

not running

复制代码

由于之前没有详细查看docker overlay网络的使用限制,一直以为只要docker的版本保持在1.9.1+就可以了。后来又查了下,发现还有一个限制:内核版本大于等于3.16。于是赶紧查看了下内核版本:

# uname -r

3.10.0-514.10.2.el7.x86_64

复制代码

果然内核版本低了,于是开始升级内核。

导入elrepo的key,然后安装elrepo的yum源:

sudo rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

复制代码

列出可用的内核相关包:

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

复制代码

lt为长期维护版本,mt为稳定版本,可以看到最新的稳定版本为:

5.2.10-1.el7.elrepo

复制代码

开始升级内核(以后可以直接执行这句):

sudo yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64

复制代码

升级完后需要重启一下:

reboot

复制代码

再次查看内核:

uname -r

3.10.0-514.10.2.el7.x86_64

复制代码

WTF,为什么还是老的?原来是启动的时候还是默认选择了老的内核,这里需要重新设置一下启动时的默认内核:

首先查看当前都有哪些启动项:

cat /boot/grub2/grub.cfg |grep menuentry

menuentry 'CentOS Linux (5.2.10-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.6.2.el7.x86_64-advanced-07151862-c2b9-45dc-bf7a-af8d2a6fa6c1' {

menuentry 'CentOS Linux (3.10.0-514.10.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.6.2.el7.x86_64-advanced-07151862-c2b9-45dc-bf7a-af8d2a6fa6c1' {

复制代码

设置默认选项(需要升级为root用户):

grub2-set-default 'CentOS Linux (5.2.10-1.el7.elrepo.x86_64) 7 (Core)'

复制代码

再次重启,重启后查看内核:

uname -r

5.2.10-1.el7.elrepo.x86_64

复制代码

OK,内核成功升级,再次启动Docker试试(别忘了启动服务发现,我这里是ETCD):

ETCD启动:

./etcd --name docker-node3 --initial-advertise-peer-urls http://10.208.10.17:2380 --listen-peer-urls http://10.208.10.17:2380 --listen-client-urls http://10.208.10.17:2379,http://127.0.0.1:2379 --advertise-client-urls http://10.208.10.17:2379 --initial-cluster-token etcd-cluster --initial-cluster docker-node1=http://10.208.10.14:2380,docker-node2=http://10.208.10.16:2380,docker-node3=http://10.208.10.17:2380 --initial-cluster-state new &

复制代码

Docker 启动:

sudo /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://10.208.10.14:2379 --cluster-advertise=10.208.10.14:2375 &

复制代码

当所有主机都完成上述操作时,发现容器间总算可以互通了。

其他问题:

error locating sandbox id c43437e6300a0c6ea20d2d9f95bbe318e557d1eedfa585ab5218345eeef32a36: sandbox c43437e6300a0c6ea20d2d9f95bbe318e557d1eedfa585ab5218345eeef32a36 not found

复制代码could not get network sandbox (oper true): failed get network namespace ""

复制代码

最好删除之前创建的network和container,否则可能出现其他问题。

不同主机上的容器间使用hostname或者container name通信好像有问题,可以使用docker swarm来解决。

参考资料:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值