KVM virtualization management card

Virtual bridge to view the current status: brctl show

brctl commonly used commands

addbr add a bridge

delbr delete a bridge

addif add network port

delif delete network port

VALNET

  Represents LAN Local Area Network, a local area network, typically connected to a LAN computer Hub (hub) and Switch (Switch). In general, two computers connected to the same Hub or Switch, they are in the same LAN. (That is, if your network is divided out from under a switch that few strings, then we are connected in this network is a LAN inside)

A represents a LAN broadcast domains (broadcast domain multicast routers). The implication is: all members of the LAN will receive broadcast packets sent by any one member.

  VLAN expressed Virtual LAN (virtual network segment). switch having a VLAN function can be divided into a plurality of own port LAN. Broadcast packets can be sent from a computer to other computers in the same LAN received, but located in other LAN computers can not receive. Briefly, a VLAN switch is divided into a plurality of switches, limit the scope of the broadcast, in the isolated computer Layer to a different VLAN.

For example, there are two sets of machines, Group A and B, we want configured in Group A of the machine can access each other, Group B in the machine can also visit each other, but A and B machine can not visit each other. One method is to use two switches, A and B are connected to a switch. Another method is to use a switch with a VLAN function, the machine A and B are placed in a different VLAN.

  VLAN isolation is the isolation story, A and B can not access each other refers to a Layer broadcast packet (such as ARP) can not cross the border of the VLAN. But the three-tier (for example, IP) can be achieved through a router so that A and B are interoperable.

Now almost all switches support VLAN. The switch port generally has two configuration modes: Access and Trunk.

ccess mouth 

  These ports are marked with VLAN tag, indicating that the port belongs to which VLAN. With different VLAN ID to distinguish VLAN, VLAN ID ranges are 1-4096. Access ports are directly connected to a computer network card, so the card out of the packet flows after Access ports are marked in the VLAN tag. Access port can only belong to one VLAN.

Trunk 口

Suppose there are two switches A and B. There are the A VLAN1 (red), VLAN2 (yellow), VLAN3 (blue); there VLAN1,2,3 on B, then how to make the same VLAN can communicate between the AB it?

  The approach is to link A and B, and A and B port connected to allow data VLAN1,2,3 through all three VLAN. This port is a Trunk port. The VLAN1, data 2, 3 of the pack is always with their VLAN tag in the process of reaching the other side by the switch Trunk mouth. 

Linux Bridge achieve Vlan principle

 

  eth0 is the physical NICs on the host, there is a designated sub-device eth0.10 connected thereto. eth0.10 device is a VLAN, VLAN ID which is VLAN 10. eth0.10 hanging named brvlan10

On Linux Bridge, virtual network cards virtual machine VM1 of vent0 also hung on brvlan10.

  Such a configuration is its effect: the host software implements a switch (of course, virtual), defined above a VLAN10. eth0.10, brvlan10 and vnet0 both were received on the Access VLAN10 mouth. The eth0 is a Trunk port. VM1 be sent by vnet0 VLAN10 packets are marked with labels.

eth0.10 action is: VLAN10 defined role brvlan10 is: Bridge on other network devices are automatically added to the VLAN10 increase a VLAN20, following FIG.

 

这样虚拟交换机就有两个 VLAN 了,VM1 和 VM2 分别属于 VLAN10 和 VLAN20。

对于新创建的虚机,只需要将其虚拟网卡放入相应的 Bridge,就能控制其所属的 VLAN。

VLAN 设备总是以母子关系出现,母子设备之间是一对多的关系。 一个母设备(eth0)可以有多个子设备(eth0.10,eth0.20 ……),而一个子设备只有一个母设备。

操作步骤

 

第一步 查看当前宿主机核心是否提供VLAN功能

dmesg | grep –i 802

或者检查/proc/net/vlan目录是否存在,如果沒有提供VLAN 功能,/proc/net/vlan目录是不存在的

第二步 查看8021q模块是否载入系统

lsmod | grep 8021q

第三步 如果没有载入请载入

modprobe 8021q

第四步 安装VLAN配置工具---vconfig,需提前准备好安装包vconfig-1.9-16.el7.x86_64.rpm

rpm -ivh vconfig-1.9-16.el7.x86_64.rpm

rpm -qa vconfig

第五步 添加一块网卡,使用ip a查看

第六步 使用nmtui填写配置文件,重启网卡

第七步 基于新添加的网卡建立vlan10,vlan20接口:ens39.10 ens39.20

vconfig add ens39 10

vconfig add ens39 20

第八步 创建刚添加vlan10和vlan20接口的配置文件

vim ifcfg-ens39.10                 vim ifcfg-ens39.20

VLAN=yes                           VLAN=yes

TYPE=vlan                           TYPE=vlan

PHYSDEV=ens39                       PHYSDEV=ens39

VLAN_ID=10                          VLAN_ID=20

NAME=ens39.10                       NAME=ens39.20

ONBOOT=yes                          ONBOOT=yes

ZONE=trusted                        ZONE=trusted

DEVICE=ens39.10                      DEVICE=ens39.20

BRIDGE=brvlan-10                     BRIDGE=brvlan-20

第九步 建立网桥brvlan-10和brvlan-20

brctl addbr brvlan-10

brctl addbr brvlan-20

编辑网桥配置文件

vim ifcfg-brvlan-10

TYPE=bridge

BOOTPROTO=static

NAME=brvlan-10

DEVICE=brvlan-10

ONBOOT=yes

vim ifcfg-brvlan-20

TYPE=bridge

BOOTPROTO=static

NAME=brvlan-20

DEVICE=brvlan-20

ONBOOT=yes

第十一步 将网桥brvlan-10接到网口ens39.10,将网桥brvlan-20接到网口ens39.20

brctl addif brvlan-10 ens34.10

brctl addif brvlan-20 ens34.20

第十二步 重启网络服务

systemctl restart network

第十三步 虚机测试VLAN

先将NetworkManager服务关闭

(1)在宿主机中已经提前创建好了虚机 VM1

在 virt-manager 中将 VM1 的虚拟网卡挂到 brvlan-10 上

(2)从VM1克隆一台虚机VM2

virst-clone -o vm1 -n vm2 -f /var/lib/libvirt/images/vm2.qcow2

(3)在 virt-manager 中将 VM2 的虚拟网卡挂到 brvlan-10 上

(4)启动VM1和VM2,并配置ip

(5)查看 Bridge,发现 brvlan10 已经连接了 vnet0 vnet1设备。

(6)当两台虚机处于同一vlan,就可以相互ping通,处于不同vlan,就不能ping通

第十四步 如何使两台虚机ping通外网

(1)再分别添加一块网卡

(2)将添加的网卡挂到br0上即可

网卡配置bond(绑定)

 

就是说将多张网卡通过一个额外的软件的bond驱动实现绑定,这样,可以提高网卡的吞吐量,实现高可用和负载均衡。

  (1)网卡bond(绑定),也称作网卡捆绑。就是将两个或者更多的物理网卡绑定成一个虚拟网卡。网卡是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在应用部署中是一种常用的技术。

      多网卡绑定实际上需要提供一个额外的软件的bond驱动程序实现。通过驱动程序可以将多块网卡屏蔽。对TCP/IP协议层只存在一个Bond网卡,在Bond程序中实现网络流量的负载均衡,即将一个网络请求重定位到不同的网卡上,来提高总体网络的可用性。

(2)网卡绑定的目的:

   1.提高网卡的吞吐量。

   2.增强网络的高可用,同时也能实现负载均衡。

(3)网卡配置bond(绑定)bond模式:

1、Mode=0(balance-rr) 表示负载分担round-robin,平衡轮询策略,具有负载平衡和容错功能

  bond的网卡MAC为当前活动的网卡的MAC地址,需要交换机设置聚合模式,将多个网卡绑定为一条链路。(就是说我每个网卡负载能力都是一样的,轮着来负责请求,而且给你提供请求的网卡也是随机的)

2、  Mode=1(active-backup) 表示主备模式,具有容错功能,只有一块网卡是active(激活),另外一块是备的standby(备份),这时如果交换机配的是捆绑,将不能正常工作,因为交换机往两块网卡发包,有一半包是丢弃的。(就是说有两块网卡,一个是主,一个是备,交换机的网卡做了捆绑以后,交换机会同时往这两快网卡发数据,因为第二块网卡是备的网卡,这个时间段它是没有对外提供服务的,只有第一块网卡对外提供服务,所以,交换机往这两块网卡发包,第二块网卡的包就丢弃了)

3、Mode=2(balance-xor) 表示XOR Hash负载分担(异或平衡策略),具有负载平衡和容错功能

每个slave接口传输每个数据包和交换机的聚合强制不协商方式配合。(需要xmit_hash_policy)。

4、  Mode=3(broadcast)  表示所有包从所有interface发出,广播策略,具有容错能力,这个不均衡,只有冗余机制...和交换机的聚合强制不协商方式配合。(选用此模式,多块网卡同时对外提供服务,只不过可能第一块负担的多一些,第二块负担的少一些)(需要配置交换机)

5、Mode=4(802.3ad) 表示支持802.3ad协议(IEEE802.3ad 动态链接聚合) 和交换机的聚合LACP方式配合(需要xmit_hash_policy)。

6、  Mode=5(balance-tlb) 适配器传输负载均衡,并行发送,无法并行接收(当服务器发送数据的时候,是多块网卡同时发送,但在接收的时候,只有一块网卡在接收数据),解决了数据发送的瓶颈。 是根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave。 

7、Mode=6(balance-alb) 在5的tlb基础上增加了rlb。适配器负载均衡模式并行发送,并行接收数据包。(既可以同时发送也可以同时接收数据)

  5和6不需要交换机端的设置,网卡能自动聚合。4需要支持802.3ad。0,2和3理论上需要静态聚合方式,但实测中0可以通过mac地址欺骗的方式在交换机不设置的情况下不太均衡地进行接收。

常用的有三种:

mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。

mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。

mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。

实现多块网卡绑定bond

 

第一步 因为我们之前的实验是做的vlan,所以要恢复ens39网卡,并添加额外的3张网卡

(1)关掉绑定的虚拟机

(2)将虚拟机的网卡绑定至br0

(3)断开虚拟网桥,断开虚拟网口

brctl delif brvlan-10 ens39.10

brctl delif brvlan-20 ens39.20  

(4)删除虚拟网桥和网口

vconfig rem ens39.10

vconfig rem ens39.20

brctl delbr brvlan-10

brctl delbr brvlan-20

(5)删除网桥配置文件

rm –rf ifcfg-ens39.*

第二步 修改每个网卡的配置文件

TYPE=Ethernet

BOOTPROTO=none

DEVICE=每个网卡名

ONBOOT=yes

MASTER=bond0

SLAVE=yes

第三步 载入bond模块

modprobe bonding

第四步 创建bond0网卡

DEVICE=bond0

TYPE=Bond

NAME=bond0

BONDING_MASTER=yes 

BOOTPROTO=static

USERCTL=no

ONBOOT=yes

#IPADDR=192.168.10.10

#PREFIX=24

#GATEWAY=192.168.10.19

BONDING_OPTS="mode=6 miimon=100"

BRIDGE=br1

第五步 创建桥接的网卡br1

vim ifcfg-br1

TYPE=Bridge

DEVICE=br1

ONBOOT=yes

IPADDR=192.168.66.2

#IPADDR1=192.168.20.1

#IPADDR2=192.168.30.1

#IPADDR3=192.168.40.1

#IPADDR4=192.168.50.1

#PREFIX3=24

#PREFIX4=24

#GATEWAY=172.16.0.1

#DNS1=172.16.254.251

#DNS2=223.5.5.5

第六步 重启网络服务

在bond上做VLAN

 

第一步 在原先bond实验的基础上进行实验,先对虚拟网卡br1进行修改

TYPE=Bridge

DEVICE=br1

ONBOOT=yes

BOOTPROTO=static

NAME=br1

第二步 创建虚拟网口br1 10 和 br1 20

vconfig add br1 10

vconfig add br1 20

第三步 为虚拟网口创建配置文件

vim ifcfg-br1.10

VLAN=yes

TYPE=vlan

PHYSDEV=br1

VLAN_ID=10

NAME=br1.10

ONBOOT=yes

ZONE=trusted

DEVICE=br1.10

BRIDGE=brvlan-10

vim ifcfg-br1.20

第四步 编辑网桥配置文件 brvlan-10 和 brvaln-20

vim ifcfg-brvlan-10

TYPE=bridge

BOOTPROTO=static

NAME=brvlan-10

DEVICE=brvlan-10

ONBOOT=yes

vim ifcfg-brvlan-20

TYPE=bridge

BOOTPROTO=static

NAME=brvlan-20

DEVICE=brvlan-20

ONBOOT=yes

第五步 网口连接网桥

brctl addif brvlan-10 br1.10

brctl addif brvlan-20 br1.20

第六步 重启网络服务

第七步 开启虚拟机验证

Guess you like

Origin www.cnblogs.com/shuaiyin/p/10953468.html