全局proxy
更新 /etc/environment
http_proxy=http://10.0.0.1:8080
https_proxy=http://10.0.0.1:8080
ftp_proxy=http://10.0.0.1:8080
no_proxy="127.0.0.1,localhost"
也可以更新 /etc/profile, /etc/environment是设置整个系统的环境,而/etc/profile是设置所有用户的环境,前者与登录用户无关,后者与登录用户有关。
但profile 中写法不一样
export http_proxy=http://10.0.0.1:8080
export https_proxy=http://10.0.0.1:8080
export ftp_proxy=http://10.0.0.1:8080
export no_proxy="127.0.0.1,localhost"
ubuntu apt repo proxy
更新 /etc/apt/apt.conf
Acquire::http::proxy "http://10.0.0.1:8080/";
Acquire::ftp::proxy "http://10.0.0.1:8080/";
Acquire::https::proxy "http://10.0.0.1:8080/";
Acquire::http::proxy::192.168.34.77 DIRECT; ## 访问这个IP 不走proxy,直接访问,相当于no_proxy
centos yum repo proxy
update /etc/yum.conf
proxy=10.0.0.1:8080
如果要认证
proxy=10.0.0.1:8080
proxy_username=aaa
proxy_password=bbb
pip proxy
可以直接读取系统的代理设置。
如果没有设置,可以用下面的方法手工设置一下
export https_proxy=https://username:password@proxyserver:port
然后就可以安装了
pip install somepackage
也可以直接在命令行中直接指定proxy
pip install --proxy=https://[username:password@]proxyserver:port somepackage
current bash shell
export http_proxy=xxxxxx
Docker proxy
User level
On the Docker client, create or edit the file ~/.docker/config.json
in the home directory of the user which starts containers.
{
"proxies":
{
"default":
{
"httpProxy": "http://127.0.0.1:3001",
"httpsProxy": "http://127.0.0.1:3001",
"noProxy": "*.test.example.com,.example2.com"
}
}
}
Docker daemon level
-
Create a systemd drop-in directory for the docker service:
sudo mkdir -p /etc/systemd/system/docker.service.d
-
Create a file named
/etc/systemd/system/docker.service.d/http-proxy.conf
that adds theHTTP_PROXY
environment variable:[Service] Environment="HTTP_PROXY=http://proxy.example.com:80" Environment="HTTPS_PROXY=https://proxy.example.com:443" Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
-
Flush changes and restart Docker
sudo systemctl daemon-reload sudo systemctl restart docker
-
Verify that the configuration has been loaded and matches the changes you made, for example:
sudo systemctl show --property=Environment docker Environment=HTTP_PROXY=http://proxy.example.com:80 HTTPS_PROXY=https://proxy.example.com:443 NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp
网友评论