欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V99方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 2260|回复: 1
收起左侧

[系统维护] 两网口做bonding

[复制链接]
oppo 发表于 2014-9-5 15:29 | 显示全部楼层 |阅读模式
#!/bin/bash

# Name:         bond.sh
# Use:                 Configure Linux(centos>6) bond
# Usage:         bash bond.sh
# History:        
#        release20140722  hean  basic function


#有ip的写在前面
bond0=(
eth0
eth1
)

RSYNCSERVER="10.217.13.242::hean/bond/tmp/"

IPADDR=`ifconfig ${bond0[0]} |grep "inet\ addr"|awk '{print $2}'|awk -F '[:]' '{print $2}'`
NETMASK=`ifconfig ${bond0[0]} |grep "inet\ addr"|awk '{print $4}'|awk -F '[:]' '{print $2}'`
GATEWAY=`ip route |grep default|awk '{print $3}'`

LOGFILE=/tmp/$IPADDR.log

rm -f $LOGFILE && touch $LOGFILE
echo "${bond0[0]} is active. IPADDR=$IPADDR , NETMASK=$NETMASK , GATEWAY=$GATEWAY">>$LOGFILE

MODE=0 #bonding mode
        
cd /etc/sysconfig/network-scripts/

#按照要求修改网卡
function ModifyEth()
{
        #备份配置文件
        if [ ! -d backup ]; then
                mkdir backup
                cp ifcfg-* backup/
        fi
        rm ifcfg-* -f
        cp backup/ifcfg-* ./

        sed -i "s/^BOOTPROTO.*/BOOTPROTO=none/g" ifcfg-${bond0[0]}
        sed -i "s/^BOOTPROTO.*/BOOTPROTO=none/g" ifcfg-${bond0[1]}
        
        sed -i -r "/IPADDR.*|NETMASK.*|GATEWAY.*/d" ifcfg-${bond0[0]}
        sed -i -r "/IPADDR.*|NETMASK.*|GATEWAY.*/d" ifcfg-${bond0[1]}
        
}
        
#配置${bond0[0]} ${bond0[1]} 做bond0
function Bond0()
{
        cat >> ifcfg-${bond0[0]} <<eof
MASTER=bond0
SLAVE=yes
eof

        cat >> ifcfg-${bond0[1]} <<eof
MASTER=bond0
SLAVE=yes
eof

        cat > ifcfg-bond0 <<eof
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$IPADDR
NETMASK=$NETMASK
GATEWAY=$GATEWAY
USERCTL=no
eof

echo "************************************************" >>$LOGFILE
cat ifcfg-${bond0[0]} >>$LOGFILE
echo "************************************************" >>$LOGFILE
cat ifcfg-${bond0[1]} >>$LOGFILE
echo "************************************************" >>$LOGFILE
cat ifcfg-bond0 >>$LOGFILE
echo "************************************************" >>$LOGFILE
}

#修改modprobe配置文件
function ModifyModprobe()
{
        cd /etc/modprobe.d/
        rm -f sinabonding.conf
        touch sinabonding.conf
        
        #增加以下2行配置
        cat >> sinabonding.conf <<eof
alias bond0 bonding
options bond0 mode=$MODE miimon=100
eof
cat sinabonding.conf >>$LOGFILE
}


#回滚操作
function RollBack()
{
        
        if [ ! -d /etc/sysconfig/network-scripts/backup ]; then
                echo "you have not bond yet!"
                exit 0
        fi
        
        rm /etc/sysconfig/network-scripts/ifcfg-* -f && cp /etc/sysconfig/network-scripts/backup/ifcfg-* /etc/sysconfig/network-scripts/
        rm -f /etc/modprobe.d/sinabonding.conf
        echo "RollBack Finished!"
        exit 0
}

if [ $# -eq 0 ]; then
        ModifyEth
        Bond0
        ModifyModprobe
        rsync $LOGFILE $RSYNCSERVER
fi

if [ "$1"x = "-r"x ]; then
        RollBack
fi
 楼主| oppo 发表于 2014-9-16 16:35 | 显示全部楼层
hean@multiple-ssh> ip add|grep eth1
10.77.104.146:4: 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
10.77.104.148:4: 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
10.77.104.150:4: 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
10.77.104.147:4: 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
10.77.104.149:4: 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
hean@multiple-ssh> cat /etc/sysconfig/network-scripts/ifcfg-eth1
10.77.104.147:5: DEVICE="eth1"
10.77.104.147:5: HWADDR="F8:BC:12:34:B5:DD"
10.77.104.147:5: NM_CONTROLLED="yes"
10.77.104.147:5: ONBOOT="yes"
10.77.104.147:5: IPADDR=
10.77.104.149:5: DEVICE="eth1"
10.77.104.149:5: HWADDR="F8:BC:12:34:AB:61"
10.77.104.149:5: NM_CONTROLLED="yes"
10.77.104.149:5: ONBOOT="yes"
10.77.104.149:5: IPADDR=
10.77.104.148:5: DEVICE="eth1"
10.77.104.148:5: HWADDR="F8:BC:12:34:AD:B5"
10.77.104.148:5: NM_CONTROLLED="yes"
10.77.104.148:5: ONBOOT="yes"
10.77.104.148:5: IPADDR=
10.77.104.146:5: DEVICE="eth1"
10.77.104.146:5: HWADDR="F8:BC:12:34:CC:D9"
10.77.104.146:5: NM_CONTROLLED="yes"
10.77.104.146:5: ONBOOT="yes"
10.77.104.146:5: IPADDR=
10.77.104.150:5: DEVICE="eth1"
10.77.104.150:5: HWADDR="F8:BC:12:34:C5:B9"
10.77.104.150:5: NM_CONTROLLED="yes"
10.77.104.150:5: ONBOOT="yes"
10.77.104.150:5: IPADDR=
hean@multiple-ssh> rsync 10.217.13.242::hean/bond/bond.sh .
hean@multiple-ssh> ls
10.77.104.146:9: bond.sh
10.77.104.148:9: bond.sh
10.77.104.149:9: bond.sh
10.77.104.147:9: bond.sh
10.77.104.150:9: bond.sh
hean@multiple-ssh> sudo ./bond.sh
hean@multiple-ssh> 


[root@localhost tmp]# ls
10.77.104.146.log  10.77.104.147.log  10.77.104.148.log  10.77.104.149.log  10.77.104.150.log
[root@localhost tmp]# cat 10.77.104.146.log 
eth0 is active. IPADDR=10.77.104.146 , NETMASK=255.255.255.0 , GATEWAY=10.77.104.1
************************************************
DEVICE="eth0"
BOOTPROTO=none
HWADDR="F8:BC:12:34:CC:D8"
NM_CONTROLLED="yes"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
************************************************
DEVICE="eth1"
HWADDR="F8:BC:12:34:CC:D9"
NM_CONTROLLED="yes"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
************************************************
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.77.104.146
NETMASK=255.255.255.0
GATEWAY=10.77.104.1
USERCTL=no
************************************************
alias bond0 bonding
options bond0 mode=0 miimon=100
[root@localhost tmp]# cat 10.77.104.147.log 
eth0 is active. IPADDR=10.77.104.147 , NETMASK=255.255.255.0 , GATEWAY=10.77.104.1
************************************************
DEVICE="eth0"
BOOTPROTO=none
HWADDR="F8:BC:12:34:B5:DC"
NM_CONTROLLED="yes"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
************************************************
DEVICE="eth1"
HWADDR="F8:BC:12:34:B5:DD"
NM_CONTROLLED="yes"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
************************************************
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.77.104.147
NETMASK=255.255.255.0
GATEWAY=10.77.104.1
USERCTL=no
************************************************
alias bond0 bonding
options bond0 mode=0 miimon=100

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-12-28 21:15 , Processed in 0.035505 second(s), 8 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表