Linux bond6配置文件,Linux服务器网卡绑定bond配置(示例代码)
原文
網(wǎng)卡綁定是通過把多張網(wǎng)卡綁定為一個(gè)邏輯網(wǎng)卡,實(shí)現(xiàn)本地網(wǎng)卡的冗余,帶寬擴(kuò)容和負(fù)載均衡。bond在實(shí)際網(wǎng)絡(luò)應(yīng)用部署中是一種常用的技術(shù)
下面介紹如何在CentOS服務(wù)器上實(shí)現(xiàn)網(wǎng)卡綁定
1、服務(wù)器ifconfig查看可以看到有兩塊網(wǎng)卡eth0,eth1
要實(shí)現(xiàn)物理網(wǎng)口eth0,eth1網(wǎng)卡綁定,綁定后的虛擬邏輯網(wǎng)口bond0 IP地址和原來的eth0的IP保持一致
2、modinfo bonding 檢查自己的操作系統(tǒng)是否支持bonding
如果沒有消息返回,說明內(nèi)核不支持bonding,需要重新編譯內(nèi)核
3、檢查ifenslave,是否有這個(gè)命令
4、接下來進(jìn)入正題
在cd /etc/sysconfig/network-scripts/下創(chuàng)建ifcfg-bond0配置文件
[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/
[root@YuanFan-CentOS network-scripts]# vi ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.31.2
NETMASK=255.255.255.0
GATEWAY=192.168.31.1
DNS1=114.114.114.114
DNS2=1.1.1.1
USERCTL=no
接下來修改ifcfg-eth0和ifcfg-eth1兩塊物理網(wǎng)卡的配置文件
將原有的IP、子網(wǎng)掩碼、網(wǎng)關(guān)信息等信息全部刪除,修改成如下格式
[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/
[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
5、修改modprobe相關(guān)設(shè)定文件,并加載bonding模塊
[root@YuanFan-CentOS ~]#
vi /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=6 miimon=200
加載bonding模塊
[root@YuanFan-CentOS ~]# modprobe bonding
如果這時(shí)是SecureCRT等SSH終端連接的服務(wù)器后臺(tái),會(huì)話可能會(huì)斷開,在服務(wù)器上確認(rèn)bonding模塊是否加載,然后用service network restart或者/etc/init.d/network restart命令重啟網(wǎng)絡(luò)
[root@YuanFan-CentOS ~]# lsmod | grep bonding
bonding? ? ? ? ? ? ? ?132885? 0
[root@YuanFan-CentOS ~]# service network restart
Shutting down interface bond0:? [? OK? ]
Shutting down loopback interface:? [? OK? ]
Bringing up loopback interface:? [? OK? ]
Bringing up interface bond0:? Determining if ip address 192.168.31.2 is already in use for device bond0...
[? OK? ]
[root@YuanFan-CentOS ~]#
查看bond網(wǎng)卡綁定后的模式
cat /proc/net/bonding/bond0
[root@YuanFan-CentOS ~]#?cat /proc/net/bonding/bond0
6、測(cè)試一下負(fù)載均衡功能
手動(dòng)斷開eth0鏈路的網(wǎng)線,看網(wǎng)絡(luò)是否還通
如下圖所示ethtool eth0 可以看到eth0網(wǎng)口已經(jīng)斷開,右側(cè)可以看到ping 192.168.31.1網(wǎng)關(guān)一直可以ping通
注:mode bond網(wǎng)卡綁定的幾種模式之前有介紹,請(qǐng)參見本公眾號(hào)歷史文章
mode:Mode of operation
0 for balance-rr,
1 for active-backup,
2 for balance-xor,
3 for broadcast,
4 for 802.3ad,
5 for balance-tlb,
6 for balance-alb (charp)
總結(jié)
以上是生活随笔為你收集整理的Linux bond6配置文件,Linux服务器网卡绑定bond配置(示例代码)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 紫光国微 2022 年营收 71.20
- 下一篇: linux旧版本如何升级成新版本,Lin