Docker跨主机容器互传数据问题及解决方法

目前我这里docker主要使用1.5版本,用途是给研发、运维做测试环境,给游戏与平台业务做生产应用,昨天接到某游戏研发反馈,2个不同宿主机进行数据同步的时候,出现以下错误

orrupted MAC on input.
Disconnecting: Packet corrupt
lost connection

经过谷歌搜索发现问题原因是

"Corrupted MAC on input"
This situation happens when the packet is decrypted, the length field is checked, the MAC is computed over the decrypted data and then checked against the MAC field from the SSH packet (see the picture above). If those two MACs don‘t match we print the "bad mac" error message.
Possible reasons for "Corrupted MAC on input"
If you see those messages instead of the "Bad packet length" one you can safely assume that the encryption/decryption works fine. If it wasn‘t then the packet length check could hardly pass a few times in a row - assuming we have seen the message a couple of times at least. That means that we have a data corruption somewhere. There are many situations this could happen. It could be a mulfunctioning:
firewall, or
NAT, or
NIC device driver, or
NIC itself, or
switch/router along the way, or
...something else that corrupted the data in between the two SSH parties
Again, it could also be the SSH implementation itself but as with the "bad packet length" problem that‘s usually not the case. Note that all those corruptions assume that the TCP packet passes the checksum test but that can easily happen. The checksum is basically a sum of all 16 bit words in the TCP frame; see RFC 793 (Transmission Control Protocol) for the details.

具体网页地址是https://blogs.oracle.com/janp/entry/ssh_messages_code_bad_packet

我容器跨主机互通是使用ovs+vxlan,为了测试是否真为此问题,我使用下面方法进行测试。

1、测试环境

容器名       内网IP          宿主机
test_mac    172.16.2.114    A 
test_mac_2  172.16.2.115    B
test_mac_3  172.16.2.116    A

在宿主机A的容器test_mac里生成3G测试文件

09:56:16 # dd if=/dev/zero of=/tmp/test.tgz bs=1G count=3
3+0 records in
3+0 records out
3221225472 bytes (3.2 GB) copied, 5.21114 s, 618 MB/s

2、测试另外宿主机B的跨主机容器数据同步情况

[email protected]:/tmp
09:56:21 # scp  -P 22 172.16.2.114:/tmp/test.tgz .
[email protected]‘s password:
test.tgz                                                                                     3%   99MB  50.6MB/s   00:58 ETA
Corrupted MAC on input.
Disconnecting: Packet corrupt
lost connection

可以看到出现了问题。

3、测试通宿主机容器数据同步情况

09:59:50 # scp -P 22 172.16.2.114:/tmp/test.tgz .
[email protected]‘s password:
test.tgz                                                                                   100% 3072MB  80.8MB/s   00:38
[email protected]:/tmp

可以看到正常同步。

4、解决跨宿主机容器数据同步方法

先在宿主机B里获取容器test_mac_2的pid

[[email protected] ~]# docker inspect test_mac_2|grep -i pid
        "PidMode": "",
        "Pid": 29416,

可以看到pid是29416

然后使用nsenter来设置容器的内网网卡eth1关闭校验和

nsenter --target 29416 --mount --uts --ipc --net --pid -- /bin/bash -c "ethtool -k eth1"

使用nsenter是因为此方法可以直接拥有最高权限来修改,如果直接在容器里输入会有下面错误

10:12:52 # ethtool -K eth0 tx off rx off
Cannot get device feature names: No such device
[email protected]:/

下面是解决前eth1网卡信息

[[email protected] ~]# nsenter --target 29416 --mount --uts --ipc --net --pid -- /bin/bash -c "ethtool -k eth1"
Features for eth1:
rx-checksumming: on
tx-checksumming: on
	tx-checksum-ipv4: off [fixed]
	tx-checksum-ip-generic: on
	tx-checksum-ipv6: off [fixed]
	tx-checksum-fcoe-crc: off [fixed]
	tx-checksum-sctp: off [fixed]
scatter-gather: on
	tx-scatter-gather: on
	tx-scatter-gather-fraglist: on
tcp-segmentation-offload: on
	tx-tcp-segmentation: on
	tx-tcp-ecn-segmentation: on
	tx-tcp6-segmentation: on
udp-fragmentation-offload: on
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off [fixed]
receive-hashing: off [fixed]
highdma: on
rx-vlan-filter: off [fixed]
vlan-challenged: off [fixed]
tx-lockless: on [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: on
tx-ipip-segmentation: on
tx-sit-segmentation: on
tx-udp_tnl-segmentation: on
tx-mpls-segmentation: off [fixed]
fcoe-mtu: off [fixed]
tx-nocache-copy: on
loopback: off [fixed]
rx-fcs: off [fixed]
rx-all: off [fixed]
tx-vlan-stag-hw-insert: on
rx-vlan-stag-hw-parse: on
rx-vlan-stag-filter: off [fixed]
busy-poll: off [fixed]

开始运行命令关闭校验和

[[email protected] ~]# nsenter --target 29416 --mount --uts --ipc --net --pid -- /bin/bash -c "ethtool -K eth1 tx off rx off "
Actual changes:
rx-checksumming: off
tx-checksumming: off
	tx-checksum-ip-generic: off
tcp-segmentation-offload: off
	tx-tcp-segmentation: off [requested on]
	tx-tcp-ecn-segmentation: off [requested on]
	tx-tcp6-segmentation: off [requested on]
udp-fragmentation-offload: off [requested on]

然后在查看一下eth1网卡信息

Features for eth1:
rx-checksumming: off
tx-checksumming: off
	tx-checksum-ipv4: off [fixed]
	tx-checksum-ip-generic: off
	tx-checksum-ipv6: off [fixed]
	tx-checksum-fcoe-crc: off [fixed]
	tx-checksum-sctp: off [fixed]
scatter-gather: on
	tx-scatter-gather: on
	tx-scatter-gather-fraglist: on
tcp-segmentation-offload: off
	tx-tcp-segmentation: off [requested on]
	tx-tcp-ecn-segmentation: off [requested on]
	tx-tcp6-segmentation: off [requested on]
udp-fragmentation-offload: off [requested on]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: on
tx-vlan-offload: on
ntuple-filters: off [fixed]
receive-hashing: off [fixed]
highdma: on
rx-vlan-filter: off [fixed]
vlan-challenged: off [fixed]
tx-lockless: on [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: on
tx-ipip-segmentation: on
tx-sit-segmentation: on
tx-udp_tnl-segmentation: on
tx-mpls-segmentation: off [fixed]
fcoe-mtu: off [fixed]
tx-nocache-copy: on
loopback: off [fixed]
rx-fcs: off [fixed]
rx-all: off [fixed]
tx-vlan-stag-hw-insert: on
rx-vlan-stag-hw-parse: on
rx-vlan-stag-filter: off [fixed]
busy-poll: off [fixed]

可以很明显看到rx-checksumming与tx-checksumming都从on变为off了。

然后在宿主机B里使用test_mac_2进行数据同步宿主机A的test_mac数据

10:16:09 # scp  -P 22 172.16.2.114:/tmp/test.tgz .
[email protected]‘s password:
test.tgz                                                                                   100% 3072MB  46.6MB/s   01:06
[email protected]:/

可以看到数据传输正常。

时间: 2024-08-24 10:18:35

Docker跨主机容器互传数据问题及解决方法的相关文章

如何实现docker跨主机之间容器通信问题(方法二)

主机名 宿主机IP 容器分配网段 启动容器的IP testa 192.168.1.105 172.172.0.0/24 172.172.0.10 testb 192.168.1.106 172.172.1.0/24 172.172.1.10 1.在testa主机上创建docker桥接网络 docker network create --subnet=172.172.0.0/24 docker-br0 2.在testb主机上创建docker桥接网络 docker network create --

10: docker 跨主机的容器间通信(macvlan / overlay )

docker 跨主机的容器间通信(macvlan) 作用: 虚拟多个mac地址,虚拟出多个网卡给容器用. #创建macvlan网络 docker network create --driver macvlan(要创建的网络类型) --subnet  子网IP段  --gateway 本机网关 -o parent=本机网卡  创建的macvlan网络名称 [[email protected] ~]# docker network create --driver macvlan --subnet 1

Docker跨主机通信网络

Docker跨主机通信网络 跨主机网络方案包括: docker原生的 overlay 和 macvlan.第三方方案:常用的包括flannel.weave 和 calico. (1)准备 Overlay 网络实验环境 [[email protected] ~]# docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap [[email protected] ~]# netstat -

Docker 跨主机网络方案分析

overlay 俗称隧道网络,它是基于 VxLAN 协议来将二层数据包封装到 UDP 中进行传输的,目的是扩展二层网段,因为 VLAN 使用 12bit 标记 VLAN ID,最多支持 4094 个 VLAN,这对于大型云网络会成为瓶颈,而 VxLAN ID 使用 24bit 来标记,支持多达 16777216 个二层网段,所以 VxLAN 是扩展了 VLAN,也叫做大二层网络. overlay 网络需要一个全局的“上帝”来记录它网络中的信息,比如主机地址,子网等,这个上帝在 Docker 中是

Docker 跨主机网络(十六)

一.跨主机网络概述 前面已经学习了 Docker 的几种网络方案:none.host.bridge 和 joined 容器,它们解决了单个 Docker Host 内容器通信的问题.本章的重点则是讨论跨主机容器间通信的方案. docker 原生的 overlay 和 macvlan.第三方方案:常用的包括 flannel.weave 和 calico. 二.准备 overlay 环境 为支持容器跨主机通信,Docker 提供了 overlay driver.Docerk overlay 网络需要

在数据库并发情况下避免插入重复数据的一个解决方法

目前公司的项目中碰到一个情况:需要向一个数据表table1中插入记录,该表的结构类似于下面的定义: 列名  类型 是否允许为空 Id int no Area string no AreaIndex int no Name string no 其中Name的值由Area和AreaIndex拼接而成,形式类似于“Area+AreaIndex”.对于相同的Area,AreaIndex从1开始计数,所以对于Area分别为“AA”,“BB”,“CC”的情况,Name的值类似下面这样: AA001 AA00

[转]mysql导入导出数据中文乱码解决方法小结

本文章总结了mysql导入导出数据中文乱码解决方法,出现中文乱码一般情况是导入导入时编码的设置问题,我们只要把编码调整一致即可解决此方法,下面是搜索到的一些方法总结,方便需要的朋友. linux系统中 linux默认的是utf8编码,而windows是gbk编码,所以会出现上面的乱码问题. 解决mysql导入导出数据乱码问题 首先要做的是要确定你导出数据的编码格式,使用mysqldump的时候需要加上--default-character-set=utf8, 例如下面的代码: 代码如下: mys

Android - "已安装了存在签名冲突的同名数据包",解决方法!

错误提示:已安装了存在签名冲突的同名数据包. 解决方法:打开Android Studio,打开logcat,用usb线连接你出错的手机,识别出手机之后,在你的项目后面,点击"run"按钮,随后AS会提示你,你删除先前安装的APP就可以了! 原文地址:https://www.cnblogs.com/sunylat/p/9962767.html

Docker compose v3版本构建跨主机容器编排构建wordpress集群

在Docker 1.13版本之后,可以说Docker 对于compose容器调度编排实现了飞跃,可以使得在编排容器的时候可以结合Docker swarm集群和跨主机通讯的概念.在Docker swarm 的基础之上引入stack对service镜像管理和编排.下面我们实战一下用之前构建wordpress集群来测试一下: 环境要求: 1.存在了Docker swarm集群: [[email protected] ~]# docker node ls ID