Tcpcopy pressure test tool test in Linux

Source: Internet
Author: User
Tags iptables git clone nginx reverse proxy

Introduction of Tcpcopy
Xcopy is mainly by NetEase's Wang bin developed a set of traffic replication testing tools. The Xcopy series includes open source software such as Tcpcopy, Udpcopy, Mysqlcopy, which is integrated into the Tcpcopy open source project. Once applied to NetEase advertising system, URS System, Nginx HMUX protocol and other systems, to avoid the on-line brought many problems. So many times we refer to tcpcopy (broadly speaking) that includes Xcopy's system-wide products.

The tcpcopy consists of two parts: Tcpcopy client (tcpcopy) and Tcpcopy server (intercept), where the Tcpcopy client runs on the online system to capture the online request packets, while Tcpcopy The server runs in the test system, which is used to do a series of auxiliary coordination work, such as returning the reply header information, maintaining the routing information, etc.

Ii. the new structure of tcpcopy
The latest version of the current tcpcopy is 0.9.9, and Tcpcopy has started using the new architecture since the v0.8 version. Here's a look at the new architecture:

In contrast to the old architecture prior to 0.8, the new architecture offload Intercept's work from the test server to the other standalone secondary server (assistant server), In principle, it is important to use an idle server in the same network segment to act as a secondary server to intercept the response packet, and transfer the traditional architecture from the IP layer to capture the response packets from the data link layer to grasp the response packet, these changes greatly reduce the tcpcopy to test the machine's various interference (under the new architecture, in addition to routing settings, Others have not been affected, greatly enhancing the ability of intercept to capture response packs, and testing is more realistic.

A comparison of the old and new architectures can be provided in the official Chinese handbook.

Third, tcpcopy installation and configuration options
Installation

Tcpcopy hosted on GitHub, whose project home page is: https://github.com/wangbin579/tcpcopy, can be installed by the following method tcpcopy

The code is as follows Copy Code
# git clone git://github.com/wangbin579/tcpcopy.git
Here you can also download the zip package from GitHub
# CD tcpcopy-0.9.9
# sh autogen.sh
#./configure--enable-option
# Make && make install

Compilation options

The optional options for--enable are:

--enable-debug compile tcpcopy with debug support (saved in a log file)
--enable-mysqlsgt run tcpcopy at MySQL skip-grant-tables mode (recommended)
--enable-mysql run tcpcopy at MySQL mode
--enable-offline run tcpcopy at offline mode
--enable-pcap run tcpcopy at pcap mode
--ENABLE-UDP run tcpcopy at UDP mode
--enable-nfqueue Run the Tcpcopy server (intercept) at Nfqueue mode
--enable-advanced run Tcpcopy at Advanced Mode (Advanced archecture)
--enable-dlinject send packets at the data link layer instead of the IP layer
--enable-rlantency add more lantency control
The details can also be viewed through the./configure--help.

Error

There are several errors that you may encounter during installation:

Autogen.sh:1: Autogen.sh:autoreconf:not found
Workaround: sudo apt-get install Automake

Errors that you may encounter when you compile with the--enable-nfqueue option:

No need to check nfqueue or Ip_queue
Checking for Nfqueue directory ... configure:error:nfqueue required. Install libnetfilter_queue (Download it from http://www.netfilter.org/projects/libnetfilter_queue/index.html) or Specify its path using--with-nfqueue=/dir/
Workaround: sudo apt-get install Libnetfilter-queue-dev

Errors that you may encounter when you compile with the--ENABLE-PCAP option:

Configure:error:pcap.h not found.
Workaround: sudo apt-get install Libpcap-dev

Iv. tcpcopy Online Replication
In the new architecture of tcpcopy, online replication testing requires at least 4 hosts. The relationship between four of them I simply drew a sketch that might be better understood relative to the architecture diagram:

The role relationships of the above four hosts are as follows:

A host: As a requester, in the application scenario, you can understand that it is the front-end Nginx, LoadRunner testing machine

B Host: The online host, in the application scenario, can be understood as it is the web architecture of Tomcat, resin applications (which can be accessed through the Nginx reverse proxy, can also be loadrunner directly through the Http://IP: the form of the port to access the object)

C Host: Test host, in the application scenario, its running application and B host on the application of the same. For example, the new version or new features of the application cloth on the C host, through the replication B host traffic in the real environment under the pressure test, you can find out whether there are bugs, performance and so on. This is also the purpose of the tcpcopy test. The machine needs to configure route routing in the test environment.

D Host: Intercept host, that is, the secondary server in the schema diagram. Intercept through communication between and tcpcopy, control the replication of traffic between B and C. And finally on the C host simulation results, is equivalent to a host direct Request C host (This is the figure A, c between the meaning of Gray arrow).

Note: The above is just my personal understanding. In reality test environment, according to the different simulation pressure, a, B, C, D can be N sets at the same time.

Now according to the above architecture, simulation for replication, the IP of each host is as follows:

A host: 172.20.0.130

B Host: 172.20.0.40

C Host: 172.20.0.42

D Host: 172.20.0.39

A host:

No Configuration required

C Host:

Configuring routing

The code is as follows Copy Code
# route Add-host 172.20.0.130 GW 172.20.0.39

D Host:

Install Tcpcopy

The code is as follows Copy Code

#./configure--enable-advanced--enable-pcap--enable-nfqueue
# make
# make Install
Run intercept

If D's main kernel version is less than 3.5, the following--enable-nfqueue parameter is not required at compile time, and the Uqeue module is used to run the following way intercept

The code is as follows Copy Code
# modprobe Ip_queue # if not running
# iptables-i output-p TCP--sport port-j QUEUE # if not set
#./intercept

Since I am using a kernel version of Ubuntu larger than 3.5 here, start it as follows

# sudo iptables-i output-p tcp--sport 8080-j nfqueue
# sudo intercept-i eth0-f ' TCP and SRC host 172.20.0.42 and src port 8080 '-D
Note: In the old traditional architecture, depending on the kernel version, the steps above need to be started. In the new architecture above the firewall part is not required to start, here to thank the original author Wang bin to give the concept of timely correction.

B Host

Install Tcpcopy

Compile the installation using the following method

The code is as follows Copy Code
#./configure--enable-advanced--enable-pcap
# make
# sudo make install

Note: Here the--enable-pcap parameters can not be added, the added advantage is that the package can be filtered conditionally.

Start Tcpcopy

The code is as follows Copy Code
# sudo tcpcopy-x 172.20.0.40:8080-172.20.0.42:8080-s 172.20.0.39-i eth0-d

Verify

After the default tcpcopy is installed, the tcpcopy and intercept execution files are generated in the/usr/loca/bin directory, and the location of the log files is not specified using the-l parameter in our startup process, by default in the/usr/local/ The bin directory generates Error_intercept.log files (both B and D hosts are available). We can view the information interaction between tcpcopy and intercept by looking at the log file.

Verify the success of traffic replication, you can view the B, C two host access logs, can be viewed from a host to B host of access to the same on the C host also embodies, if any, to prove the success of replication.

Note: Depending on the complexity of the internal and external network test environment, the routing rules may also be slightly different. Specific can see Wang bin in csdn on the blog.

Five, off-line test

An offline host requires only two hosts: an online host and a test host.

Grab the package on the online host in the following way:

The code is as follows Copy Code
Tcpdump-i any TCP and port <port>-S 0-w online.pcap

Install offline version tcpcopy on test server

The code is as follows Copy Code

#./configure--enable-offline
# make
# sudo make install
Start intercept and tcpcopy on the test server

# modprobe Ip_queue (does not require this operation if the kernel is greater than 3.5)
# iptables-i output-p TCP--sport <port>-j QUEUE
# Intercept

Replay the packets that are crawled online

The code is as follows Copy Code
# Tcpcopy-i < Grab package file address >-x <port>-< local ip>:<port>

Note:

1, the above iptables operation must have, no words package can not be replayed.

2, tcpcopy playback process of the local IP, can be native IP can also be the LAN other host IP.

Related Article

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.