Bind multiple NICs of Linux and FreeBSD to increase server traffic

Source: Internet
Author: User

This article may be helpful if you think that a gigabit Nic on an intranet server cannot meet your switching needs.
 
 
In fact, I have never thought about writing this article before, because I had an interview with a well-known domestic video website two days ago. I had the following question: "I will give you a server with four Gigabit NICs, how can I achieve the maximum 4G traffic output?" At that time, I did not think much about completing the job. After several days, I deployed the hadoop cluster. In retrospect, it was better to write and share the job. This may be a problem encountered by newbie in O & M or in the future. The current division of labor is also refined. For vswitches that are specialized in management, they do not know servers, and vswitches do not know servers. They often cannot think of similar solutions.
 
 
 
Applicability: ultra-large data exchange, massive data replication between networks, or multi-nic Master/Slave.
Purpose: To change the traffic of a single 1g Nic to 2-4g for multiple NICs.
 
 
In fact, this feature already exists in linux and Freebsd, but it is not noticed by most people. Instead of spending a lot of money to add servers, why not mine them in the system? Saving money is king. The cost for buying a server is enough to buy dozens of NICs.
 
 
1. Configure the multi-port EtherChannel of the vswitch.
 
 
Take the cisco3750 switch as an example. Of course, the 29 Series can also use Ethernet channels. You need at least two layer switches. But I only have 3750 in my hand, so I took 3750 to talk about it.
 
 
> Enable
# Conf terminal
Sw (config) # int port-channel 1
# Multiple servers are bound to multiple ports at the same time. The "Number" must be different.
Sw (config-if) # exit
Sw (config) # int range g1/0/1-4
Sw (config-if-range) # no sw
Sw (config-if-range) # channel-group 1 mode on
# Specify the "Number" set for the port-channel and set it to the Ethernet channel mode.
Sw (config-if-range) # exit
Sw (config) # do wr
# It is important to save it to startup.
 
 
To add multiple channels, you must specify different numbers. The switch ports of different channels cannot overlap. If you allocate Ports 1-4 to channel 1, you cannot allocate ports 4-8 to channel 2 but only ports 5-8. This is a basic logic problem.
 
 
Then, you can plug in N NICs on your server and boot the system. Here we use CentOS and FreeBSD8.2 as examples.
 
 
Ii. bind multiple ports in Linux
 
 
Linux is relatively simple. If it is more than 2.4 kernels, the bonding module has been loaded to the kernel by default.
 
 
#! /Bin/sh
Cd/etc/sysconfig/network-scripts/
Echo "DEVICE = bond0
BOOTPROTO = static
IPADDR = "IP"
NETMASK = "MASK"
BROADCAST = "BCAST"
ONBOOT = yes
TYPE = Ethernet
USERCTL = no "> ifcfg-bond0
 
Echo "DEVICE = eth0
ONBOOT = yes
BOOTPROTO = dhcp
USERCTL = no "> ifcfg-eth0
 
Echo "DEVICE = eth1
ONBOOT = yes
BOOTPROTO = dhcp
USERCTL = no "> ifcfg-eth1
 
Echo "alias bond0 bonding
Options bond0 miimon = 100 mode = 0 ">/etc/modprobe. conf
# Mode = 0 indicates that two NICs are enabled for parallel transmission at the same time. mode = 1 indicates that only one Nic is used.
Echo "ifenslave bond0 eth0 eth1">/etc/rc. local
Echo "------ Preparing to reboot ------ 5 seconds countdown" & sleep 5
Reboot
# If there are other NICs, modify the script to continue adding echo "DEVICE = ethx ....."
 
 
Use the root user to put this script on your server and execute it. You need to modify your own IP address, subnet mask, and broadcast address. If you have other NICs that need to be bound, copy and paste eth1 and modify it with reference to eth1.
 
 
3. FreeBSD is simpler
 
 
FreeBSD8.2 loads the netgraph module by default. You can go to/boot/kernel/to check whether ng_fec.ko and ng_socket.ko exist. If not, add the following three lines to the Kernel configuration file and then re-buildkernel and installkernel.
 
 
Options NETGRAPH
Options NETGRAPH_FEC
Options NETGRAPH_SOCKET
 
 
Then modify/etc/rc. conf.
 
 
Defaultrouter = "192.168.1.1"
Fec_interfaces = "fec0"
Fecconfig_fec0 = "em0 em1"
Ifconfig_fec0 = "inet 192.168.1.2 netmask 255.255.255.0"
# Comment out the IP address of ifconfig_em0, as shown below:
# Ifconfig_em0 = "inet 192.168.1.2 netmask 255.255.255.0"
 
 
Multiple NICs are directly added to fecconfig_fec0, separated by spaces.
 
 
Then, enjoy the speed and passion.
This article is from the "practice test truth" blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.