今天遇到需要 network bonding 的情况, 记录点从头使用 network bonding 的笔记吧.

network bond

init

  1. ############(deleted)
  2. Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  3. CentOS Linux release 7.3.1611 (Core)

config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
ls /etc/sysconfig/network-scripts/

cat <<'EOF' > /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
DEVICE=ens192
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF

cat << 'EOF' > /etc/sysconfig/network-scripts/ifcfg-ens224
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
DEVICE=ens224
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF

# 下面这里找一个没人用的 IP. PREFIX 和 NETMASK 有坑
# 这里叫 bond0 只是名字, 并不是它的 mode
cat << 'EOF' > /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=bond0
IPADDR=192.168.100.211
GATEWAY=192.168.1.1
NETMASK=255.255.0.0
PREFIX=16
NM_CONTROLLED=no
BONDING_MASTER=yes
EOF

# 这里会设置 mode. 共 7 种 mode
cat << 'EOF' > /etc/modprobe.d/bond.conf
alias bond0 binding
options bond0 miimon=100 mode=4
EOF

setup

centos7默认没有加bonding内核模板,加载方式modprobe –first-time bonding
查看是否加载成功 lsmod | grep bonding 或者 modinfo bonding
重启网络服务service network restart
可能会启动失败,bond0的状态不是UP, 查看/var/log/message可看到如下信息
Error: Connection activation failed: Master device bond0 unmanaged or not available for activation

1
2
3
4
5
6
7
8
# 安装 bonding mod
modprobe --first-time bonding
lsmod | grep bonding
# 禁用 NetworkManager 原因见上
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
# 重启 network
service network restart

参考

http://www.imooc.com/article/15741