centos7实现双网卡绑定
一、修改网卡为统一eth
1.1.修改grub配置文件
vim /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos_rd-nfs-01/root rd.lvm.lv=centos_rd-nfs-01/swap biosdevname=0 net.ifnames=0 rhgb quiet"
1.2.修改网卡配置文件
/etc/sysconfig/network-scripts
cp ifcfg-p3p1 ifcfg-p3p1.bak
mv ifcfg-p3p1 ifcfg-eth4
我之前没有添加mac地址,导致老是不生效或者
根据Centos 官方WIKI的FAQ中得知,如果你有多个接口,并且想要控制其设备名,而不是让内核以它自己的方式命名,创建,/etc/udev/rules.d/XXX-net.rules规则是必要的!那么这里我们也创建好规则吧
vim /etc/udev/rules.d/70-persistent-net.rules
SUBSYTEM=="net",ACTION=="add",DRIVERS=="?**",ATTP{address}=="00:50:56:99:c3:42",ATTR {type} =="1".KERNEL=="eth*",NAME="eth0"
1.3.更新内核
grub2-mkconfig -o /boot/grub2/grub.cfg
只要做完这步,然后重新启动 Linux 操作系统,通过 ip addr 可以看到网卡名称已经变为 eth0 ,网络能正常使用
1.4.重启系统
reboot
二、bonding模式下双网卡绑定
2.2.查看系统内核是否支持bonding
[root@node1 ~]# cat /boot/config-3.10.0-957.el7.x86_64 |grep -i bonding
CONFIG_BONDING=m
2.2.备份网卡配置,并创建bond0网卡文件
[root@node1 network-scripts]# cp -a ifcfg-eth4 ifcfg-eth4.bak
[root@node1 network-scripts]# cp -a ifcfg-eth5 ifcfg-eth5.bak
[root@node1 network-scripts]# cp -a ifcfg-eth4.bak ifcfg-bond0
2.3.修改网卡配置文件
[root@node1 network-scripts]# cat ifcfg-eth4
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
HWADDR=b4:96:91:47:12:70
NAME=eth4
DEVICE=eth4
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
[root@node1 network-scripts]# cat ifcfg-eth5
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
HWADDR=b4:96:91:47:12:72
NAME=eth5
DEVICE=eth5
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
[root@node1 network-scripts]# cat ifcfg-bond0
TYPE=Bond
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
DEVICE=bond0
ONBOOT=yes
IPADDR=192.168.135.46
PREFIX=24
GATEWAY=192.168.135.1
DNS1=172.21.128.3
DNS2=172.21.128.2
DOMAIN=onepluscorp.cn
IPV6_PRIVACY=no
USERCTL=no
2.4.将eth4、eth5网卡合并显示
[root@RD-NFS-01 network-scripts]# paste ifcfg-eth4 ifcfg-eth5
TYPE=Ethernet TYPE=Ethernet
PROXY_METHOD=none PROXY_METHOD=none
BROWSER_ONLY=no BROWSER_ONLY=no
BOOTPROTO=none BOOTPROTO=none
DEFROUTE=yes DEFROUTE=yes
IPV4_FAILURE_FATAL=no IPV4_FAILURE_FATAL=no
IPV6INIT=yes IPV6INIT=yes
IPV6_AUTOCONF=yes IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy IPV6_ADDR_GEN_MODE=stable-privacy
HWADDR=b4:96:91:47:12:70 HWADDR=b4:96:91:47:12:72
NAME=eth4 NAME=eth5
DEVICE=eth4 DEVICE=eth5
ONBOOT=yes ONBOOT=yes
USERCTL=no USERCTL=no
MASTER=bond0 MASTER=bond0
SLAVE=yes SLAVE=yes
2.5.对比配置文件不同内容
[root@RD-NFS-01 network-scripts]# diff ifcfg-eth4 ifcfg-eth5
12,14c12,14
< HWADDR=b4:96:91:47:12:70
< NAME=eth4
< DEVICE=eth4
---
> HWADDR=b4:96:91:47:12:72
> NAME=eth5
> DEVICE=eth5
2.6.创建bonding.conf(网卡绑定模式)配置文件
[root@node1 network-scripts]# echo -e "alias bond0 bonding
options bond0 mode=6 miimon=100" >> /etc/modprobe.d/bonding.conf
[root@node1 network-scripts]# cat /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 mode=6 miimon=100
注意:
#mode=6代表负载均衡;两块网卡同时工作,增加网络带宽,不需要依赖物理交换机设置
#mode=1代表主备切换;只有一块网卡处于活动状态,活动网卡故障切换到备用网卡
#miimon=100代表网络链路检测频率100ms检查一次,如果出现问题则切换到备用网卡
2.7.加载bonding模块
[root@node1 network-scripts]# modprobe bonding
#验证bonding模块是否加载成功,出现如下结果则证明加载成功
[root@node1 network-scripts]# lsmod | grep bonding
bonding 152656 0
2.8.重启网络
[root@node1 network-scripts]# systemctl restart network
2.9.查看网卡绑定的模式以及绑定的网卡状态信息
[root@RD-NFS-01 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth4
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: b4:96:91:47:12:70
Slave queue ID: 0
Slave Interface: eth5
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: b4:96:91:47:12:72
Slave queue ID: 0
2.10.网卡验证
ifconfig
#出现bond0并且网络正常即可