一、链路聚合
链路聚合(Link Aggregation),是指将多个物理端口捆绑在一起,成为一个逻辑端口,以实现出/入流量在各成员端口中的负荷分担。
1.环境:两块网卡的虚拟机,则是两个独立的网络接口,将几个接口连接起来,以就叫链路聚合
2.链路聚合作用:1)提高稳定性 ;2)提高网络带宽(有两个千兆网卡,要1500兆)
3.链路聚合方式:1)bond ;2)team
二、bond--->最多连两块网卡。功能比team少
1)工作方式0,平衡轮询模式:两块网卡轮流接收数据包
2)工作方式1,主备式:一个网卡工作另一网卡备用-----> 速率不变,稳定性提高
3)工作方式3,广播容错(带广播功能的轮换) :所有数据包都通过接口广播
1.命令方式聚合步骤
a)关机状态加两块网卡
b)开机清除网卡初始配置
c)添加bond链路 ----->此时是虚拟接口,网络ping不通
nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.xx/24
d)给bond链路插入两块真实网卡 ----->网通
nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 ###master指定接口bond0
nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0 ###bond-slave实现网卡阵列服务
测试:
监控命令: watch -n 1 cat /proc/net/bonding/bond0 ###查看网络接口信息
ping 172.25.254.xx
ifconfig eth0 down ###当eth0网卡坏,eth1立马接替eth0,依然可无间断的ping通
ifconfig eth0 up ###再次启用网卡0,网卡状态为up,但不会替代网卡1工作,工作网卡仍为eth1
2.文本方式聚合
a) vim /etc/sysconfig/network-scripts/ifcfg-bond0 ###添加链路
DEVICE=bond0 ##设备为bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.xx
PREFIX=24
TYPE=Bond ##链路类型为bond接口
BONDING_OPTS=mode=active-backup ##接口工作模式为主动备份式
BONDING_MASTER=yes
b) vim /etc/sysconfig/network-scripts/ifcfg-eth0 ###插入真实网卡0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0 ###为谁服务
SLAVE=yes ##master主;slave辅助
c) vim /etc/sysconfig/network-scripts/ifcfg-eth1 ##插入真实网卡1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
d) systemctl restart network ###启动底层服务
systemctl restart NetworkManager ###重启上层控制服务
3.删除bond接口
nmcli connection delete bond0 ##删除bond0接口
nmcli connection delete eth0 ##删除eth0网卡接口
nmcli connection delete eth1 ##删除eth1网卡接口
三、team ------>最多可连8块网卡
1.聚合方式四种:
a)broadcast 广播容错模式:所有数据包都通过接口广播
b)roundrobin 平衡轮询模式:多块网卡轮流接收数据包
c)activebackup 主动备份模式:只有一块网卡工作,当工作中的网卡出现问题,其他网卡顶替其工作
d)loadbalance 负载均衡模式:该模式判断不同网卡的负载,给负载最少的网卡发送数据包
2.命令方式聚合步骤:
a)关机状态加两块网卡
b)开机清除网卡初始配置
c)添加team链路----->此时是虚拟接口,网络ping不通
nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' ip4 172.25.254.xx/24
d)给bond链路插入真实网卡--->网通
nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
测试:
监控命令: watch -n 1 teamdctl team0 stat ###查看网络接口信息
ping 172.25.254.xx
ifconfig eth0 down ###当eth0网卡坏,eth1立马接替eth0,依然可无间断的ping通
ifconfig eth0 up ###再次启用网卡0,网卡状态为up,但不会替代网卡1工作,工作网卡仍为eth1
3.文本方式
a) vim /etc/sysconfig/network-scripts/ifcfg-team0
DEVICE=team0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.xx
PREFIX=24
TEAM_CONFIG='{"runner":{"name":"activebackup"}}' ###虚拟接口配置
TYPE=Team ###链路类型
b) vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
DEVICETYPE=TeamPort ###类型=team接口
TEAM_MASTER=team0 ###为谁服务
c)vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
DEVICETYPE=TeamPort
TEAM_MASTER=team0
d) systemctl restart network ###启动底层服务
systemctl restart NetworkManager ###重启上层控制服务
4. 删除team接口
nmcli connection delete team0 ##删除team0接口
nmcli connection delete eth0 ##删除eth0网卡接口
nmcli connection delete eth1 ##删除eth1网卡接口
四、配置网络桥接
网络桥接用网络桥实现共享上网。主机和客户机,除了利用软件外,还可以用系统自带的网络桥建立连接
虚拟机通过网络桥可以实现对真机真实网卡的控制
环境(无网桥): ##无网桥状况,虚拟机接口数据需真机的内核做NAT后才可从真实接口出来
关闭所有虚拟机;
备份: cp /etc/sysconfig/network-scripts/ifcfg-br0 /mnt
cp /etc/sysconfig/network-scripts/ifcfg-enp0s25 /mnt
删除除了Bridge中virbr0、virbr1外的所有网络:nm-connection-editor
reboot后nm-connection-editor配置网络
删除后:
1.永久配置网桥
1)vim /etc/sysconfig/network-scripts/ifcfg-enp0s25 ###真实网卡配置文件
DEVICE=enp0s25 ###真实网卡
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0 ###在真实网卡上打开一个br0接口;共享真实网卡的控制权(输入、输出)
2)vim /etc/sysconfig/network-scripts/ifcfg-br0 ###网桥配置文件
TYPE=Bridge ###网桥
DEVICE=br0
BOOTPROTO=none
IPADDR=172.25.254.xx
PREFIX=24
ONBOOT=yes
3)systemctl restart network
systemctl restart NetworkManager.service
4)brctl show ###查看网桥
注:比较有无网桥安装虚拟机,发现有网桥状态,建立虚拟机网络速度更快。因为有网桥就不用经过NAT转换,读取速度更快
2.临时配置网桥(虚拟机)
1)建立网桥接口 brctl addbr br0 ###此时网ping不通;brctl show查看有网桥,无网卡
2)设置网桥IP ifconfig br0 172.25.254.xx/24 ###自己主机通,其他主机不通
3)桥接物理网卡 brctl addif br0 eth0 ###将br0插到eth0设备;其他主机也通
删除临时配置:
1)删除桥接接口的网卡信息 brctl delif br0 eth0 ##将br0从eth0设备取下
2)关闭桥接接口 ifconfig br0 down ##停止桥接接口工作后才能删除
3)删除网桥接口 brctl delbr br0