配置全局代理

您可以在 Cumulus Linux 的 /etc/profile.d/ 目录中配置 全局 HTTP 和 HTTPS 代理。设置 http_proxyhttps_proxy 变量,以使用您要用于在命令行上获取 URL 的代理服务器地址配置交换机。这对于 aptapt-getcurlwget 等程序非常有用,这些程序都可以使用此代理。

  1. 在终端中,在 /etc/profile.d/ 目录中创建一个新文件。

    cumulus@switch:~$ sudo nano /etc/profile.d/proxy.sh
    
  2. 向文件中添加一行以配置 HTTP 或 HTTPS 代理,或两者都配置

    • HTTP 代理

      http_proxy=http://myproxy.domain.com:8080
      export http_proxy
      
    • HTTPS 代理

      https_proxy=https://myproxy.domain.com:8080
      export https_proxy
      
  3. /etc/apt/apt.conf.d 目录中创建一个文件,并将以下行添加到文件中以获取 HTTP 和 HTTPS 代理。以下示例使用 http_proxy 作为文件名

    cumulus@switch:~$ sudo nano /etc/apt/apt.conf.d/http_proxy
    Acquire::http::Proxy "http://myproxy.domain.com:8080";
    Acquire::https::Proxy "https://myproxy.domain.com:8080";
    
  4. 将代理地址添加到 /etc/wgetrc 文件,然后取消注释 http_proxyhttps_proxy 行(如果需要)

    cumulus@switch:~$ sudo nano /etc/wgetrc
    ...
    https_proxy = https://myproxy.domain.com:8080
    http_proxy = http://myproxy.domain.com:8080
    ...
    
  5. 要在当前环境中执行 /etc/profile.d/proxy.sh 文件,请运行 source 命令

    cumulus@switch:~$ source /etc/profile.d/proxy.sh
    

使用 echo 命令确认配置

  • HTTP 代理

    cumulus@switch:~$ echo $http_proxy
    http://myproxy.domain.com:8080
    
  • HTTPS 代理

    cumulus@switch:~$ echo $https_proxy
    https://myproxy.domain.com:8080
    

设置 apt 软件包缓存