Linux双网卡绑定实现高可用

看看一般情况下网卡基本配置是怎么样的?

使用DHCP自动获取IP:

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

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

NAME=eth0

TYPE=Ethernet

IPV6INIT=no

HWADDR=xx:xx:xx:xx:xx:xx

如果是手工配静态IP:

TYPE=Ethernet

BOOTPROTO=static

NAME=eth0

ONBOOT=yes

IPADDR=192.168.1.1

NETMASK=255.255.255.0

GATEWAY=192.168.1.254

DNS=192.168.100.1


配置双网卡高可用:

方法一:teaming

常用的两种策略:轮询式(roundrobin)的流量负载均衡;热备份(activebackup)连接冗余

①建立虚拟网卡team0   ,可参考 man teamd.conf

nmcli connection add  type team con-name team0  ifname team0 autoconnect yes  

config '{"runner": {"name": "activebackup"}}'

解析:nmcli connection  添加   类型  team 配置文件名 team0   网卡名  team0  开机自动启用

team的工作模式为热备份,若手误敲错,可将其删除 nmcli connection delete team0

②为team0添加两块真实网卡(team-slave)

nmcli connection add type team-slave  con-name team0-1 ifname  eth1  master team0

nmcli connection add type team-slave  con-name team0-2 ifname  eth2  master team0

nmcli con modify team0-1 connection.autoconnect yes

nmcli con modify team0-2 connection.autoconnect yes

若手误敲错,可将其删除 nmcli connection delete team0-1

③配值虚拟网卡team0的IP地址

nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect  yes

④激活网卡

nmcli connection up team0

nmcli connection up team0-1

nmcli connection up team0-2

⑤查看绑定状态

teamdctl team0 state

方法二:bonding

①网卡一配置文件内容:

TYPE=Ethernet

BOOTPROTO=none

ONBOOT=yes

USERCTL=no         

DEVICE=eth0

MASTER=bond0

SLAVE=yes

②网卡二配置文件内容:

TYPE=Ethernet

BOOTPROTO=none

ONBOOT=yes

USERCTL=no

DEVICE=eth1

MASTER=bond0

SLAVE=yes

③创建绑定网卡

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

TYPE=Ethernet

BOOTPROTO=none

ONBOOT=yes

USERCTL=no

DEVICE=bond0

IPADDR=192.168.1.1

PREFIX=24

NM_CONTROLLED=no

DNS=xxxx

GATEWAY=xxxx

BONDING_OPTS="mode=6 miimon=100"    ##等同于步骤⑤

④让内核支持网卡绑定驱动

modprobe --first-time bonding

lsmod |grep bonding

⑤创建一个网卡绑定内核驱动文件(若做了步骤③可省略此步)

vim /etc/modprobe.d/bond.conf

alias bond0 bonding

options bond0 miimon=100 mode=6

解析:定义网卡绑定为mode6平衡负载模式,且当出现故障时自动切换时间为100毫秒

常见的网卡绑定驱动模式有:

mode0平衡负载模式:平时两块网卡均工作,且自动备援,采用交换机设备支援。

mode1自动备援模式:平时只有一块网卡工作,故障后自动替换为另外的网卡。

mode6平衡负载模式:平时两块网卡均工作,且自动备援,无须交换机设备支援

⑥重启网络生效

systemctl restart network

⑦查看验证

 ifconfig  ; ip a s  ;

 cat /proc/net/bonding/bond0

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 多网卡同IP技术 将多个网卡端口绑定为一个,可以提升网络的性能。在linux系统上有两种技术可以实现,Linux ...
    geekdeedy阅读 10,593评论 0 4
  • CentOS 6之前,网络接口使用连续号码命名:eth0、eth1等,当 增加或删除网卡时,名称可能会发生变化 ...
    楠人帮阅读 800评论 0 0
  • centos6 主机名 /etc/sysconfig/network hostname redhat:当前生效 v...
    毛利卷卷发阅读 662评论 0 0
  • 采用传统的命名方式 vim /etc/default/grub 编辑此文件 运行此命令grub2-mkconfig...
    尘曦的雨阅读 510评论 0 0
  • hexdump -C 查看二进制文件 xxd:查看二进制文件 whatis 简单描述命令的用途whatis c...
    JevonWei阅读 860评论 0 0