How to build a P2P download service in Linux

Source: Internet
Author: User
Tutorial on how to build a P2P download service in a Linux environment-Linux Enterprise Application-Linux server application information. The following is a detailed description. The P2P protocols in Linux mainly include BitTorrent, aMule, and Gnutella. This article describes how to build a P2P service in the Redhat Enterprise Linux Advanced Server 4 environment.

With the prevalence of the broadband network, the traditional HTTP and FTP methods for Multi-Point download can no longer meet your needs. As the number of downloads increases, the connection speed decreases sharply. P2P technology breaks the regular format and greatly saves network bandwidth. This allows you to directly connect to other users' computers and exchange and search for files without having to browse and download the files on the web page to maximize network bandwidth. It allows everyone to share a variety of massive resources that are hard to reach in common ways on the Internet. Each PC using P2P software is a client downloading resources, and the server is uploading files.

BitTorrent is an open source P2P software for Multi-Point download, which is very convenient to use. Is a multi-point Download shared file software, because the download can also be provided to other users, so the download speed will not decrease as the number of users increases, the more people you download, the faster the download speed. Many large companies, such as RedHat, have used BT to allow their customers to download the development version.

Set up a BitTorrent Server

BitTorrent is written in Python. It is an open source software that can be run either in Windwos or in Linux. The official website of BitTorrent is: http://bitconjurer.org/BitTorrent. The latest version is 4.0.2-1. Run "rpm-qa | grep Python" to check whether the Python language is configured before installing BitTorrent. Otherwise you need to download the installation from its official website http://www.python.org.

1. Download and install software

# Wget http://www.bittorrent.com/dl/BitTorrent-4.0.2-1.noarch.rpm

# Rpm-ivh BitTorrent-4.0.2-1.noarch.rpm

After the installation is complete, all BitTorrent commands and tools are installed in the/usr/bin directory. Including: btmaketorrent. py (seed making tool), bttest. py (test seed tool), bttrack. py (Tracker tool) and btdownloadheadless. py (used to create a Shared Source Tool) and btlaunchtasks. py (the Shared Source Tool is started in the background) and btshowmetainfo. py (tool for viewing download conditions) and btdownloadgui. py (graphical sharing Source Tool), btmaketorrent. py (graphical seed making tool ).

2. Configure and start BitTorrent

The core of BitTorrent is Tracker. the BitTorrent service does not need servers, but the BitTorrent service still has the concept of servers. This is called Tracker. To be accurate, Tracker is a program on the running server. This program can track the number of people downloading the same file at the same time. When the BT client connects to the Tracker, a list of download personnel is generated. Based on this list, the BT client automatically connects to other nodes in the network for download. So the first step is to start a Tracker:

#./Bttrack. py -- port 6969 -- dfile dstate>/dev/null 2> & 1 &

We recommend that you use common user permissions to start this service, which is more secure. This command will generate a dstate file in the current directory and open port 6969.

3. Seed)

The track service of the BT server does not provide the download service. The download service is its seed, which is a client that has been downloaded or is being downloaded. Because there is no such seed in the beginning, you must first generate one by yourself. If you want to create a seed for/home/cve-avi, the related command is:

#./Btdownloadheadless. py -- max_allow_in 30 -- max_upload_rate 1000 -- minport 6888 -- maxport 6888/home/cstrap. avi. torrent http://www.mydomain.com: 6969/annouce

Parameter description:

-- Max_allow 30: this seed can accept up to 30 connections.

-- Max_upload_rate 1000: the maximum acceptable download bandwidth of this seed is 1000 KB (byte)/s, which can control the download bandwidth.

-- Minport 6888 -- maxport 6888: set the maximum and minimum listening port number. This means that the seed only listens to port 6888, which facilitates port opening on the firewall.

Csf-. avi. torrent: the name of the created seed file.

4. Set the Apache server

Configure the Web server to associate the seed (. torrent) file with application/x-bittorrent. Soon Add the following line to the Apache configuration file:/etc/httpd. conf:

AddType application/x-bittorrent. torrent

5. Restart the Web server and open the firewall port 6888.

Place the created seeds in the document directory of the Web server so that users can access them and start a original sharing source.

# Iptables-a input-I eth0-p -- dport 6888-j ACCEPT

# Iptables-a output-I eth0-p -- dport 6888-j ACCEPT

#./Btdownloadheadless. py http://www.mydomain.com/cjh.avi.torrent

In the example. As I am a Linux system administrator, I am used to working using command lines. Readers can also use graphical front-end tools, as shown in figure 1.



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // www.ppcn.net/upload/2006_03/060313242424951.jpg'); ">
BitTorrent graphical front-end tool

So far, we have established a BitTorrent server. To download other BT resources, we need to install a client.

Install the Azureus download software on the client

1. Download A Bit Torrent client: Azureus. The official website is http://azureus.sourceforge.net /.

# Wget http://ftp10.enet.com.cn/pub/lin... 2_linux.GTK.tar.bz2

2. install Java Virtual Machine

Because Azureus is written in Java, it requires a Java Virtual Machine to run it. Download the latest JDK (Java Development Kit) Development Kit: j2sdk-1_4_2-linux-i586.bin, A J2SE V1.4.2 SDK Linux self-decompressed binary file.

3. Install the Bit Torrent client software Azureus

This is a green software that can be decompressed without compilation. The operation is as follows:

# Bunzip2 Azureus_2.2.0.2_linux.GTK.tar.bz2

# Tar vxf Azureus_2.2.0.2_linux.GTK.tar

4. Run the software

# Cd azureus

#./Azureus

5. Configuration Software

Perform simple configuration when running azureus for the first time:

● Configure the Internet access method

You can set the connection to the Internet (ADSL, Modem, etc.) based on your actual situation. The maximum upload speed, maximum download speed, and maximum upload speed of each Torrent are supported. Click "Next" to configure the server port.

● Configure the NAT/Server port

The advantage of using NAT (Network Address Translation) is that it connects to the Internet, but does not allow all computers in the Network to have a real Internet IP Address. The NAT Function allows you to manage valid Internet IP addresses in a unified manner. When an internal computer needs to access the Internet, it dynamically or statically converts a fake IP address to a valid IP address. In addition, if you do not want external network users to know the internal structure of the network, you can use NAT to isolate the internal network from the external Internet. We strongly recommend that you set the NAT/Server port to 6881 or 6889 at the lowest. If you are familiar with the computer network, you can also click the "Test" button and select another port. Do not conflict with the ports used by some systems. Click "Next" to configure the directory for storing the downloaded files.

6. Download Software

After the configuration is complete, you can use it for download. Click "Creat a Torrent" in the "File" Main Menu and enter the link of the Torrent File to be downloaded to start work.

7. BT download instance

This is the working interface for the author to download Fedore Core 3. You can see that Azureus downloads the IOS file of Fedore Core 3. The figure shows the file name, download speed, and completion percentage. Java-based Azureus is a cross-platform BT client program with 27 languages to choose from, you can manage multiple downloads, view detailed real-time download statistics, set advanced download management rules, and set and establish torrent in a single GUI window. The new version includes download speed restrictions, shared online restrictions, and more data columns. If the software is disconnected when you use Azureus to download the software, you can click the download link again and overwrite half of the files downloaded last time when selecting the storage location, at this time, the program will automatically resume the file.



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // www.ppcn.net/upload/2006_03/060313242424952.jpg'); ">
Download Fedore Core 3 with Azureus

Use aMule Software

AMule is a P2P software that supports ED2K networks. It is based on wxWindows and is similar to eMule. Developed based on the E-Donkey network protocol, it is equivalent to a Mod of e-Donkey (Donkey) and the source code is completely open. AMule is easier to configure than e-Donkey, and the interface, icons, and buttons are more beautiful, highlighting the three-dimensional and translucent feeling. Almost all of us are switching to e-Mule. The aMule software can be regarded as e-Mule in the Linux network environment.

Each client of aMule is both a file downloader and a uploader. When you are downloading but haven't downloaded the complete file, you have shared the downloaded part with others. AMule downloads the desired file from many file uploaders (called the "Source", which is similar to the BT seed) at the same time and finally splices it into the entire file, in addition, aMule is very convenient for file sharing that is not in the download queue. You do not need to make the seeds as easily as BT and upload them to the server. You only need to specify a shared directory, aMule will automatically share it. The shared directory is forcibly shared once aMule is run, even if no files are downloaded in the download bar. This is better than BT, which can prevent you from downloading and not uploading. While BT only uploads things that it is downloading or has already downloaded at runtime, and cannot share directories. Some even set BT download to unrestricted, to several KB/s or even 0KB/S. In aMule, if you set the upload speed to a value smaller than 10, aMule will automatically limit your download speed.

The installation of aMule is quite difficult, and it is the most difficult tool and software for the author to handle since Linux. It is highly dependent on some linked library files, and also needs GTK support. Therefore, the software installation is detailed here. The steps for downloading and installing software are as follows:

# Cd/usr/local

# Wget http://jaist.dl.sourceforge.net/.../wxGTK-2.6.1.tar.gz

# Wget http://jaist.dl.sourceforge.net/... wxBase-2.6.1.tar.gz

# Wget http://jaist.dl.sourceforge.net/... aMule-2.1.0.tar.bz2

Note the installation sequence: Install wxBase, then wxGTK, and aMule. After wxBase is installed, run the ldconfig command. The wxGTK compilation parameter is./configure -- with-gtk.

# Cd wxBase-2.6.1;./configure; make install;/sbin/ldconfig; cd ..

# Cd wxGTK-2.6.1;./configure -- with-gtk; make install; make clean; cd ..

# Cd aMule-2.1.0;./configure; make install

Now aMule is a GTK 2 interface, which is very beautiful and supports Chinese well. After installation, set the nickname to [CHN] [VeryCD] xxxx, and then set the server name to: DonkeyServer NO1, address 62.241.53.2: 4242. In addition, there are other servers, such as Chinese psp source power, address 61.152.93.254: 4661; and Razorback 2, address 195.245.244.243: 4661. For more information about server settings, see. The usage of aMule is almost the same as that of eMule, and you can get started quickly.



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // www.ppcn.net/upload/2006_03/060313242424953.jpg'); ">
AMule server settings page

If the download speed of aMule is too slow, for example, only 2 kb/s ~ 3KB/s, there must be no port ing. You only need to map the 4662 TCP and 4672 UDP ports. You do not need to map a bunch of ports like Using BT. If Port 4771 is enabled, remote control is enabled. If you are not at home, aMule is installed on your friend's machine, or you can remotely control your aMule on the friend's machine. Unlike Azureus, aMule needs to download more files. If the system is equipped with a Linux firewall, you need to open the above TCP and UDP ports in the firewall.

Gtk-Gnutella

Gtk-Gnutella is the server/client implementation of Gnutella in Linux (Linux and BSD) systems. This software depends on GTK + (version 1.2 and later) and libxml, but Gnome is not required. Currently, Gtk-Gnutella is mainly developed and tested in Linux (Debian 3.1) and supports at least the following operating systems: linux, FreeBSD, NetBSD, OpenBSD, Darwin, Solaris, Tru64 UNIX (OSF/1), sgi irix, and BeOS. The supported CPU architectures include: x86, AMD64, PowerPC, iSCSI, MIPS, etc. Gnutella is released under the GNU General Public License (GPL. Gtk-Gnutella has not been completed yet, but it has complete functions. Through Gtk-Gnutella, you can share, search, and download various files. Gtk-Gnutella has good stability, you can consciously work one day after another.

Developers of Gtk-Gnutella think their technology is better than ED2K. Because it is open-source and does not have a central server, it is a completely interconnected network between users, thus ensuring that users are not monitored by the central server. It can be said that the network will not disappear as long as someone is still using the software. Despite the recent rise of BT and other technologies, the number of users has declined sharply, but a large number of resources can still be searched, and the speed is also good. The bandwidth demand for searching network resources is also less than ED2k. To put it simply, Gtk-Gnutella users are connected to each other in a network, and your search will be sent to other Gtk-Gnutella users. Then they will be uploaded to form a huge search network. This seems to consume a lot of network resources, but Gtk-Gnutella introduces the concepts of Ultrapeer and Leaf. If the bandwidth is relatively small, the search request will be mainly sent to the ultra-high-bandwidth Ultrapeer. They will help you continue to contact other nodes for search and then tell you after searching. Gtk-Gnutella is a client with good compatibility. You only need gtk + or gtk2, but not gnome desktop environment. The download and installation methods are as follows:

# Cd/usr/local

# Wget http://jaist.dl.sourceforge.net/... tella-0.96b.tar.bz2

# Bunzip2 gtk-gnutella-0.96b.tar.bz2

# Tar vxf gtk-gnutella-0.96b.tar; cd gtk-gnutella-0.96b;./Configure; make install

After performing the preceding operations, the system will provide an installation wizard to complete the installation. Gtk-Gnutella has good security performance. It cannot work under the root permission and must be used in the work environment of common users. I really appreciate this method. For details about the work interface, see.



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // www.ppcn.net/upload/2006_03/060313242524954.jpg'); ">
Gtk-Gnutella working interface

Gnutella also has some clients available, such as LimeWire (http://www.limewire.com /). Its interface is beautiful, user-friendly, and can be changed to the skin. However, the free basic version is too slow.

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.