在没有互联网连接的服务器上下载并安装 ubuntu 软件包和依赖项

Adr*_*jan 5 package-management offline

我正在尝试在具有有效互联网连接的服务器上下载所有软件包和所需的依赖项,并将它们传输到没有互联网连接的服务器上,然后通过 apt-get 安装它们。

我有两种下载包的解决方案:

  1. apt-get --print-uris --yes install pkgspec | grep ^\' | cut -d\' -f2 > downloads.list
    
    Run Code Online (Sandbox Code Playgroud)

毫无用处,因为它仅适用于尚未下载并安装在具有有效互联网连接的服务器上的包和依赖项。

  1. aptitude download '?reverse-depends(package)'
    
    Run Code Online (Sandbox Code Playgroud)

如果您不需要,它也会下载所有包和依赖项。

有人知道在全新安装的 Ubuntu 服务器 16.04 上下载软件包和依赖项的更好解决方案吗?

我想创建一个脚本,该脚本遍历包列表并自动下载所有包和依赖项。

然后我需要一个解决方案来通过 apt-get 在离线计算机上使用这个软件包。想法是创建一个本地 apt 存储库,允许您通过 apt-get 使用本地包。

因此,我使用此命令创建 Packages.gz,其中包含有关第一步下载的所有包的信息。

dpkg-scanpackages . /dev/null | gzip > Packages.gz
Run Code Online (Sandbox Code Playgroud)

然后我将新源添加到 /etc/apt/sources.list.d/ 并运行 apt-get update。

deb [trusted=yes] file:///tmp/dpkgs /
Run Code Online (Sandbox Code Playgroud)

现在我有一个问题,例如我可以安装 apache (仍然有一些错误)。但是如果我想安装 php 我收到以下错误。

root@ubuntu:~# apt-get install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php : Depends: php7.0 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
Run Code Online (Sandbox Code Playgroud)

有人对这个问题有可行的解决方案吗?谢谢。

Joe*_*Joe 0

我从来没有尝试过这个,所以 YMMV。

查看这个apt-offline

他们声称完全按照您的意愿行事。


小智 0

我的建议是使用 ssh 隧道,我假设您正在通过具有互联网连接的计算机通过 SSH 连接登录到服务器,因此您可以尝试使用反向隧道来至少访问您想要的存储库...请遵循这些脚步:

  1. 使用以下命令登录到您的服务器:

    ssh -R 127.0.0.1:9800:yourrepo.address:80 youruser@ServerWithoutInternetConnectionAddress
    
    Run Code Online (Sandbox Code Playgroud)
  2. 登录服务器后,将以下行添加到 /etc/hosts 中:

    127.0.0.1 yourrepo.adress
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在您的存储库配置文件中/etc/apt/sources.list或中/etc/apt/sources.list.d/repofile.list通过添加使用的端口来修改您的存储库地址(我使用了 9800,尽管它可以是高于 1023 的任何端口):

    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial-updates main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-java/ xenial main
    deb [arch=amd64] http://yourrepo.address:9800/ubuntu-production/ xenial multiverse
    
    Run Code Online (Sandbox Code Playgroud)

现在apt-get update应该apt-get install可以工作了。请考虑,您可以拥有与存储库一样多的隧道,您只需要更改源端口。

例如,考虑到您有官方的 ubuntu 存储库/etc/apt/sources.list和其他存储库,/etc/apt/sources.list.d/repofile.list我可以使用端口 9801us.archive.ubuntu.com和端口 9800 ,/etc/apt/sources.list.d/repofile.list如下所示:

/etc/apt/sources.list

deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial main restricted universe multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial main restricted multiverse
deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial-security main restricted universe multiverse
deb http://us.archive.ubuntu.com:9801/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial-security main restricted multiverse
deb-src http://us.archive.ubuntu.com:9801/ubuntu/ xenial-updates main restricted multiverse
Run Code Online (Sandbox Code Playgroud)

/etc/apt/sources.list

deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-mirror/ xenial-updates main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-java/ xenial main
deb [arch=amd64] http://yourrepo.address:9800/ubuntu-production/ xenial multiverse
Run Code Online (Sandbox Code Playgroud)

通过将此添加到/etc/hosts

127.0.0.1     yourrepo.adress      us.archive.ubuntu.com
Run Code Online (Sandbox Code Playgroud)

并从具有互联网连接的计算机登录,如下所示:

ssh -R 127.0.0.1:9800:yourrepo.address:80 -R 127.0.0.1:9801:us.archive.ubuntu.com:80 youruser@ServerWithoutInternetConnectionAddress
Run Code Online (Sandbox Code Playgroud)

PS:考虑一下,如果您的存储库需要密钥,您将需要提取密钥(从具有密钥的计算机apt-key export KEY_ID >> key.asc)并使用以下命令添加它:

apt-key add key.asc
Run Code Online (Sandbox Code Playgroud)