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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| 1、创建bonding的配置文件 sudo vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 BONDING_MASTER=yes IPADDR=192.168.1.22 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 ONBOOT=yes BOOTPROTO=none BONDING_OPTS="mode=active-backup miimon=100 primary=ens160"
> > > >
2、修改网卡的配置文件
ens160设置: sudo vim /etc/sysconfig/network-scripts/ifcfg-ens160 ---------------------------------------------------- DEVICE="ens160" ONBOOT="yes" BOOTPROTO="none" MASTER="bond0" SLAVE="yes" ----------------------------------------------------
ens256设置: sudo vim /etc/sysconfig/network-scripts/ifcfg-ens256 ---------------------------------------------------- DEVICE="ens256" ONBOOT="yes" BOOTPROTO="none" MASTER="bond0" SLAVE="yes" -----------------------------------------------------
3、重启网络管理服务 systemctl restart network
4、查看地址:ip a - 发现ens160和ens256网卡ip都没了(这样才是正常的) - 多出了一个 bond0 ------------------------------------------------------------------------------------------------------------------- [root@k8s-loadbalancer2 ~] 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens160: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000 link/ether 00:0c:29:09:66:8f brd ff:ff:ff:ff:ff:ff 3: ens256: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000 link/ether 00:0c:29:09:66:8f brd ff:ff:ff:ff:ff:ff 4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:0c:29:09:66:8f brd ff:ff:ff:ff:ff:ff inet 192.168.1.22/24 brd 192.168.1.255 scope global noprefixroute bond0 valid_lft forever preferred_lft forever ----------------------------------------------------------------------------------------------------------------------------------
5、查看bond0的详细信息: - cat /proc/net/bonding/bond0 - Primary Slave 指网卡正常时由ens160来当主 - MII Status: up 说明网卡正常 -------------------------------------------------------------------------- [root@k8s-loadbalancer2 ~] Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup) Primary Slave: ens160 (primary_reselect always) Currently Active Slave: ens160 MII Status: up MII Polling Interval (ms): 50 Up Delay (ms): 0 Down Delay (ms): 0
Slave Interface: ens256 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:09:66:99 Slave queue ID: 0
Slave Interface: ens160 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:09:66:8f Slave queue ID: 0 ----------------------------------------------------------------
6、测试 - 此时当执行:ifdown ens160 时,ens256会接管ip(192.168.1.22) - 查看:/proc/net/bonding/bond0 - 此时是ens256来接管工作的 - 再执行 ifup ens160 再查看,发现此时是ens160来接管ip工作了 ---------------------------------------------------------------
[root@k8s-loadbalancer2 ~] Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: ens256 MII Status: up MII Polling Interval (ms): 50 Up Delay (ms): 0 Down Delay (ms): 0
Slave Interface: ens256 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:09:66:99 Slave queue ID: 0 -------------------------------------------------------------------
|