当前位置:网站首页>容器内组播
容器内组播
2022-07-25 06:27:00 【Fiona_q】
初闻组播我也是一愣,作为非计算机专业,半路出家研究容器和k8s的小白,组播对于我来说是陌生的,所以也是各种查阅资料,经历了先了解再尝试,不论是负责任还是不负责任地说,很大程度上本篇博客也是搬运工的操作,但是还是想要纪念一下我仅有的一些学习成果。
先声明一下研究组播的原因,要在容器集群管理软件上实现局域网内组播的功能,这次学习经历了对组播概念的了解,对局域网的了解,对macvlan的初步了解,关于路由和网关只有简单理解,目前并不熟悉打通局域网如何配置它们,大概过程就是这个样子,所以接下来我们一起学习吧~
目录
1. IP网络数据传输的方式
单播(unicast)
单播是在一个单个的发送者和一个接受者之间通过网络进行的通信。
缺点:会因为数据包的多次重复而浪费带宽资源,源主机的负荷会因为多次的数据复制而加大。
广播(broadcast)
主机之间“一对所有”的通讯模式,网络对其中每一台主机发出的信号都进行无条件复制并转发,所有主机都可以接收到所有信息(不管你是否需要)。
缺点:信息会发送到不需要该信息的主机从而浪费带宽资源,甚至引起广播风暴。
组播/多播(multicast)
主机之间“一对一组”的通讯模式,也就是加入了同一个组的主机可以接受到此组内的所有数据,网络中的交换机和路由器只向有需求者复制并转发其所需数据。
优点:提高了数据传送效率,减少了骨干网络出现拥塞的可能性。
更形象的理解可以看一下下图:


图片资料来自IP传输三种方式之组播 - 腾讯云开发者社区-腾讯云。
2.组播地址
首先了解一下五类IP地址的划分:
A类地址:第一个字节0开头,其余7位为网络地址,后3个字节为主机地址。A类地址是起始地址为:1~126,有效网络数字为126,每个网络号所包含的有效主机数为16,777,214。1.0.0.1~126.225.255.254,A类保留给政府机构。 A类地址中的私有地址和保留地址: |
B类地址:第一个字节10开头,前2个字节为网络地址,后2个字节为主机地址,B类地址的起始地址为:128~191,有效网络数为16,382个,每个网络号所包含的有效主机数为65,531。128.0.0.1~191.255.255.254,B类分配给中等规模的公司。 B类地址的私有地址和保留地址: |
C类地址:第一个字节110开头,前3个字节为网络地址,后1个字节为主机地址,C类地址的起始地址为192~223,有效网络数为2,097,150个,每个网络号所包含的有效主机数为254。192.0.0.1~223.255.255.254,C类分配给任何需要的人。 C类地址中的私有地址: |
D类地址:第一个字节1110开头,通常用于多点传送或者组的寻址。224.0.0.0~239.255.255.255,D类用于组播。 D类地址不分网络地址和主机地址 |
| E类地址:第一个字节11110开头,实验地址,保留给将来使用。240.0.0.0~247.255.255.255,E类用于实验,各类可容纳的地址数目不同。E类地址不分网络地址和主机地址 |
IP地址的资料来自说说有哪五类ip?范围是什么?_zxa1334的博客-CSDN博客_各类地址第一个字节起始范围
我们要实现的是容器内组播的功能,所以需要使用D类地址,关于D类地址的说明如下:

PS:可知不是所有的 D 类地址 , 都可以作为组播地址 。
3. macvlan
macvlan 本身是 linux 内核的模块,本质上是一种网卡虚拟化的技术,其功能是允许在同一个物理网卡上虚拟出多个网卡,通过不同的 MAC 地址在数据链路层进行网络数据的转发。
一块网卡上配置多个 MAC 地址,即多个接口,每个接口都可以配置自身的 IP 地址。Docker 的 macvlan 网络实际上就是使用了 Linux 提供的 macvlan 驱动功能。
因为多个 MAC 地址的网络数据包都是从同一个网卡上传输,因此需要打开网卡的混杂模式。
(上述资料来自链接:https://www.jianshu.com/p/cc481870236b)
macvlan有四种模式,分类如下:
bridge:各个子设备之间可以通信。
vepa:各个子设备直接无法直接通信(可以通过支持端口聚合的交换机通信),可以和外部通信。
private:和vepa模式类似,各个子设备之间无法通信,即使通过支持端口聚合的交换机也不能。
passthru:会接管父设备(网口),父设备不能接收数据包,并且每个父设备只允许存在一个macvlan设备。
后续测试docker-macvlan使用的是bridge模式。
4. 组播通信实现
数据源:组播程序所在的物理机作为数据源,将数据信息发给组播组地址。
组播组:设置组播组ip,并将数据源发送的信息转发给组播成员。
组播组 主机 :一般来说组播组中主机与数据源主机处于同一局域网中,在不同网络中需要有组播路由器。
组播分类 :
因特网组播 :路由器之间的组播 ; 涉及到 IGMP 协议 和 组播路由选择协议 。
硬件组播 :子网内的组播 。
具体实现:
首先开启网卡的混杂模式:
ip link set enp4s0 promisc on 
在安装有docker环境的主机上创建驱动为macvlan的网络:
docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.2 -o parent=enp4s0 macvlan190 -d : 驱动类型
--subnet:子网段
--gateway:网关
-o parent: 使用的网卡
macvlan190: 创建的macvlan的名字,自己设置即可

查看网络情况:
docker network ls 
将需要的容器运行在该macvlan上:
docker run -it -d --name mactest1 --net macvlan190 --ip 192.168.0.207 test1:v1--name: mactest1为启动的容器的名字
--net: macvlan190为使用的网络
--ip: 192.168.0.207为容器的ip
test1:v1是本地镜像包的名字

查看网络ping通情况,macvlan的ip无法ping通本机的ip,可以ping通同网段的其他ip: 
查看组播测试结果,可以接收组播消息: 
边栏推荐
- JS gets the text selected by the mouse and is in the selected state
- Cout format output common functions and flags summary
- Detailed annotation and analysis of start.s of uboot
- C#--MetroFramework框架调用metroModernUI库,并在工具栏使用
- mysql 查询当前数据库下的表名
- Draw Bezier curve through screen interaction
- 【C语言】指针和数组的深入理解(第一期)
- GF Securities online account opening? Is it safe?
- Installation and configuration of automatic operation and maintenance management workers ansible
- Easy gene chip SEQ analysis method: practical workflow and advanced applications
猜你喜欢

In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?

NFT: how to improve rentable NFT (erc-4907)
![[unity3d] ugui callback function](/img/6f/312e7f2cf76fa932e66c5ba0737219.png)
[unity3d] ugui callback function

Pdf snapshot artifact

JZ7 重建二叉树

阻塞队列分析

SAP FICO section III BDC and ltmc import S4 financial account

Developers must read: 2022 mobile application operation growth insight white paper

The code of Keil and Si compiler is not aligned??

Easy gene chip SEQ analysis method: practical workflow and advanced applications
随机推荐
Detailed explanation of the difference, working principle and basic structure between NMOS and PMOS
Solve the problem of invalid modification of QT 5 interface. Solve the problem of invalid modification of qtdesigner
Ceres solver version 1.14 and eigen3.2.9
EOL offline sequence based on iso13209 (Otx)
Keil uvisin5 code auto completion or code Association
[reprint] pycharm packages.Py program as executable exe
4、 MFC toolbar, runtime class information mechanism, runtime creation mechanism
When the graduation season comes, are you ready? What are we going to do
SAP FICO 第三节 BDC和LTMC导入S4财务科目
嵌入式c语言开发之宏定义求两个数的最大值的使用技巧
VBS common built-in functions (2)
Bug notes
The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market
DOM event type
Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
Netease game Flink SQL platform practice
Scientific computing library numpy Foundation & Improvement (Understanding + explanation of important functions)
U-boot-1.1.6 transplant notes (beginner)
Special episode of Goddess Festival | exclusive interview with Chinese AI goddess Zhang Qingqing's transformation from a female learning tyrant to a female entrepreneur
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate