zoukankan      html  css  js  c++  java
  • linux系统多网卡热备实现高并发负载均衡

    #nmcli实现bonding

    #先停止NetworkManager
    service NetworkManager stop
    chkconfig NetworkManager off   //开机自启动 关闭

    #虚拟主机网卡类型要一致选(桥接)模式:

    #添加bonding接口:
    nmcli con add type bond con-name mybond0 ifname bond0 mode active-backup
    #生成的配置文件路径:
    cd /etc/sysconfig/network-scripts
    #配置文件名称:
    ifcfg-mybond0
    #如果要设置静态IP地址,修改配置文件内:
    BOOTPROTO=dhcp             修改为:BOOTPROTO=static
                               新增静态ip地址:IPADDR=172.20.37.200
                               子网掩码:PREFIX=16
    #新增bond0的机制及模式(Mode 1 (active-backup): 活动-备份(主备)策略,只有一个slave被激活,当且仅当活动的slave接口失败时才会激活其他slave.为了避免交换机发生混乱此时绑定的MAC地址只有一个外部端口上可见)
    BONDING_OPTS="miimon=100 mode=1"

    #添加从属网卡接口(我的网卡端口名称为:ens33/ens34):
    nmcli con add type bond-slave ifname ens33 master bond0
    nmcli con add type bond-slave ifname ens34 master bond0
    #生成的配置文件路径:
    cd /etc/sysconfig/network-scripts
    #配置文件名称:
    ifcfg-bond-slave-ens33
    ifcfg-bond-slave-ens34

    #重新加载网卡:
    nmcli con reload

    #检查bond0的链接信息:
    nmcli con

    #如有多余链接端口(非bond0的从属接口,直接关闭):
        [root@localhost network-scripts 10:51:15]#nmcli con
        NAME              UUID                                  TYPE      DEVICE
        mybond0           e9660986-e80b-40b2-938b-2c0b1e093a8a  bond      bond0  
        virbr0            d172ee2f-c59c-4128-9867-ee7e8a2e60c8  bridge    virbr0
        bond-slave-ens33  c5330bec-dd78-4991-81ba-7ffbb8740493  ethernet  ens33  
        bond-slave-ens34  ec9a5f9e-d7b8-4411-b813-8d7a3c407282  ethernet  ens34  
        bond-slave-ens38  4aa576a2-aef3-4852-8e2d-a5876cfff407  ethernet  ens38  
        ens33             cda2e0f9-5936-4cf3-b32d-59846c30cbd5  ethernet  --     
        ens34             61294f12-63bb-45d0-8fc3-6c6a977e0777  ethernet  --  
        #例入:ens33、ens34及virbr0属于多余,直接down,命令:
        nmcli con down ens33
    #修改路径/etc/sysconfig/network-scripts/下的ens33和ens34的配置文件
    #ifcfg-ens33和ifcfg-ens34文件内开机自启参数的:
    ONBOOT="yes"  改修: ONBOOT="no"

    #启动绑定,先启动从属接口
    nmcli con up bond-slave-ens34
    nmcli con up bond-slave-ens33

    #启动绑定的mybond0
    nmcli con up mybond0

    #启动网络服务:

    centos6/7:service network restart

    centos8:systemctl restart NetworkManager



    #配置完成查看bondo参数:
    cat /proc/net/bonding/bond0

    #删除bond网络
        1.nmcli connection delete bond0   删除bond0
        2.nmcli connection delete eth0   删除eth0
        3.nmcli connection delete eth1  删除eth1
        4.rmmod bonding(很重要)
    #重启reboot



    方法二:
    在/etc/sysconfig/network-scripts/目录下建立ifcfg-bond0文件:
    DEVICE=bond0
    USERCTL=no
    BOOTPROTO=none
    ONBOOT=yes
    IPADDR=192.168.100.17    
    NETMASK=255.255.255.0
    GATEWAY=192.168.100.1
    TYPE=UnKnown    
    BONDING_OPTS="miimon=80 mode=0"   

    记得ifcfg-eth0和ifcfg-eth1文件记得备份出来,用于恢复:

    然后分别修改ifcfg-eth0文件,如下:
    DEVICE="eth0"
    ONBOOT="yes"
    BOOTPROTO=none:
    MASTER=bond0
    SLAVE=yes
    USERCTL=no
    在把ifcfg-eth1文件修改如下:
    DEVICE="eth1"
    ONBOOT="yes"
    BOOTPROTO=none
    MASTER=bond0
    SLAVE=yes
    USERCTL=no

    在/etc/modprobe.d/目录下建立bonding.conf文件,文件内容如下:
    alias bond0 bonding

    执行modprobe  bonding

    然后重启网络
    service network restart

    此命令查看绑定情况
    cat/proc/net/bonding/bond0

    网卡绑定解除:

    删除ifcfg-bond0,/etc/modprobe.d/bonding.conf

    修改ifcfg-eth0和ifcfg-eth0为绑定之前的样子

    rmmod bonding(很重要)

    service network restart

  • 相关阅读:
    大白痴学习webmagic
    selenium docs
    centos6.5单用户模式拯救系统
    使用Squid做代理服务器,Squid单网卡透明代理配置详解(转)
    Redundant Call to Object.ToString()
    Specify a culture in string conversion explicitly
    Benefits of Cold Showers: 7 Reasons Why Taking Cool Showers Is Good For Your Health
    Why Creating a Meaningful Morning Routine Will Make You More Successful
    git图示所有分支的历史
    Rewriting History with Git Rebase
  • 原文地址:https://www.cnblogs.com/joker-apologize/p/11734836.html
Copyright © 2011-2022 走看看