MENU

H3C 交换机链路聚合与服务器 bond0 负载均衡设置

January 3, 2018 • Read: 4575 • 17年实战

配置 bond0 上联网络设备也需要做捆绑,如果是冗余的 bond 则上联不用配置

H3Cs5560 交换机

interface Bridge-Aggregation 1
port access vlan 10

创建聚合口,划入vlan

int g 1/0/1

port link-aggregation group 1

聚合的两个物理口都加入集合组

int g 2/0/1

port link-aggregation g 1

服务器

bond0 配置cat ifcfg-bond0

DEVICE=bond0
BOOTPROTO=static
IPADDR=10.0.0.126
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
ONBOOT=yes
USERCTL=no
TYPE=Ethernet

eth1,2... 配置cat ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes

配置文件开机启用 bond0

vim /etc/modprobe.d/openfwwf.conf

alias bond0 bonding
options bond0 miimon=1000 mode=0

命令方式启用 bond0 模块

insmod /lib/modules/uname -r/kernel/drivers/net/bonding/bonding.ko miimon=1000 mode=0

其他配置
删除模块命令

rmmod /lib/modules/uname -r/kernel/drivers/net/bonding/bonding.ko miimon=1000 mode=0

license 原因 bond 指定配置文件 mac 地址MACADDR=mac地址
查看状态

cat /proc/net/bonding/bond*
# 查看 bond 状态
ethtool bond0| grep -i speed
# 查看网卡速率如:Speed: 2000Mb/s
display link-aggregation verbose | include /0/2
#Status 状态为 ‘S’

配置脚本. py

#!/usr/bin/env python
# -- coding: utf-8 --
# --------------------------------------------------
#Author:        LJ
#Email:         admin@attacker.club
#Site:          blog.attacker.club

#Site:blog.attacker.club  Mail:admin@attacker.club
#Date:2017-09-05 21:28:39 Last:2017-09-09 14:07:11
#Description:   
# --------------------------------------------------

import  sys,os,re
ip = "192.168.16.25"
netmask = "255.255.254.0"
gateway = "192.168.16.1"
bond = "0"

def warn (Text):
    print ">>>>>t033[1;31m%s033[0mt<<<<<" % Text
def info (Text):
    print ">>>>>t033[1;33m%s033[0mt<<<<<" % Text
#提示

def shell(cmd):
    os.system(cmd)

def shellinfo(cmd):
    r=os.popen(cmd)
    text=r.read()
    r.close()
    return text

#shell
def file(path,method,content):
    f=open(path,method)
    f.write(content)
    f.close()
#file




if name == "__main__":
    ethx_info = shellinfo("ip add |grep ^2|awk '{print $2}'")
    eth0 = (re.match('w+d',ethx_info).group())
    ethx_info = shellinfo("ip add |grep ^3|awk '{print $2}'")
    eth1 = (re.match('w+d',ethx_info).group())
    file('/etc/sysconfig/network-scripts/ifcfg-%s' % eth0,'w',
     '''DEVICE=%s
     BOOTPROTO=none
     ONBOOT=yes
     USERCTL=no
     MASTER=bond0
     SLAVE=yes
     ''' % (eth0))
    file('/etc/sysconfig/network-scripts/ifcfg-%s' % eth1,'w',
     '''DEVICE=%s
     BOOTPROTO=none
     ONBOOT=yes
     USERCTL=no
     MASTER=bond0
     SLAVE=yes
     ''' % (eth1))
    file('/etc/sysconfig/network-scripts/ifcfg-bond0','w',
     '''DEVICE=bond0
     BOOTPROTO=static
     IPADDR=%s
     NETMASK=%s
     GATEWAY=%s
     ONBOOT=yes
     USERCTL=no
     TYPE=Ethernet
     ''' % (ip,netmask,gateway))
    file('/etc/modprobe.d/bond.conf','w',
     '''
     alias bond bonding
     options bond0 miimon=1000 mode=%s
     '''% (bond)
    info('配置文件修改完毕')
    info('本机地址:%s' % ip)
    warn('重启网卡中。。。')
    shell( 'service network restart')

兼总条贯 知至知终

无标签
最后编辑于: March 26, 2018