linux物理機上網卡冗餘配置

將Linux多網卡綁定爲一個邏輯網卡,可實現本地網卡冗餘、帶寬擴容提高網絡I/O和負載均衡。centos

原理:使用的是Linux內核中的bonding模塊,目前各發行版已包含該模塊,無需從新編譯內核。bonding提供綁定/集成多個網卡爲一個虛擬邏輯網口的功能。bash

 

網卡綁定有7中模式,這裏用的mode1,用於熱備、冗餘網口。自動備援模式,其中一條線若斷線,其餘線路將會自動備援。網絡

不重啓、手工配置負載均衡

1 modprobe bonding miimon=100rest

2 ifconfig bond0 192.168.0.1 netmask 255.255.255.0server

3 ifenslave bond0 em1 em2ip

 

配置後,需重啓get

#!/bin/bashit

#for centos 6.5編譯

cd /etc/sysconfig/network-scripts/ && touch ifcfg-bond0

FILE_PATH=/etc/sysconfig/network-scripts/ifcfg-bond0

cat > $FILE_PATH <<EOF

DEVICE=bond0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=static

BONDING_OPTS="miimon=80 mode=1"

EOF

 

read -p "IP:" ipmodi

read -p "MASK:" mask

read -p "gateway:" getw

read -p "hostname:" host

echo "IPADDR=$ipmodi" >> $FILE_PATH

echo "NETMASK=$mask" >> $FILE_PATH

echo "GATEWAY=$getw" >> $FILE_PATH

#sed -i 's/HOSTNAME=.*$/HOSTNAME='$HOST'/g' /etc/sysconfig/network

sed -i '/HOSTNAME/cHOSTNAME='$host'' /etc/sysconfig/network

cat $FILE_PATH

 

echo "alias netdev-bond0 bonding" > /etc/modprobe.d/bonding.conf

echo "nameserver 172.16.65.10" >> /etc/resolv.conf

 

NET_PATH=/etc/sysconfig/network-scripts

cp $NET_PATH/ifcfg-em1 $NET_PATH/ifcfg-em1.bak

cp $NET_PATH/ifcfg-em2 $NET_PATH/ifcfg-em2.bak

cat > $NET_PATH/ifcfg-em1 <<EOF

DEVICE=em1

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=static

MASTER=bond0

SLAVE=yes

EOF

 

cat > $NET_PATH/ifcfg-em2 <<EOF

DEVICE=em2

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=static

MASTER=bond0

SLAVE=yes

EOF

 

echo -e "\nifenslave em1 em2" >> /etc/rc.local

 

/etc/init.d/network restart

相關文章
相關標籤/搜索