

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在代理服务器中运行程序包管理器和其他工具
<a name="use-proxy-server-tools"></a>

按照以下过程在代理服务器中运行软件包管理器和其他工具。

**要在代理服务器中运行一个工具，如程序包管理器，请执行以下操作：**

1.  通过将语句添加到您的 `squid.conf` 文件中，将该工具添加到代理服务器的允许列表中。

1.  在 buildspec 文件中添加指向代理服务器的私有终端节点的命令行。

 以下示例演示了如何为 `apt-get`、`curl` 和 `maven` 执行此操作。如果您使用其他工具，则相同的原则将适用。将其添加到`squid.conf`文件中的允许列表中，然后在 buildspec 文件中添加命令以 CodeBuild 了解代理服务器的端点。

**在代理服务器中运行 `apt-get`**

1. 将以下语句添加到您的 `squid.conf` 文件中，以便将 `apt-get` 添加到代理服务器中的允许列表。前三行允许 `apt-get` 在构建环境中运行。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required for apt-get to run in the build environment
   acl apt_get dstdom_regex .*\.launchpad.net # Required for CodeBuild to run apt-get in the build environment
   acl apt_get dstdom_regex .*\.ubuntu.com    # Required for CodeBuild to run apt-get in the build environment
   http_access allow localnet allowed_sites
   http_access allow localnet apt_get
   ```

1. 在构建规范文件中添加以下语句，以便 `apt-get` 命令在 `/etc/apt/apt.conf.d/00proxy` 中查找代理配置。

   ```
   echo 'Acquire::http::Proxy "http://<private-ip-of-proxy-server>:3128"; Acquire::https::Proxy "http://<private-ip-of-proxy-server>:3128"; Acquire::ftp::Proxy "http://<private-ip-of-proxy-server>:3128";' > /etc/apt/apt.conf.d/00proxy
   ```

**在代理服务器中运行 `curl`**

1.  将以下内容添加到您的 `squid.conf` 文件中，以便将 `curl` 添加到构建环境中的允许列表。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment
   acl allowed_sites dstdomain google.com # Required for access to a webiste. This example uses www.google.com.
   http_access allow localnet allowed_sites
   http_access allow localnet apt_get
   ```

1.  在 buildspec 文件中添加以下语句，以便 `curl` 使用专用代理服务器访问您添加到 `squid.conf` 的网站。在此示例中，网站为 `google.com`。

   ```
   curl -x <private-ip-of-proxy-server>:3128 https://www.google.com
   ```

**在代理服务器中运行 `maven`**

1.  将以下内容添加到您的 `squid.conf` 文件中，以便将 `maven` 添加到构建环境中的允许列表。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment
   acl maven dstdom_regex .*\.maven.org # Allows access to the maven repository in the build environment
   http_access allow localnet allowed_sites
   http_access allow localnet maven
   ```

1. 在 buildspec 文件中添加以下语句。

   ```
   maven clean install -DproxySet=true -DproxyHost=<private-ip-of-proxy-server> -DproxyPort=3128
   ```