特殊:Badtitle/NS100:AptProxy
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/AptProxy }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/af | • {{#if: UbuntuHelp:AptProxy|Afrikaans| [[::AptProxy/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ar | • {{#if: UbuntuHelp:AptProxy|العربية| [[::AptProxy/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/az | • {{#if: UbuntuHelp:AptProxy|azərbaycanca| [[::AptProxy/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/bcc | • {{#if: UbuntuHelp:AptProxy|جهلسری بلوچی| [[::AptProxy/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/bg | • {{#if: UbuntuHelp:AptProxy|български| [[::AptProxy/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/br | • {{#if: UbuntuHelp:AptProxy|brezhoneg| [[::AptProxy/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ca | • {{#if: UbuntuHelp:AptProxy|català| [[::AptProxy/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/cs | • {{#if: UbuntuHelp:AptProxy|čeština| [[::AptProxy/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/de | • {{#if: UbuntuHelp:AptProxy|Deutsch| [[::AptProxy/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/el | • {{#if: UbuntuHelp:AptProxy|Ελληνικά| [[::AptProxy/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/es | • {{#if: UbuntuHelp:AptProxy|español| [[::AptProxy/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/fa | • {{#if: UbuntuHelp:AptProxy|فارسی| [[::AptProxy/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/fi | • {{#if: UbuntuHelp:AptProxy|suomi| [[::AptProxy/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/fr | • {{#if: UbuntuHelp:AptProxy|français| [[::AptProxy/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/gu | • {{#if: UbuntuHelp:AptProxy|ગુજરાતી| [[::AptProxy/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/he | • {{#if: UbuntuHelp:AptProxy|עברית| [[::AptProxy/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/hu | • {{#if: UbuntuHelp:AptProxy|magyar| [[::AptProxy/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/id | • {{#if: UbuntuHelp:AptProxy|Bahasa Indonesia| [[::AptProxy/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/it | • {{#if: UbuntuHelp:AptProxy|italiano| [[::AptProxy/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ja | • {{#if: UbuntuHelp:AptProxy|日本語| [[::AptProxy/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ko | • {{#if: UbuntuHelp:AptProxy|한국어| [[::AptProxy/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ksh | • {{#if: UbuntuHelp:AptProxy|Ripoarisch| [[::AptProxy/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/mr | • {{#if: UbuntuHelp:AptProxy|मराठी| [[::AptProxy/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ms | • {{#if: UbuntuHelp:AptProxy|Bahasa Melayu| [[::AptProxy/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/nl | • {{#if: UbuntuHelp:AptProxy|Nederlands| [[::AptProxy/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/no | • {{#if: UbuntuHelp:AptProxy|norsk| [[::AptProxy/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/oc | • {{#if: UbuntuHelp:AptProxy|occitan| [[::AptProxy/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/pl | • {{#if: UbuntuHelp:AptProxy|polski| [[::AptProxy/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/pt | • {{#if: UbuntuHelp:AptProxy|português| [[::AptProxy/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ro | • {{#if: UbuntuHelp:AptProxy|română| [[::AptProxy/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/ru | • {{#if: UbuntuHelp:AptProxy|русский| [[::AptProxy/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/si | • {{#if: UbuntuHelp:AptProxy|සිංහල| [[::AptProxy/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/sq | • {{#if: UbuntuHelp:AptProxy|shqip| [[::AptProxy/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/sr | • {{#if: UbuntuHelp:AptProxy|српски / srpski| [[::AptProxy/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/sv | • {{#if: UbuntuHelp:AptProxy|svenska| [[::AptProxy/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/th | • {{#if: UbuntuHelp:AptProxy|ไทย| [[::AptProxy/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/tr | • {{#if: UbuntuHelp:AptProxy|Türkçe| [[::AptProxy/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/vi | • {{#if: UbuntuHelp:AptProxy|Tiếng Việt| [[::AptProxy/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/yue | • {{#if: UbuntuHelp:AptProxy|粵語| [[::AptProxy/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/zh | • {{#if: UbuntuHelp:AptProxy|中文| [[::AptProxy/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/zh-hans | • {{#if: UbuntuHelp:AptProxy|中文(简体)| [[::AptProxy/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:AptProxy | UbuntuHelp:AptProxy | {{#if: | :}}AptProxy}}/zh-hant | • {{#if: UbuntuHelp:AptProxy|中文(繁體)| [[::AptProxy/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:AptProxy|:AptProxy|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :AptProxy/zh | | {{#ifexist: AptProxy/zh | | {{#ifeq: {{#titleparts:AptProxy|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:AptProxy|1|-1|}} | zh | | }}
Introduction
apt-proxy is a program that caches the packages you download from the Internet, to your hard disk. Because apt-proxy behaves as if it were a HTTP server with a full copy of the repositories you select, you can access the packages from other computers on your network. If a package is not in the cache, apt-proxy automatically downloads and caches it. This can significantly decrease download bandwidth and installation time when you have to install the same packages repeatedly (i.e. an upgrade of multiple machines).
Installation
apt-proxy is available from the Universe archive. To install it, run this command from a terminal:
sudo apt-get install apt-proxy
Configuring apt-proxy Server
Default settings
The first section of the apt-proxy configuration file, located at /etc/apt-proxy/apt-proxy-v2.conf, contains the default settings for the apt-proxy and its cache.
The first step is to check the address
parameter to the IP of your apt-proxy server in the internal network. If it is commented out, apt-proxy will listen on all the IP addresses of your server. The port
parameter specifies the port apt-proxy listens on for requests and defaults to 9999, which is generally a good value to use.
If you wish to change the directory that apt-proxy stores its cached packages, change the cache_dir
parameter. The cache directory defaults to /var/cache/apt-proxy.
If you are using a web proxy server (such as Squid), you can configure apt-proxy to be aware of it with http_proxy = proxy_server:port
.
If you are behind a firewall you may experience problems with active FTP connections when trying to connect to a FTP backend. passive_ftp = on
should solve this problem.
The other values control the time a package remains in the cache, how old a package must be at least before apt-proxy checks for newer versions or how often the cache is checked for old packages. They can safely be left on their default values.
Backends
apt-proxy has to know where to find remote repositories, which it refers to as backends. This is done via backend sections in /etc/apt-proxy/apt-proxy-v2.conf. A backend entry for Ubuntu may look like this:
[ubuntu] ;; Ubuntu archive backends = http://archive.ubuntu.com/ubuntu http://de.archive.ubuntu.com/ubuntu
As you can see, it is possible to specify more than one server, separated by blank space. If the first server is down, apt-proxy tries to get the data from the second server and so on. Note: If the first server is up, but does not have a required file, apt-proxy will not fall back to a second server.
You can also override values set in the [default
-section. For instance, if you know that a special server takes very long to answer a request, you can increase the timeout value:
[ubuntu-slow] timeout = 60 ;wait 1 Minute backends = prot://some.very.slow.server.net/ubuntu-slow
A complete example apt-proxy-v2.conf may look like this:
[DEFAULT] ;; All times are in seconds, but you can add a suffix ;; for minutes(m), hours(h) or days(d) address = 127.0.0.1 port = 9999 cache_dir = /var/cache/apt-proxy ;; Control files (Packages/Sources/Contents) refresh rate min_refresh_delay = 1s complete_clientless_downloads = 1 ;; Debugging settings. debug = all:4 db:0 timeout = 30 passive_ftp = on ;;-------------------------------------------------------------- ;; Cache housekeeping cleanup_freq = 1d max_age = 120d max_versions = 3 ;;--------------------------------------------------------------- ;; Backend servers ;; ;; Place each server in its own [section] [ubuntu] ; Ubuntu archive backends = http://archive.ubuntu.com/ubuntu http://de.archive.ubuntu.com/ubuntu [ubuntu-security] ; Ubuntu security updates backends = http://security.ubuntu.com/ubuntu [marillat] backends = http://mirrors.ecology.uni-kiel.de/debian/debian-multimedia [debian] ; Backend servers, in order of preference backends = http://ftp.us.debian.org/debian http://ftp.de.debian.org/debian http://ftp2.de.debian.org/debian ftp://ftp.uk.debian.org/debian [debian-non-US] ; Debian debian-non-US archive backends = http://ftp.uk.debian.org/debian-non-US http://ftp.de.debian.org/debian-non-US ftp://ftp.uk.debian.org/debian [security] ; Debian security archive backends = http://security.debian.org/debian-security http://ftp2.de.debian.org/debian-security [openoffice] ; OpenOffice.org packages backends = http://ftp.freenet.de/pub/debian-openoffice http://ftp.sh.cvut.cz/MIRRORS/OpenOffice.deb http://borft.student.utwente.nl/debian [apt-proxy] ; Apt-proxy new versions backends = http://apt-proxy.sourceforge.net/apt-proxy
Note that you don't specify versions of distributions in this file; by enabling Ubuntu, you gain the ability to proxy for all versions (Hoary, Breezy, Dapper etc). What is downloaded depends on what is configured in the sources.list file on each client.
Initializing apt-proxy
After changing the apt-proxy configuration file, restart apt-proxy and update the list by running the following:
$ sudo /etc/init.d/apt-proxy restart
Your apt-proxy is ready for use.
Importing apt Cache
Note: In the current version of apt-proxy in the repositories (1.9.33ubuntu1), this might not work correctly. This is a known bug. Regardless, attempting this should not negatively impact your system. Packages already downloaded with apt-get, are cached in /var/cache/apt/archives. These packages can be imported into the apt-proxy cache with apt-proxy-import from the current package list. aptitude update should be run prior to apt-proxy-import to get a fresh list as follows:
$ sudo aptitude update $ sudo apt-proxy-import -r /var/cache/apt/archives
Updating clients to use your proxy server
apt clients need the /etc/apt/sources.list file to be reconfigured to point to the new apt-proxy server instead of the outside world. Configuration of the sources.list file looks similar to the config for normal apt repositories with the exception that the backend section has to be appended to the path:
deb http://apt-proxy:port/backend dist component
Replace mentions of specific repository URL with references to your server and the backend for it; such as:
deb http://archive.ubuntu.com/ubuntu dapper main restricted deb http://security.ubuntu.com/ubuntu dapper-security main restricted universe
would become
deb http://server:9999/ubuntu dapper main restricted deb http://server:9999/ubuntu-security dapper-security main restricted universe
A sources.list corresponding to the apt-proxy-v2.conf above may look like this:
# apt-proxy entries for standard modules deb http://localhost:9999/ubuntu dapper main restricted universe multiverse deb-src http://localhost:9999/ubuntu dapper main restricted universe multiverse # apt-proxy entries for security patches deb http://localhost:9999/ubuntu-security dapper-security main restricted universe multiverse deb-src http://localhost:9999/ubuntu-security dapper-security main restricted universe multiverse
Troubleshooting
Problems with acquiring packages
In Dapper Drake, other Ubuntu computers connecting to the proxy may have problems receiving the file headers of the repository list. If this happens to you, on the computers connecting to the proxy, edit /etc/apt/apt.conf, with:
sudo nano /etc/apt/apt.conf
or your choice of text editor. It will likely be
Acquire::http::Proxy "false";
change this to
Acquire::Proxy "false";
and save, exit, and try updating the repositories file list again with
sudo apt-get update
or any other method that updates the repositories (such as Check in Update Manager or Reload in Synaptic). It should load correctly now.
Connection Refused
On some setups, the proxy is not available to external machines. The proxy works very well on localhost, but fails to cooperate with external machines.