Linux proxy 设置

Linux proxy 设置

全局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"

用户级别proxy

~/.bashrc

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

curl proxy

可以直接读取系统的代理设置。

也可以在命令中用 -x 参数指定

curl -x http://10.0.0.1:8080/ www.google.com

socks5 proxy

curl -x socks5://proxy.example.com http://www.example.com/

curl --socks5 proxy.example.com http://www.example.com/

current bash shell

export http_proxy=xxxxxx

Configure Docker to use a proxy server

User level

适用于 container 里面,需要proxy 连接。

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

这个设置用于docker pull,container 里面如果需要用到proxy 需要 user level 设置。

  1. Create a systemd drop-in directory for the docker service:

    sudo mkdir -p /etc/systemd/system/docker.service.d
    
  2. Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_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"
    
  3. Flush changes and restart Docker

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  4. 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
    

gitlab runner proxy

官方文档

$ cat /etc/systemd/system/gitlab-runner.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://www-proxy.xxx.com:8080/"
Environment="HTTPS_PROXY=http://www-proxy.xxx.com:8080/"

maven proxy

用户环境 ~/.m2/settings.xml


....
  
   
      proxy
      true
      http
      www-proxy.xxx.com
      8080
    
  

你可能感兴趣的:(Linux proxy 设置)