APT、PIP、CURL代理配置, 代理上网
CURL
对于CURL
使用 http 代理:
shell
export http_proxy="http://172.16.16.122:3128";
export https_proxy="https://172.16.16.122:3128";
使用 socks5 代理:
shell
export http_proxy="socks5://172.16.16.122:3128";
export https_proxy="socks5://172.16.16.122:3128";
将上述命令写入 /etc/profile
或 ~/.bashrc
文件,然后执行source /etc/profile
OR source ~/.bashrc
即可。
APT
对于APT
你已经得到了关于如何通过代理服务器进行APT更新的说明,这里我再概述一遍:
在服务器A上安装并配置好Squid代理服务器。
在服务器B上配置APT代理,创建或编辑/etc/apt/apt.conf.d/02proxy.conf
文件,并添加:
shell
Acquire::http::Proxy "http://172.16.16.122:3128";
Acquire::https::Proxy "https://172.16.16.122:3128";
注意,HTTPS代理可能需要 ProxyServer 进行额外的SSL配置。
apt使用socks5代理
在/etc/apt/apt.conf.d
下新建proxy.conf
,输入
shell
Acquire::http::Proxy "socks5h://172.17.0.1:3210";
Acquire::https::Proxy "socks5h://172.17.0.1:3210";
Acquire::socks::Proxy "socks5h://172.17.0.1:3210";
注意: apt 使用 socks5 前缀是 socks5h
YUM
注意: 设置 http_proxy
环境变量,并不能达到让yum能连外网。yum连外网有自已的设置方法。
为 /etc/yum.repos.d/
下的所有仓库设置代理,则可以修改 /etc/yum.conf
文件,在该文件尾部添加如下一行:
ini
proxy=http://ip:port
proxy_username=USERNAME
proxy_password=PASSWORD
Socks5代理:
ini
proxy=socks5://your_ip:port
清理 yum 缓存:
shell
yum clean all
yum makecache
PIP
对于PyPI
对于Python包管理器,你需要配置pip以使用代理。在服务器B上,你可以为pip添加代理设置:
在用户主目录下创建或编辑$HOME/.pip/pip.conf
(对于全局配置则是/etc/pip.conf
),添加:
ini
[global]
proxy = http://172.16.16.122:3128
pip 只支持 http 代理,不支持 socks 代理。