Haproxy、IPsec等服务器网口Bond的配置方法
(2011-10-10 09:19:26)
标签:
haproxyipsec配置方法杂谈 |
作者:高鹏杰
一、
进行bond配置时,安装好操作系统是必须的。又因为服务器直接连接核心交换机,操作有风险,所以服务器在bond配置完成前,除了远程管理卡网线以外不要接任何其它网线,让现场人员配置好远程管理卡,我们通过远程管理卡对服务器进行bond配置。
二、
Haproxy、IPsec等服务器除了服务器板载的网卡外,一般还安装有外接的4口网卡,上联网线就是要连接于外接网卡上。当系统安装完毕后,外接网卡系统识别为eth0~eth3,板载网卡识别为eth4~eth7,但是上线要求中一般要求网线连接于外接网卡,并且内网为eth2和eth3,配置bond0,外网为eth4和eth5,配置bond1,所以需要对系统中网卡的配置文件进行修改。以下以前段时间上线的永丰机房Haproxy服务器为例说明。
修改前:
#cd /etc/sysconfig/network-scripts/
# ls
ifcfg-eth0
ifcfg-eth1
ifcfg-eth2
ifcfg-eth3
ifcfg-eth4
ifcfg-eth5
ifcfg-eth6
ifcfg-eth7
修改方法:
#mv ifcfg-eth4 ifcfg-eth41
#mv ifcfg-eth5 ifcfg-eth51
#mv ifcfg-eth0 ifcfg-eth4
#mv ifcfg-eth1 ifcfg-eth5
#mv ifcfg-eth41 ifcfg-eth0
#mv ifcfg-eth51 ifcfg-eth1
笨方法,但是实现了将外接网卡配置文件名由ifcfg-eth0、ifcfg-eth1变为ifcfg-eth4和ifcfg-eth5。接下来需要修改eth0、eth1、eth4、eth5的配置文件中的“DEVICE”部分,改为和配置文件名匹配。如:
#vi /etc/sysconfig/network-scripts/ifcfg-eth4
DEVICE=eth4
BOOTPROTO=static
HWADDR=00:1B:21:3F:8E:68
ONBOOT=yes
TYPE=Ethernet
修改后:
#cd /etc/sysconfig/network-scripts/
# ls
ifcfg-eth0
ifcfg-eth1
ifcfg-eth2
ifcfg-eth3
ifcfg-eth4
ifcfg-eth5
ifcfg-eth6
ifcfg-eth7
配置ifcfg-eth2
#vi /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
HWADDR=00:1b:21:7c:00:54
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
配置ifcfg-eth3
#vi /etc/sysconfig/network-scripts/ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
HWADDR=00:1b:21:7c:00:55
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
配置ifcfg-eth4
#vi /etc/sysconfig/network-scripts/ifcfg-eth4
DEVICE=eth4
BOOTPROTO=none
HWADDR=00:1b:21:7c:00:50
ONBOOT=yes
TYPE=Ethernet
MASTER=bond1
SLAVE=yes
配置ifcfg-eth5
#vi /etc/sysconfig/network-scripts/ifcfg-eth5
DEVICE=eth5
BOOTPROTO=none
HWADDR=00:1b:21:7c:00:51
ONBOOT=yes
TYPE=Ethernet
MASTER=bond1
SLAVE=yes
配置bond0
#vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
配置bond1
#vi /etc/sysconfig/network-scripts/ifcfg-bond1
DEVICE=bond1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
配置bond0.235
#vi /etc/sysconfig/network-scripts/ifcfg-bond0.235
DEVICE=bond0.235
BOOTPROTO=static
ONBOOT=yes
USERCTL=no
IPADDR=172.16.235.19
NETMASK=255.255.255.0
说明:bond0.235为bond0的子端口,235为Ip:172.16.235.19所属VLAN的VLAN号,配置时需根据IP所属VLAN确认子端口号,不能确认的情况下可询问网络组。
配置bond1.135
#vi /etc/sysconfig/network-scripts/ifcfg-bond1.135
DEVICE=bond1.135
BOOTPROTO=static
ONBOOT=yes
USERCTL=no
IPADDR=180.149.135.19
NETMASK=255.255.255.0
GATEWAY=180.149.135.1
说明:bond1.135为bond1的子端口,135为Ip:180.149.135.19所属VLAN的VLAN号,配置时需根据IP所属VLAN确认子端口号,不能确认的情况下可询问网络组。
至此,网卡配置完成。
三、
#vi /etc/modprobe.conf
alias
eth0 bnx2
alias
eth1 bnx2
alias
eth2 igb
alias eth3 igb
alias
eth4 igb
alias
eth5 igb
alias eth6 bnx2
alias eth7 bnx2
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptsas
alias scsi_hostadapter2 ata_piix
alias scsi_hostadapter3 usb-storage
install ipv6 /bin/true
install sctp /bin/true
install pppoe /bin/true
install pppox /bin/true
install ppp_generic /bin/true
install slhc /bin/true
install bluetooth /bin/true
install dccp /bin/true
install ipx /bin/true
install appletalk /bin/true
install
irda
install
ax25
install
x25
#alias net-pf-10 off
#alias ipv6 off
#options ipv6 disable=1
#增加以下4行配置
alias bond0 bonding
options bond0 mode=balance-rr use_carrier=1 miimon=1
alias bond1 bonding
options bond1 mode=balance-rr use_carrier=1 miimon=1
四、
现在新装CentOS系统后都有2.6.18和2.6.30两个内核,bond需要2.6.30内核的支持,所以修改grub.conf,服务器启动时使用2.6.30内核。
#vi /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
#
NOTICE:
#
#
#
#
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.30-SINA)
title SinaLinux (2.6.18-164.el5)
五、
#vi /etc/sysconfig/network
VLAN=yes
向配置文件中增加“VLAN=yes”,设置下次启动自动加载802.1q 模块。
六、
重启后可以通过查看/proc/net/bonding/bond0(bond1)来检查网卡eth2~eth5是否被加载到bond0和bond1中。
$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)
Bonding Mode: load balancing (round-robin)
MII Status: down
MII Polling Interval (ms): 1
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII
Status: down
Link Failure Count: 0
Permanent HW addr: 00:1b:21:3f:8e:6c
Slave Interface: eth3
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:1b:21:3f:8e:6d
[pengjie@yf19 ~]$ cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)
Bonding Mode: load balancing (round-robin)
MII Status: down
MII Polling Interval (ms): 1
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth4
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:1b:21:3f:8e:68
Slave Interface: eth5
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:1b:21:3f:8e:69
至此bond配置完成,在和网络组确认核心交换机配置完成后,可以联系现场人员连接网线了。注意,外网连接外接网卡的1、2口,内网连接外接网卡的3、4口。