**配置网络桥接
**配置 bond 网络接口
**配置 team 网络接口
简单的说,bonding就是把多个物理网络接口绑定到一起,使它们就像一个网络接口那样运行。 通过Bonding技术,可以实现网口冗余,负载均衡,从而达到高可用高可靠的目的。
模式 0 ( 平衡轮循 ) - 轮循策略 , 所有接口都使用采用轮循方式在所有 Slave 中传输封包 ; 任何 Slave 都可以接收。
模式 1 ( 主动备份 ) - 容错。一次只能使用一个 Slave 接口, 但是如果该接口出现故障 , 另一个Slave 将接替它。
模式 3 ( 广播 ) - 容错。所有封包都通过所有 Slave 接口广播。
[kiosk@foundation84 Desktop]$ su - 切换到超级用户
Password:
Last login: Thu May 17 10:55:36 CST 2018 on pts/2
Last failed login: Thu May 17 10:57:57 CST 2018 from 172.25.254.121 on ssh:notty
There was 1 failed login attempt since the last successful login.
ABRT has detected 2 problem(s). For more info run: abrt-cli list --since 1526525736
[root@foundation84 ~]# virt-manager 打开虚拟机管理命令
[root@foundation176 Desktop]# ifconfig 查看时没有bond0网卡
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a3:bd:a3 txqueuelen 1000 (Ethernet)
RX packets 2010 bytes 156554 (152.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 108 bytes 11595 (11.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:af:54:5f txqueuelen 1000 (Ethernet)
RX packets 1594 bytes 111905 (109.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 23 bytes 2196 (2.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 2196 (2.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@foundation176 Desktop]# nmcli connection add con-name bond0 type bond mode active-backup ip4 172.25.254.121/24 添加bond0
Connection 'bond0' (84d66bb7-0355-4e30-8d06-65e9e34113ba) successfully added.
[root@foundation176 Desktop]# ifconfig 查看已经成功添加
nm-bond: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 172.25.254.121 netmask 255.255.255.0 broadcast 172.25.254.255
ether 4e:55:dc:7f:f4:11 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@foundation176 Desktop]# nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0 添加两块网卡,因为打开监控没有网卡为其服务
Connection 'eth0' (295663a8-4d73-44df-a7de-123d2a94b49f) successfully added.
[root@foundation176 Desktop]# nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0
Connection 'eth1' (9aba4da4-c36f-4667-8ddf-66dcea0d1fa3) successfully added.
[root@foundation176 Desktop]# ping 172.25.254.121 ping网可以ping的通
PING 172.25.254.121 (172.25.254.121) 56(84) bytes of data.
64 bytes from 172.25.254.121: icmp_seq=1 ttl=64 time=0.043 ms
[root@foundation176 Desktop]# ifconfig eth0 down 将eth0关闭,则eth1会出来顶替eth0的工作
[root@foundation176 Desktop]# ifconfig eth0 up 将etho打开,则eth0作为备份闲置,解决了网突然坏掉的情况
[root@localhost ~]# cat /proc/net/bonding/nm-bond 只有添加了bond之后才可以查看到信息
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: None
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
[root@localhost ~]# watch -n 1 cat /proc/net/bonding/nm-bond
查看bond网络接口的配置打开监控
添加bond接口etho,eth1的监控呈现,以及当eth0坏掉的时候eth1出来顶替的效果。
[root@localhost ~]# ping 172.25.254.121
PING 172.25.254.250 (172.25.254.250) 56(84) bytes of data.
64 bytes from 172.25.254.250: icmp_seq=1 ttl=64 time=0.568 ms
64 bytes from 172.25.254.250: icmp_seq=2 ttl=64 time=0.507 ms
64 bytes from 172.25.254.250: icmp_seq=3 ttl=64 time=0.715 ms
64 bytes from 172.25.254.250: icmp_seq=4 ttl=64 time=0.406 ms
Team和 bond0 功能类似,Team不需要手动加载相应内核模块,Team有更强的拓展性,支持8块网卡。
broadcast 广播容错
roundrobin 平衡轮循
activebackup 主备
loadbalance 负载均衡
由于本虚拟机并未设置IP,所以就不能用上一个实验的ping命令来测试实验效果。
[root@localhost Desktop]# nmcli connection delete bond0 删除bond接口恢复环境
[root@localhost Desktop]# nmcli connection delete eth0 删除eth0
[root@localhost Desktop]# nmcli connection delete eth1 删除eth1
[root@localhost Desktop]# nmcli connection add con-name team0 ifname team0 type team config '{"runner":{"name":"activebackup"}}' 添加team接口
Connection 'team0' (826f5c34-ffdd-4c61-9723-7e1c1b831357) successfully added.
[root@localhost Desktop]# ifconfig 查看team接口已经添加成功
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a3:bd:a3 txqueuelen 1000 (Ethernet)
RX packets 8471 bytes 628512 (613.7 KiB)
RX errors 0 dropped 3494 overruns 0 frame 0
TX packets 158 bytes 16489 (16.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:af:54:5f txqueuelen 1000 (Ethernet)
RX packets 9659 bytes 749027 (731.4 KiB)
RX errors 0 dropped 270 overruns 0 frame 0
TX packets 1642 bytes 176497 (172.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 41 bytes 3960 (3.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 41 bytes 3960 (3.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
team0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 4a:15:d5:09:87:2f txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost Desktop]# nmcli connection add con-name eth0 ifname eth0 type team-slave master team0 添加eth0
Connection 'eth0' (600f4215-9c67-4412-874d-54a57611cdbb) successfully added.
[root@localhost Desktop]# nmcli connection add con-name eth1 ifname eth1 type team-slave master team0 添加eth1
Connection 'eth1' (2232066a-715b-4a31-8db2-7a1325c3fa8e) successfully added.
[root@localhost Desktop]# ifconfig eth0 down 将eth0关闭,则eth1会出来顶替eth0
[root@localhost Desktop]# ifconfig eth0 up 将eth0打开,则eth0会作为备份在eth1坏掉的时候出来工作
删除bond0接口以及两块网卡,添加team0接口:
用ifconfig查看team0接口已经添加成功:
添加两块网卡:
测试eth0坏掉的情况,通过监控查看:
[root@localhost ~]# teamdctl team0 stat 查看team0的状态
setup:
runner: activebackup
runner:
active port:
[root@localhost ~]# watch -n 1 teamdctl team0 stat 监控team0接口
监控所示,网卡已经添加成功,并且eth0不能工作的时候eth1出来顶替工作,当eth0好了之后进行闲置,如遇网卡坏掉则立即出来顶替工作。
网桥将两个相似的网络连接起来,并对网络数据的流通进行管理。它工作于数据链层,不但能扩展网络的距离或范围,而且可提高网络的性能、可靠性和安全性。网络1 和网络2 通过网桥连接后,网桥接收网络1 发送的数据包,检查数据包中的地址,如果地址属于网络1 ,它就将其放弃,相反,如果是网络2 的地址,它就继续发送给网络2.这样可利用网桥隔离信息,将同一个网络号划分成多个网段(属于同一个网络号),隔离出安全网段,防止其他网段内的用户非法访问。由于网络的分段,各网段相对独立(属于同一个网络号),一个网段的故障不会影响到另一个网段的运行。
[kiosk@foundation84 Desktop]$ su - 切换到超级用户
Password:
Last login: Mon May 21 17:41:22 CST 2018 on pts/0
[root@foundation84 ~]# cd /etc/sysconfig/network-scripts/
[root@foundation84 network-scripts]# ls
ifcfg-Auto_331 ifdown-ippp ifup-aliases ifup-routes
ifcfg-Auto_Auto-Go ifdown-ipv6 ifup-bnep ifup-sit
ifcfg-Auto_Ethernet ifdown-isdn ifup-eth ifup-Team
ifcfg-Auto_XUPT-ET ifdown-post ifup-ib ifup-TeamPort
ifcfg-br0 ifdown-ppp ifup-ippp ifup-tunnel
ifcfg-lo ifdown-routes ifup-ipv6 ifup-wireless
ifcfg-p4p2 ifdown-sit ifup-isdn init.ipv6-global
ifdown ifdown-Team ifup-plip keys-Auto_Auto-Go
ifdown-bnep ifdown-TeamPort ifup-plusb network-functions
ifdown-eth ifdown-tunnel ifup-post network-functions-ipv6
ifdown-ib ifup ifup-ppp
[root@foundation84 network-scripts]# mv ifcfg-br0 ifcfg-p4p2 /opt/
移动网卡到文件进行备份,之后好进行还原。这里的p4p2指自己的网卡名字,
每台主机的名字不同,我们可以通过命令nm-connection-editor来查看自己
的网卡名字,以防止环境搭建出现问题。
[root@foundation84 network-scripts]# ls 查看已经移动过去
ifcfg-Auto_331 ifdown-isdn ifup-eth ifup-Team
ifcfg-Auto_Auto-Go ifdown-post ifup-ib ifup-TeamPort
ifcfg-Auto_Ethernet ifdown-ppp ifup-ippp ifup-tunnel
ifcfg-Auto_XUPT-ET ifdown-routes ifup-ipv6 ifup-wireless
ifcfg-lo ifdown-sit ifup-isdn init.ipv6-global
ifdown ifdown-Team ifup-plip keys-Auto_Auto-Go
ifdown-bnep ifdown-TeamPort ifup-plusb network-functions
ifdown-eth ifdown-tunnel ifup-post network-functions-ipv6
ifdown-ib ifup ifup-ppp
ifdown-ippp ifup-aliases ifup-routes
ifdown-ipv6 ifup-bnep ifup-sit
[root@foundation84 network-scripts]# nm-connection-editor
删除其余的网络配置设置自己的IP
将多余的网络配置移除,如下图所示:
添加自己的IP:
这里我们就可以看到自己的网卡是p4p2:
设定主机IP:
操作展示:
[root@foundation84 network-scripts]# ifconfig 查看IP已经配置成功
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 148638 bytes 51428170 (49.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 148638 bytes 51428170 (49.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
p4p2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.25.254.84 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::9a40:bbff:fe25:7323 prefixlen 64 scopeid 0x20
ether 98:40:bb:25:73:23 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:e6:ea:d7 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp0s20f0u2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 70:f1:1c:0c:24:6b txqueuelen 1000 (Ethernet)
RX packets 67487 bytes 70740271 (67.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 38283 bytes 6400838 (6.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@foundation84 network-scripts]# virt-manager
打开虚拟机管理界面进行建立虚拟机,桥接没有的时候只有NTA方式来建立虚拟机。
[root@foundation84 network-scripts]# reboot 重启主机
[kiosk@foundation84 Desktop]$
[kiosk@foundation84 Desktop]$ su - 切换到超级用户
Password:
Last login: Mon May 21 17:53:31 CST 2018 on pts/0
ABRT has detected 1 problem(s). For more info run: abrt-cli list --since 1526896411
[root@foundation84 ~]# brctl show 显示网桥
bridge name bridge id STP enabled interfaces
virbr0 8000.525400e6ead7 yes virbr0-nic
[root@foundation84 ~]# cd /etc/sysconfig/network-scripts/
[root@foundation84 network-scripts]# ls
ifcfg-lo ifdown-ppp ifup-ib ifup-Team
ifcfg-p4p2 ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[root@foundation84 network-scripts]# vim ifcfg-p4p2 搭建网桥
文件内容:
DEVICE=p4p2
ONBOOT=yes
BOOTPROTO=none
BRIDGR=br0
[root@foundation84 network-scripts]# vim ifcfg-br0
文件内容:
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.84
NETMASK=255.255.255.0
TYPE=Bridge
[root@foundation84 network-scripts]# systemctl stop NetworkManager.service 关闭网络管理服务
[root@foundation84 network-scripts]# systemctl restart network 重启网络
[root@foundation84 network-scripts]# brctl show 显示网桥已经桥接成功
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
virbr0 8000.525400e6ead7 yes virbr0-nic
[root@foundation84 network-scripts]# virt-manager 打开虚拟机管理界面,就会出来用桥接的方式来建立虚拟机。
brctl 桥接管理命令
brctl show 显示
brctl addbr 添加网桥
brctl delbr 删除网桥
brctl addif 添加网桥连接
brctl delif 删除网桥连接
[root@localhost Desktop]# brctl show 显示网桥
bridge name bridge id STP enabled interfaces
[root@localhost Desktop]# nmcli connection delete eth0 删除eth0
[root@localhost Desktop]# nmcli connection delete eth1 删除eth1
[root@localhost Desktop]# nmcli connection delete team0 删除team接口
[root@localhost Desktop]# brctl show
bridge name bridge id STP enabled interfaces
[root@localhost Desktop]# brctl addbr br0 添加br0网桥
[root@localhost Desktop]# brctl show 显示网桥
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
[root@localhost Desktop]# ifconfig br0网桥已经添加成功
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::184a:deff:fe3e:83a9 prefixlen 64 scopeid 0x20
ether 1a:4a:de:3e:83:a9 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a3:bd:a3 txqueuelen 1000 (Ethernet)
RX packets 1043 bytes 81899 (79.9 KiB)
RX errors 0 dropped 2 overruns 0 frame 0
TX packets 91 bytes 9817 (9.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:af:54:5f txqueuelen 1000 (Ethernet)
RX packets 1123 bytes 90144 (88.0 KiB)
RX errors 0 dropped 792 overruns 0 frame 0
TX packets 3 bytes 182 (182.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 155 bytes 13424 (13.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 155 bytes 13424 (13.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost Desktop]# ifconfig br0 172.25.254.121/24添加IP地址
[root@localhost Desktop]# ifconfig br0 查看IP
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.121 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::184a:deff:fe3e:83a9 prefixlen 64 scopeid 0x20
ether 1a:4a:de:3e:83:a9 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26 bytes 3671 (3.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost Desktop]# ping 172.25.254.84 ping主机ping不通
PING 172.25.254.250 (172.25.254.250) 56(84) bytes of data.
From 172.25.254.121 icmp_seq=1 Destination Host Unreachable
From 172.25.254.121 icmp_seq=2 Destination Host Unreachable
[root@localhost Desktop]# brctl addif br0 eth0 添加网桥连接
[root@localhost Desktop]# brctl show 已经出现eth0
bridge name bridge id STP enabled interfaces
br0 8000.525400a3bda3 no eth0
[root@localhost Desktop]# ping 172.25.254.84 可以ping通
PING 172.25.254.250 (172.25.254.250) 56(84) bytes of data.
64 bytes from 172.25.254.250: icmp_seq=1 ttl=64 time=0.939 ms
[root@localhost Desktop]# brctl delif br0 eth0 删除网桥连接
[root@localhost Desktop]# brctl show eth0已经被删除
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
[root@localhost Desktop]# ifconfig br0 down 将br0变为关闭状态
[root@localhost Desktop]# ifconfig 查看IP时br0已经被删除
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:a3:bd:a3 txqueuelen 1000 (Ethernet)
RX packets 1743 bytes 136958 (133.7 KiB)
RX errors 0 dropped 2 overruns 0 frame 0
TX packets 98 bytes 10433 (10.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:af:54:5f txqueuelen 1000 (Ethernet)
RX packets 1818 bytes 144733 (141.3 KiB)
RX errors 0 dropped 792 overruns 0 frame 0
TX packets 3 bytes 182 (182.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 420 bytes 36192 (35.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 420 bytes 36192 (35.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost Desktop]# brctl delbr br0 删除网桥
[root@localhost Desktop]# brctl show 显示网桥时发现已经被还原
bridge name bridge id STP enabled interfaces