本文中的
proxyhost
替换为自己的代理服务器地址(IP或者域名);port
替换为自己的代理服务器地址
apt-get 配置代理
在当前用户主目录下执行以下命令配置代理相关信息。
echo 'Acquire::http::proxy "http://proxyhost:port";
Acquire::https::proxy "http://proxyhost:port";' >> ~/apt-proxy.conf
配置完成之后,在执行apt
命令的时候,使用-c
指定配置文件路径即可。
apt-get命令 -c参数(点击查看)
-c, --config-file
Configuration File; Specify a configuration file to use. The program will read the default configuration file and then this configuration file. If configuration
settings need to be set before the default configuration files are parsed specify a file with the APT_CONFIG environment variable. See apt.conf(5) for syntax
information.
sudo apt-get -c ~/apt-proxy.conf update
yum 配置代理
sudo echo 'http_proxy=http://proxyhost:port
# proxy_username=
# proxy_password=' >> /etc/yum.conf
wget 配置代理
在终端执行以下命令配置wget代理;use_proxy
的值为on
表示启用代理,值为off
表示关闭代理。
echo 'http_proxy = http://proxyhost:port
https_proxy = http://proxyhost:port
# proxy_username=
# proxy_password=
use_proxy = on' >> ~/.wgetrc
Docker 配置代理
创建配置文件目录(若配置文件目录/etc/systemd/system/docker.service.d
已存在,忽略该步骤)
sudo mkdir -p /etc/systemd/system/docker.service.d
新建配置文件(若配置文件/etc/systemd/system/docker.service.d/proxy.conf
已存在,忽略该步骤)
sudo touch /etc/systemd/system/docker.service.d/proxy.conf
在终端执行以下命令配置代理服务器配置信息。
sudo echo '[Service]
Environment="HTTP_PROXY=http://proxyhost:port"
Environment="HTTPS_PROXY=http://proxyhost:port"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"' >> /etc/systemd/system/docker.service.d/proxy.conf
重载systemd
并重启dockerd
,使代理生效。
sudo systemctl daemon-reload
sudo systemctl restart docker.service
Linux系统全局代理配置
通过配置环境变量给Linux系统全局配置代理,可以免去为apt-get
wget
docker
等服务单独配置代理。
zsh
配置文件:.zshrc
;bash
配置文件:.bashrc
。根据当前SHELL配置相关的配置文件。
echo 'export http_proxy="http://proxyhost:port";
export https_proxy="http://proxyhost:port";' >> ~/.zshrc
配置完成后,重载配置文件使配置立即生效。
source ~/.zshrc