linux网卡中onboot,Linux多网卡负载均衡 : bond

一、新建bond0虚拟设备

vi /etc/sysconfig/network-scripts/ifcfg-bond0

输入

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

NETWORK=192.168.1.0 #网段

NETMASK=255.255.255.0 # 掩码

IPADDR=192.168.1.2 # 指定IP

USERCTL=no

GATEWAY=192.168.1.1 # 网关

TYPE=Ethernet

二、修改所有真实网卡的配置

vi /etc/sysconfig/network-scripts/ifcfg-eth0

vi /etc/sysconfig/network-scripts/ifcfg-eth1

....

内容修改为:

DEVICE=eth0 # 这里填写对应的设备名称

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=yes

三、将bond0加入modprobe

vi /etc/modprobe.conf

加入

alias bond0 bonding

options bond0 miimon=100 mode=0

四、加入启动命令

vi /etc/rc.d/rc.local

加入

ifenslave bond0 eth0 eth1

其中eth0、eth1为真实网卡名称,按照实际情况填写

五、重启系统后即可启动负载均衡式的bond

第三步选项说明:

miimon=100

每100毫秒 (即0.1秒) 检查一次网络

mode=0

共有七种模式,常用的模式是0和1

mode=0 : 负载均衡模式,所有网卡一起使用,峰值=所有网卡带宽的总和,当某个网卡故障,仅降低带宽,不影响其他网卡

mode=1 : 热备模式,即一块网卡运行,其他待命,当运行的网卡故障,其他网卡顶上

mode英文解释:

mode=1(active-backup) Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor) XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3(broadcast) Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4(802.3ad) IEEE 802.3ad Dynamic link aggregation.

mode=5(balance-tlb) Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave. Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave.

mode=6(balance-alb) Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.

查看bond0状态:

cat /proc/net/bonding/bond0

若某个网卡的MII Status=down,表示该网卡无法连接网络

此时应检查:

1、网线是否插好

2、网线是否损坏

3、网卡配置是否正确

4、网卡是否没插好

5、网卡是否损坏

PS: 使用bond时,所有网卡接口都需用网线接上交换机和路由器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 系统bond0 是网络绑定设备,用于将多个物理网卡绑定为一个逻辑网卡,实现网络负载均衡和冗余备份等功能。mode=1 是其一种绑定模式,也称为“active-backup”模式,即活动备份模式,其只有一张物理网卡处于活动状态,其他网卡处于备份状态。当活动网卡出现故障时,备份网卡会立即接管其工作。 下面是在 CentOS 7 系统配置和启动 bond0 的 mode=1 模式的步骤: 1. 安装 bonding 模块 ``` sudo yum install -y bonding ``` 2. 编辑 /etc/modprobe.d/bonding.conf 文件,添加以下内容: ``` alias bond0 bonding options bond0 mode=1 miimon=100 ``` 其,mode=1 指定绑定模式为 active-backup,miimon=100 表示每隔 100 毫秒检查一次活动网卡状态。 3. 编辑 /etc/sysconfig/network-scripts/ifcfg-ethX 文件(X 表示对应的物理网卡编号),添加以下内容: ``` DEVICE=ethX BOOTPROTO=none ONBOOT=yes MASTER=bond0 SLAVE=yes ``` 其,MASTER=bond0 指定该网卡归属于 bond0 绑定设备,SLAVE=yes 表示该网卡为绑定设备的备份网卡。 4. 编辑 /etc/sysconfig/network-scripts/ifcfg-bond0 文件,添加以下内容: ``` DEVICE=bond0 BOOTPROTO=none ONBOOT=yes BONDING_OPTS="mode=1 miimon=100" ``` 其BONDING_OPTS="mode=1 miimon=100" 指定 bond0 绑定设备的模式和参数。 5. 启动网络服务,并重启 network 服务: ``` sudo systemctl start network sudo systemctl restart network ``` 6. 检查 bond0 绑定设备是否已启动: ``` sudo ifconfig bond0 ``` 如果显示了 bond0 设备及其 IP 地址等信息,则表示绑定设备已成功启动。 注意:以上步骤涉及到的文件和参数可能因系统版本和网卡型号而异,具体操作前请根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值