Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use apt-p2p to build package caches in Debian

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to install and use apt-p2p in Debian to build package cache". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to install apt-p2p in Debian to build package cache".

Apt-p2p, as its name implies, is the direct transmission of deb software packages between users.

Then I remembered that Debian had developed a software called apt-p2p, which was originally designed to cache downloaded packages for other peers also running apt-p2p as a supplement to downloads from software sources. So can you use this software to build a cache of Debian packages in the local area network?

Apt-p2p has the advantages of P2P technology:

# * you can get the software package from the user node and download it from the official source

# * the more people use apt-p2p, the more efficient and faster the package will be delivered

# * low CPU and memory resource consumption

# * Hash check is performed before the software package is delivered to maximize security and avoid downloading to damaged packages

But similarly, it also has the disadvantages of P2P:

# * if not many people use apt-p2p, the speed may not be as fast as the original apt-get.

# * although the probability is very small, it may still encounter potential hash fraud, which may lead to system security risks.

At present, there are not many people using apt-p2p in China, which may be the main reason that restricts the promotion of apt-p2p in China.

But if everyone doesn't support apt-p2p, how can apt-p2p develop? How can we get the convenience of apt-p2p?

Therefore, I would like to call on everyone to use apt-p2p!

Installation steps and methods

1. Be prepared to rely on the environment

The code is as follows:

Sudo apt-get install python python-apt python-twisted python-twisted-web2

2. Install apt-p2p

The code is as follows:

Sudo apt-get install apt-p2p

3. Modify the list of software sources (Note: third-party sources do not need and need not be modified)

The code is as follows:

Sudo cp / etc/apt/sources.list / etc/apt/sources.list.backup

Sudo sed-I's% http://%http://localhost:9977/%g' / etc/apt/sources.list

4. Configure apt-p2p as needed

The code is as follows:

Sudo gedit / etc/apt-p2p/apt-p2p.conf

Among them

"PORT =" specifies the port used by apt-p2p, which defaults to "9977". Of course, you can also specify it as "9527", just make sure it is consistent with the modified value in "/ etc/apt/sources.list"

"UPLOAD_LIMIT =" specifies the maximum upload speed. The default is "0", which means there is no speed limit. It is recommended to set it to "10 seconds 50" (KB/ seconds).

"MIN_DOWNLOAD_PEERS =" specifies how many prees nodes are available before downloading from the official source. It is recommended to use the default value "3".

"CACHE_DIR =" is the package cache directory for the specified apt-p2p. The default value is recommended.

"OTHER_DIRS =" specifies an additional package directory. Note: once specified, all files in this directory will be uploaded

"UPLOAD_LIMIT =" specifies whether the package download data list is counted and published. The default is "yes". If your computer requires a high level of confidentiality, please set it to "no".

"DHT-ONLY =" whether to use only the resources provided by the distributed hash table, it is recommended to use the default value "no"

5. If there is a firewall, the ports "9967" and "9977" must be opened. If you use a router, you also need to make mapping settings.

6. Restart apt-p2p to apply the new configuration

The code is as follows:

Sudo rm-rf / var/cache/apt-p2p/cache/*

Sudo / etc/init.d/apt-p2p restart

7. Start updating, upgrading the system or installing the software package

The code is as follows:

Sudo apt-get update

Sudo apt-get upgrade

Explanation: some tutorials say that third-party sources should be banned, but in the case of my actual use, there is no effect even if we do not prohibit the use of third-party sources.

How to view the operation of apt-p2p:

Enter http://localhost:9977/ in the browser address bar to view the relevant information

Local package cache construction method:

Apt-p2p is written by Python. After installation, it listens to port 9977 of TCP and UDP by default, and its behavior can be changed through / etc/apt-p2p/apt-p2p.conf. The TCP port is also used for native apt download packages, while the UDP port is used to build DHT networks that are common in P2P file sharing tools. You only need to insert localhost:9977 in front of the url of the software source in the / etc/apt/sources.list file, such as the server domain name of http://mirror.server/debian/, to become http://localhost:9977/mirror.server/debian/. The specific task of obtaining the software package from the Internet is left to apt-p2p:

When receiving a request to download a file from a native apt, apt-p2p first detects whether the file already exists in the cached directory tree

If it already exists, also check to see if it is up to date (by issuing a HEAD request to the software source server)

If so, return the cached file directly

Otherwise, download the file from the Internet and supply it to apt, store it in the cache and record its hash value.

The download file will first try to download from peer, not to the software source server.

Cached files and hash values are available for use by other peer. You can drill down into this process through apt-p2p 's log file / var/log/apt-p2p.log.

Here is the sources.list of the host mycastle where I installed apt-p2p:

The code is as follows:

Deb http://localhost:9977/mirrors.ustc.edu.cn/debian/ testing main

Deb-src http://localhost:9977/mirrors.ustc.edu.cn/debian/ testing main

Deb http://localhost:9977/mirrors.ustc.edu.cn/debian-security/ testing/updates main

Deb-src http://localhost:9977/mirrors.ustc.edu.cn/debian-security testing/updates main

Deb http://localhost:9977/mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb-src http://localhost:9977/mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb http://localhost:9977/mirrors.ustc.edu.cn/debian/ unstable main

Deb-src http://localhost:9977/mirrors.ustc.edu.cn/debian/ unstable main

However, the cache of apt-p2p can only be used locally, and other hosts will only get an error if they try to access port 9977 directly. Therefore, you also need to set up a http reverse proxy on the host where apt-p2p is installed, so that in apt-p2p 's view, all requests come from the local machine.

The reverse proxy I use is Pound, which is disabled by default after installation. After configuring the server in / etc/pound/pound.cfg, enable it in / etc/default/pound, and then start the server using service.

The configuration I use is as follows:

The code is as follows:

... (keep default)

ListenHTTP

Address 0.0.0.0

Port 9978

# # allow PUT and DELETE also (by default only GET, POST and HEAD)?:

XHTTP 0

Service

BackEnd

Address 127.0.0.1

Port 9977

End

End

End

Listen on port 9978, and the background server is on port 9977 of this machine.

In this way, other hosts can also use apt-p2p 's cache through port 9978. My approach is to move / etc/apt/sources.list to / etc/apt/sources.list.d/50_main.list on other hosts that are going to use the cache, and then build / etc/apt/sources.list.d/10_apt-p2p-home.list based on the list of software sources of the cache host, just change the localhost:9977 in the url to .local: 9978, and of course it's best to keep the software source server the same. In this way, apt will first use apt-p2p 's cache through reverse proxy, and when the cache is not available, you can still directly connect to the software source server to obtain the software package:

The code is as follows:

10_apt-p2p-home.list:

Deb http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ testing main

Deb-src http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ testing main

Deb http://mycastle.local:9978/mirrors.ustc.edu.cn/debian-security/ testing/updates main

Deb-src http://mycastle.local:9978/mirrors.ustc.edu.cn/debian-security testing/updates main

Deb http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb-src http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ unstable main

Deb-src http://mycastle.local:9978/mirrors.ustc.edu.cn/debian/ unstable main

50_main.list:

Deb http://mirrors.ustc.edu.cn/debian/ testing main

Deb-src http://mirrors.ustc.edu.cn/debian/ testing main

Deb http://mirrors.ustc.edu.cn/debian-security/ testing/updates main

Deb-src http://mirrors.ustc.edu.cn/debian-security testing/updates main

Deb http://mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb-src http://mirrors.ustc.edu.cn/debian/ testing-proposed-updates main

Deb http://mirrors.ustc.edu.cn/debian/ unstable main

Deb-src http://mirrors.ustc.edu.cn/debian/ unstable main

If apt-transport-https is installed, you can replace the http in 50_main.list with https.

This domain name format with hostname plus ".local" is a method provided by mDNS/DNS-SD protocol to locate hosts and publish services in the broadcast domain, which mainly implements Bonjour of Avahi and Mac OS X.

In this way, in the local area network, any host has priority to obtain the software package through apt-p2p, and an update can benefit the whole family; even if multiple hosts are updated in a short time, they only need to request the software source once; and large-scale data flow occurs in the local area network with high bandwidth, which shortens the update time and improves the efficiency.

It's just that this is equivalent to configuring two software sources on a non-cache host, and when the repeated parts of the information of the two software sources are out of sync (such as laptops updating the software package list of directly connected software source servers outside the LAN), apt-get source cannot be used because apt checks the source package more strictly.

Thank you for reading, the above is the content of "how to install and use apt-p2p to build package cache in Debian". After the study of this article, I believe you have a deeper understanding of how to install and use apt-p2p to build package cache in Debian, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report