看看一般情況下網(wǎng)卡基本配置是怎么樣的?
使用DHCP自動(dòng)獲取IP:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
NAME=eth0
TYPE=Ethernet
IPV6INIT=no
HWADDR=xx:xx:xx:xx:xx:xx
如果是手工配靜態(tài)IP:
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
ONBOOT=yes
IPADDR=192.168.1.1
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
DNS=192.168.100.1
配置雙網(wǎng)卡高可用:
方法一:teaming
常用的兩種策略:輪詢式(roundrobin)的流量負(fù)載均衡;熱備份(activebackup)連接冗余
①建立虛擬網(wǎng)卡team0? ?,可參考 man teamd.conf
nmcli connection add ?type team con-name team0 ?ifname team0 autoconnect yes??
config '{"runner": {"name": "activebackup"}}'
解析:nmcli connection ?添加 ??類型? team 配置文件名 team0 ??網(wǎng)卡名? team0? 開機(jī)自動(dòng)啟用
team的工作模式為熱備份,若手誤敲錯(cuò),可將其刪除 nmcli connection delete team0
②為team0添加兩塊真實(shí)網(wǎng)卡(team-slave)
nmcli connection add type team-slave ?con-name team0-1 ifname ?eth1? master team0
nmcli connection add type team-slave ?con-name team0-2 ifname ?eth2? master team0
nmcli con modify team0-1 connection.autoconnect yes
nmcli con modify team0-2 connection.autoconnect yes
若手誤敲錯(cuò),可將其刪除?nmcli connection delete team0-1
③配值虛擬網(wǎng)卡team0的IP地址
nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.1.1/24 connection.autoconnect ?yes
④激活網(wǎng)卡
nmcli connection up team0
nmcli connection up team0-1
nmcli connection up team0-2
⑤查看綁定狀態(tài)
teamdctl team0 state
方法二:bonding
①網(wǎng)卡一配置文件內(nèi)容:
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no? ? ? ? ?
DEVICE=eth0
MASTER=bond0
SLAVE=yes
②網(wǎng)卡二配置文件內(nèi)容:
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=eth1
MASTER=bond0
SLAVE=yes
③創(chuàng)建綁定網(wǎng)卡
vim /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=bond0
IPADDR=192.168.1.1
PREFIX=24
NM_CONTROLLED=no
DNS=xxxx
GATEWAY=xxxx
BONDING_OPTS="mode=6 miimon=100"? ? ##等同于步驟⑤
④讓內(nèi)核支持網(wǎng)卡綁定驅(qū)動(dòng)
modprobe --first-time bonding
lsmod |grep bonding
⑤創(chuàng)建一個(gè)網(wǎng)卡綁定內(nèi)核驅(qū)動(dòng)文件(若做了步驟③可省略此步)
vim /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 miimon=100 mode=6
解析:定義網(wǎng)卡綁定為mode6平衡負(fù)載模式,且當(dāng)出現(xiàn)故障時(shí)自動(dòng)切換時(shí)間為100毫秒
常見的網(wǎng)卡綁定驅(qū)動(dòng)模式有:
mode0平衡負(fù)載模式:平時(shí)兩塊網(wǎng)卡均工作,且自動(dòng)備援,采用交換機(jī)設(shè)備支援。
mode1自動(dòng)備援模式:平時(shí)只有一塊網(wǎng)卡工作,故障后自動(dòng)替換為另外的網(wǎng)卡。
mode6平衡負(fù)載模式:平時(shí)兩塊網(wǎng)卡均工作,且自動(dòng)備援,無須交換機(jī)設(shè)備支援
⑥重啟網(wǎng)絡(luò)生效
systemctl restart network
⑦查看驗(yàn)證
?ifconfig? ; ip?a?s? ;
?cat /proc/net/bonding/bond0