centos7服务器进行双网卡绑定
配置文件
#cat ifcfg-em1 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes NAME=em1 DEVICE=em1 ONBOOT=yes MASTER=bond0 SLAVE=yes # cat ifcfg-em2 TYPE=Ethernet BOOTPROTO=none IPV4_FAILURE_FATAL=no NAME=em2 ONBOOT=yes MASTER=bond0 SLAVE=yes # cat ifcfg-bond0 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no NAME=bond0 DEVICE=bond0 ONBOOT=yes DNS1=223.5.5.5 IPADDR=*.*.*.* PREFIX=24 GATEWAY=*.*.*.* # cat /etc/modprobe.d/bond0.conf alias bond0 bonding options bond0 miimon=100 mode=1 重启网卡发现配置没生效。 查看message日志 Aug 31 21:54:24 localhost systemd: Stopping LSB: Bring up/down networking... Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.0955] ifcfg-rh: update /etc/sysconfig/network-scripts/ifcfg-em1 (1dad842d-1912-ef5a-a43a-bc238fb267e7,"em1") Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.2204] device (em1): state change: activated -> deactivating (reason ‘user-requested‘) [100 110 39] Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.2206] manager: NetworkManager state is now DISCONNECTING Aug 31 21:54:25 localhost dbus[1114]: [system] Activating via systemd: service name=‘org.freedesktop.nm_dispatcher‘ unit=‘dbus-org.freedesktop.nm-dispatcher.service‘ Aug 31 21:54:25 localhost dbus-daemon: dbus[1114]: [system] Activating via systemd: service name=‘org.freedesktop.nm_dispatcher‘ unit=‘dbus-org.freedesktop.nm-dispatcher.service‘ Aug 31 21:54:25 localhost systemd: Starting Network Manager Script Dispatcher Service... Aug 31 21:54:25 localhost dbus[1114]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher‘ Aug 31 21:54:25 localhost dbus-daemon: dbus[1114]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher‘ Aug 31 21:54:25 localhost nm-dispatcher: req:1 ‘connectivity-change‘: new request (2 scripts) Aug 31 21:54:25 localhost systemd: Started Network Manager Script Dispatcher Service. Aug 31 21:54:25 localhost nm-dispatcher: req:1 ‘connectivity-change‘: start running ordered scripts... Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.2323] audit: op="device-disconnect" interface="em1" ifindex=2 pid=14176 uid=0 result="success" Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.2333] device (em1): state change: deactivating -> disconnected (reason ‘user-requested‘) [110 30 39] Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.2449] manager: NetworkManager state is now DISCONNECTED Aug 31 21:54:25 localhost nm-dispatcher: req:2 ‘down‘ [em1]: new request (2 scripts) Aug 31 21:54:25 localhost nm-dispatcher: req:2 ‘down‘ [em1]: start running ordered scripts... Aug 31 21:54:25 localhost network: Shutting down interface em1: Device ‘em1‘ successfully disconnected. Aug 31 21:54:25 localhost network: [ OK ] Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.3211] ifcfg-rh: update /etc/sysconfig/network-scripts/ifcfg-em2 (0578038a-64e9-a2fd-0a28-e4cd0b553930,"em2") Aug 31 21:54:25 localhost NetworkManager[1115]: <info> [1504187665.3220] policy: auto-activating connection ‘em2‘ Aug 31 21:54:25 localhost network: Shutting down interface em2: ERROR : [ipv6_test_device_status] Missing parameter ‘device‘ (arg 1) Aug 31 21:54:25 localhost ipv6_test_device_status: Missing parameter ‘device‘ (arg 1) Aug 31 21:54:25 localhost network: /etc/sysconfig/network-scripts/ifdown-eth: line 121: /sys/class/net/bond0/bonding/slaves: No such file or directory Aug 31 21:54:25 localhost network: [ OK ] Aug 31 21:54:26 localhost network: Shutting down interface em3: [ OK ] Aug 31 21:54:26 localhost network: Shutting down interface em4: [ OK ] Aug 31 21:54:26 localhost network: Shutting down loopback interface: [ OK ] Aug 31 21:54:26 localhost systemd: Starting LSB: Bring up/down networking... Aug 31 21:54:26 localhost NetworkManager[1115]: <info> [1504187666.6322] ifcfg-rh: new connection /etc/sysconfig/network-scripts/ifcfg-bond0 (ad33d8b0-1f7b-cab9-9447-ba07f855b143,"bond0") Aug 31 21:54:26 localhost NetworkManager[1115]: <info> [1504187666.6327] policy: auto-activating connection ‘em2‘ Aug 31 21:54:26 localhost NetworkManager[1115]: <info> [1504187666.7241] device (lo): link connected Aug 31 21:54:26 localhost network: Bringing up loopback interface: [ OK ] Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.0860] policy: auto-activating connection ‘em2‘ Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.0871] audit: op="connection-activate" uuid="ad33d8b0-1f7b-cab9-9447-ba07f855b143" name="bond0" result="fail" reason="No suitable device found for this connection." Aug 31 21:54:27 localhost network: Bringing up interface bond0: Error: Connection activation failed: No suitable device found for this connection. Aug 31 21:54:27 localhost network: [FAILED] Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.2963] policy: auto-activating connection ‘em2‘ Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.2976] audit: op="connection-activate" uuid="1dad842d-1912-ef5a-a43a-bc238fb267e7" name="em1" pid=14650 uid=0 result="fail" reason="Can not find a master for em1: Master connection not found or invalid" Aug 31 21:54:27 localhost network: Bringing up interface em1: Error: Connection activation failed: Can not find a master for em1: Master connection not found or invalid Aug 31 21:54:27 localhost network: [FAILED] Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.4642] policy: auto-activating connection ‘em2‘ Aug 31 21:54:27 localhost NetworkManager[1115]: <info> [1504187667.4655] audit: op="connection-activate" uuid="0578038a-64e9-a2fd-0a28-e4cd0b553930" name="em2" pid=14682 uid=0 result="fail" reason="Can not find a master for em2: Master connection not found or invalid" Aug 31 21:54:27 localhost network: Bringing up interface em2: Error: Connection activation failed: Can not find a master for em2: Master connection not found or invalid Aug 31 21:54:27 localhost network: [FAILED] Aug 31 21:54:27 localhost systemd: network.service: control process exited, code=exited status=1 Aug 31 21:54:27 localhost systemd: Failed to start LSB: Bring up/down networking. Aug 31 21:54:27 localhost systemd: Unit network.service entered failed state. Aug 31 21:54:27 localhost systemd: network.service failed. NetworkManager不识别 bond0设备 关闭NetworkManager以后,重启网络服务 Aug 31 21:57:47 localhost systemd: Stopped Network Manager Wait Online. Aug 31 21:57:47 localhost NetworkManager[1115]: <info> [1504187867.5810] caught SIGTERM, shutting down normally. Aug 31 21:57:47 localhost systemd: Stopping Network Manager Wait Online... Aug 31 21:57:47 localhost systemd: Stopping Network Manager... Aug 31 21:57:47 localhost NetworkManager[1115]: <info> [1504187867.6005] exiting (success) Aug 31 21:57:47 localhost systemd: Stopped Network Manager. Aug 31 21:57:58 localhost systemd: Reloading. Aug 31 21:58:06 localhost systemd: Starting LSB: Bring up/down networking... Aug 31 21:58:06 localhost network: Bringing up loopback interface: [ OK ] Aug 31 21:58:06 localhost kernel: Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Aug 31 21:58:06 localhost kernel: MII link monitoring set to 100 ms Aug 31 21:58:07 localhost kernel: IPv6: ADDRCONF(NETDEV_UP): bond0: link is not ready Aug 31 21:58:07 localhost kernel: bond0: Adding slave em1 Aug 31 21:58:07 localhost kernel: bond0: Enslaving em1 as a backup interface with a down link Aug 31 21:58:07 localhost network: Bringing up interface bond0: ERROR : [/etc/sysconfig/network-scripts/ifup-eth] Device does not seem to be present, delaying initialization. Aug 31 21:58:07 localhost /etc/sysconfig/network-scripts/ifup-eth: Device does not seem to be present, delaying initialization. Aug 31 21:58:07 localhost network: WARN : [/etc/sysconfig/network-scripts/ifup-eth] Unable to start slave device ifcfg-em2 for master bond0. Aug 31 21:58:07 localhost /etc/sysconfig/network-scripts/ifup-eth: Unable to start slave device ifcfg-em2 for master bond0. Aug 31 21:58:07 localhost kernel: IPv6: ADDRCONF(NETDEV_UP): bond0: link is not ready Aug 31 21:58:10 localhost kernel: tg3 0000:01:00.0 em1: Link is up at 1000 Mbps, full duplex Aug 31 21:58:10 localhost kernel: tg3 0000:01:00.0 em1: Flow control is off for TX and off for RX Aug 31 21:58:10 localhost kernel: tg3 0000:01:00.0 em1: EEE is disabled Aug 31 21:58:10 localhost kernel: bond0: link status definitely up for interface em1, 1000 Mbps full duplex Aug 31 21:58:10 localhost kernel: bond0: making interface em1 the new active one Aug 31 21:58:10 localhost kernel: bond0: first active interface up! 正常绑定,服务启动 ########################## 下面是网络摘取的文档内容 http://www.cnblogs.com/zhangjianghua/p/6179136.html Bonding的模式一共有7种: mode=0(balance-rr)(平衡抡循环策略) 链路负载均衡,增加带宽,支持容错,一条链路故障会自动切换正常链路。交换机需要配置聚合口,思科叫port channel。 特点:传输数据包顺序是依次传输(即:第1个包走eth0,下一个包就走eth1….一直循环下去,直到最后一个传输完毕),此模式提供负载平衡和容错能力;但是我们知道如果一个连接 或者会话的数据包从不同的接口发出的话,中途再经过不同的链路,在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要重新要求被发送,这样网络的吞吐量就会下降 mode=1(active-backup)(主-备份策略) 这个是主备模式,只有一块网卡是active,另一块是备用的standby,所有流量都在active链路上处理,交换机配置的是捆绑的话将不能工作,因为交换机往两块网卡发包,有一半包是丢弃的。 特点:只有一个设备处于活动状态,当一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得,从外面看来,bond的MAC地址是唯一的,以避免switch(交换机)发生混乱。 此模式只提供了容错能力;由此可见此算法的优点是可以提供高网络连接的可用性,但是它的资源利用率较低,只有一个接口处于工作状态,在有 N 个网络接口的情况下,资源利用率为1/N mode=2(balance-xor)(平衡策略) 表示XOR Hash负载分担,和交换机的聚合强制不协商方式配合。(需要xmit_hash_policy,需要交换机配置port channel) 特点:基于指定的传输HASH策略传输数据包。缺省的策略是:(源MAC地址 XOR 目标MAC地址) % slave数量。其他的传输策略可以通过xmit_hash_policy选项指定,此模式提供负载平衡和容错能力 mode=3(broadcast)(广播策略) 表示所有包从所有网络接口发出,这个不均衡,只有冗余机制,但过于浪费资源。此模式适用于金融行业,因为他们需要高可靠性的网络,不允许出现任何问题。需要和交换机的聚合强制不协商方式配合。 特点:在每个slave接口上传输每个数据包,此模式提供了容错能力 mode=4(802.3ad)(IEEE 802.3ad 动态链接聚合) 表示支持802.3ad协议,和交换机的聚合LACP方式配合(需要xmit_hash_policy).标准要求所有设备在聚合操作时,要在同样的速率和双工模式,而且,和除了balance-rr模式外的其它bonding负载均衡模式一样,任何连接都不能使用多于一个接口的带宽。 特点:创建一个聚合组,它们共享同样的速率和双工设定。根据802.3ad规范将多个slave工作在同一个激活的聚合体下。 外出流量的slave选举是基于传输hash策略,该策略可以通过xmit_hash_policy选项从缺省的XOR策略改变到其他策略。需要注意的 是,并不是所有的传输策略都是802.3ad适应的, 尤其考虑到在802.3ad标准43.2.4章节提及的包乱序问题。不同的实现可能会有不同的适应 性。 必要条件: 条件1:ethtool支持获取每个slave的速率和双工设定 条件2:switch(交换机)支持IEEE 802.3ad Dynamic link aggregation 条件3:大多数switch(交换机)需要经过特定配置才能支持802.3ad模式 mode=5(balance-tlb)(适配器传输负载均衡) 是根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave。该模式要求slave接口的网络设备驱动有某种ethtool支持;而且ARP监控不可用。 特点:不需要任何特别的switch(交换机)支持的通道bonding。在每个slave上根据当前的负载(根据速度计算)分配外出流量。如果正在接受数据的slave出故障了,另一个slave接管失败的slave的MAC地址。 必要条件: ethtool支持获取每个slave的速率 mode=6(balance-alb)(适配器适应性负载均衡) 在5的tlb基础上增加了rlb(接收负载均衡receive load balance).不需要任何switch(交换机)的支持。接收负载均衡是通过ARP协商实现的. 特点:该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receive load balance, rlb),而且不需要任何switch(交换机)的支持。接收负载均衡是通过ARP协商实现的。bonding驱动截获本机发送的ARP应答,并把源硬件地址改写为bond中某个slave的唯一硬件地址,从而使得不同的对端使用不同的硬件地址进行通信。 来自服务器端的接收流量也会被均衡。当本机发送ARP请求时,bonding驱动把对端的IP信息从ARP包中复制并保存下来。当ARP应答从对端到达 时,bonding驱动把它的硬件地址提取出来,并发起一个ARP应答给bond中的某个slave。 使用ARP协商进行负载均衡的一个问题是:每次广播 ARP请求时都会使用bond的硬件地址,因此对端学习到这个硬件地址后,接收流量将会全部流向当前的slave。这个问题可以通过给所有的对端发送更新 (ARP应答)来解决,应答中包含他们独一无二的硬件地址,从而导致流量重新分布。 当新的slave加入到bond中时,或者某个未激活的slave重新 激活时,接收流量也要重新分布。接收的负载被顺序地分布(round robin)在bond中最高速的slave上 当某个链路被重新接上,或者一个新的slave加入到bond中,接收流量在所有当前激活的slave中全部重新分配,通过使用指定的MAC地址给每个 client发起ARP应答。下面介绍的updelay参数必须被设置为某个大于等于switch(交换机)转发延时的值,从而保证发往对端的ARP应答 不会被switch(交换机)阻截。 必要条件: 条件1:ethtool支持获取每个slave的速率; 条件2:底层驱动支持设置某个设备的硬件地址,从而使得总是有个slave(curr_active_slave)使用bond的硬件地址,同时保证每个bond 中的slave都有一个唯一的硬件地址。如果curr_active_slave出故障,它的硬件地址将会被新选出来的 curr_active_slave接管 其实mod=6与mod=0的区别:mod=6,先把eth0流量占满,再占eth1,….ethX;而mod=0的话,会发现2个口的流量都很稳定,基本一样的带宽。而mod=6,会发现第一个口流量很高,第2个口只占了小部分流量。 mode5和mode6不需要交换机端的设置,网卡能自动聚合。mode4需要支持802.3ad。mode0,mode2和mode3理论上需要静态聚合方式。 但实测中mode0可以通过mac地址欺骗的方式在交换机不设置的情况下不太均衡地进行接收。
本文出自 “运维笔记” 博客,请务必保留此出处http://phospherus.blog.51cto.com/7824598/1961795
原文地址:http://phospherus.blog.51cto.com/7824598/1961795