前言
由于网络原因,导致国内下载某些国外的包或者GitHub等网站上的文件非常慢的情况,这里记录一下工作中常用的几种需要设置代理来加速访问的方式。
开始之前,先假设我这里已经部署好了代理,地址:
一、为wget命令设置代理
1.1、临时方式
export JQ_VERSION=1.6wget -e use_proxy=yes \-e http_proxy="hkproxy.bunian.cn:62200" \-e https_proxy="hkproxy.bunian.cn:62200" \-e HTTP_PROXY="hkproxy.bunian.cn:62200" \-e HTTPS_PROXY="hkproxy.bunian.cn:62200" \-e no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" \https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64export JQ_VERSION=1.6 wget -e use_proxy=yes \ -e http_proxy="hkproxy.bunian.cn:62200" \ -e https_proxy="hkproxy.bunian.cn:62200" \ -e HTTP_PROXY="hkproxy.bunian.cn:62200" \ -e HTTPS_PROXY="hkproxy.bunian.cn:62200" \ -e no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" \ https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64export JQ_VERSION=1.6 wget -e use_proxy=yes \ -e http_proxy="hkproxy.bunian.cn:62200" \ -e https_proxy="hkproxy.bunian.cn:62200" \ -e HTTP_PROXY="hkproxy.bunian.cn:62200" \ -e HTTPS_PROXY="hkproxy.bunian.cn:62200" \ -e no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" \ https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64
1.2、永久方式
1.2.1、针对用户而言
vi ~/.wgetrchttp_proxy="hkproxy.bunian.cn:62200"https_proxy="hkproxy.bunian.cn:62200"HTTP_PROXY="hkproxy.bunian.cn:62200"HTTPS_PROXY="hkproxy.bunian.cn:62200"no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxysource ~/.wgetrcvi ~/.wgetrc http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source ~/.wgetrcvi ~/.wgetrc http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source ~/.wgetrc
1.2.2、针对整个系统而言
vi /etc/wgetrchttp_proxy="hkproxy.bunian.cn:62200"https_proxy="hkproxy.bunian.cn:62200"HTTP_PROXY="hkproxy.bunian.cn:62200"HTTPS_PROXY="hkproxy.bunian.cn:62200"no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxysource /etc/wgetrcvi /etc/wgetrc http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/wgetrcvi /etc/wgetrc http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/wgetrc
二、设置系统代理
2.1、为当前登录用户设置代理
vi ~/.bash_profilehttp_proxy="hkproxy.bunian.cn:62200"https_proxy="hkproxy.bunian.cn:62200"HTTP_PROXY="hkproxy.bunian.cn:62200"HTTPS_PROXY="hkproxy.bunian.cn:62200"no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxysource /etc/profilevi ~/.bash_profile http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/profilevi ~/.bash_profile http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/profile
2.2、为系统范围内所有用户设置代理
vi /etc/profilehttp_proxy="hkproxy.bunian.cn:62200"https_proxy="hkproxy.bunian.cn:62200"HTTP_PROXY="hkproxy.bunian.cn:62200"HTTPS_PROXY="hkproxy.bunian.cn:62200"no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxysource /etc/profilevi /etc/profile http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/profilevi /etc/profile http_proxy="hkproxy.bunian.cn:62200" https_proxy="hkproxy.bunian.cn:62200" HTTP_PROXY="hkproxy.bunian.cn:62200" HTTPS_PROXY="hkproxy.bunian.cn:62200" no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy source /etc/profile
温馨提示: 如果不生效,就将export命令放在每一个命令前面。
如:
以上是不需要设置代理的用户名、密码的方式。如果要设置该怎么解决?
http_proxy=http://username:password@hkproxy.bunian.cn:62200 wget http://file.bunian.com/test.txthttps_proxy=http://username:password@hkproxy.bunian.cn:62200 wget https://file.bunian.com/test.txt# wgetrc或者/etc/profile文件中设置http_proxy = http://uname:passwd@hkproxy.bunian.cn:62200https_proxy = http://uname:passwd@hkproxy.bunian.cn:62200use_proxy = onhttp_proxy=http://username:password@hkproxy.bunian.cn:62200 wget http://file.bunian.com/test.txt https_proxy=http://username:password@hkproxy.bunian.cn:62200 wget https://file.bunian.com/test.txt # wgetrc或者/etc/profile文件中设置 http_proxy = http://uname:passwd@hkproxy.bunian.cn:62200 https_proxy = http://uname:passwd@hkproxy.bunian.cn:62200 use_proxy = onhttp_proxy=http://username:password@hkproxy.bunian.cn:62200 wget http://file.bunian.com/test.txt https_proxy=http://username:password@hkproxy.bunian.cn:62200 wget https://file.bunian.com/test.txt # wgetrc或者/etc/profile文件中设置 http_proxy = http://uname:passwd@hkproxy.bunian.cn:62200 https_proxy = http://uname:passwd@hkproxy.bunian.cn:62200 use_proxy = on
三、为apt-get设置代理
3.1、临时方式
export http_proxy=http://hkproxy.bunian.cn:62200export https_proxy=http://hkproxy.bunian.cn:62200export HTTP_PROXY=http://hkproxy.bunian.cn:62200export HTTPS_PROXY=http://hkproxy.bunian.cn:62200export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"apt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY updateapt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY install -y vim python3 python3-pipexport http_proxy=http://hkproxy.bunian.cn:62200 export https_proxy=http://hkproxy.bunian.cn:62200 export HTTP_PROXY=http://hkproxy.bunian.cn:62200 export HTTPS_PROXY=http://hkproxy.bunian.cn:62200 export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" apt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY update apt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY install -y vim python3 python3-pipexport http_proxy=http://hkproxy.bunian.cn:62200 export https_proxy=http://hkproxy.bunian.cn:62200 export HTTP_PROXY=http://hkproxy.bunian.cn:62200 export HTTPS_PROXY=http://hkproxy.bunian.cn:62200 export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" apt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY update apt-get -o Acquire::http::proxy=$HTTP_PROXY -o Acquire::https::proxy=$HTTPS_PROXY install -y vim python3 python3-pip
3.2、永久方式
# 方法一:touch /etc/apt/apt.conf.d/proxy.confvi /etc/apt/apt.conf.d/proxy.confAcquire::http::Proxy "http://user:password@hkproxy.bunian.cn:62200/";Acquire::https::Proxy "http://user:password@hkproxy.bunian.cn:62200";# 方法二touch /etc/apt/apt.conf.d/proxy.confvi /etc/apt/apt.conf.d/proxy.confAcquire {HTTP::proxy "http://hkproxy.bunian.cn:62200";HTTPS::proxy "http://hkproxy.bunian.cn:62200";}# 方法一: touch /etc/apt/apt.conf.d/proxy.conf vi /etc/apt/apt.conf.d/proxy.conf Acquire::http::Proxy "http://user:password@hkproxy.bunian.cn:62200/"; Acquire::https::Proxy "http://user:password@hkproxy.bunian.cn:62200"; # 方法二 touch /etc/apt/apt.conf.d/proxy.conf vi /etc/apt/apt.conf.d/proxy.conf Acquire { HTTP::proxy "http://hkproxy.bunian.cn:62200"; HTTPS::proxy "http://hkproxy.bunian.cn:62200"; }# 方法一: touch /etc/apt/apt.conf.d/proxy.conf vi /etc/apt/apt.conf.d/proxy.conf Acquire::http::Proxy "http://user:password@hkproxy.bunian.cn:62200/"; Acquire::https::Proxy "http://user:password@hkproxy.bunian.cn:62200"; # 方法二 touch /etc/apt/apt.conf.d/proxy.conf vi /etc/apt/apt.conf.d/proxy.conf Acquire { HTTP::proxy "http://hkproxy.bunian.cn:62200"; HTTPS::proxy "http://hkproxy.bunian.cn:62200"; }
四、为pip配置代理
4.1、临时方式
# 方式一export hkproxy.bunian.cn:62200pip3 install kubernetes# 方式二pip install --proxy=https://username:password@hkproxy.bunian.cn:62200 kubernetespip3 install --proxy hkproxy.bunian.cn:62200 kubernetes# 方式一 export hkproxy.bunian.cn:62200 pip3 install kubernetes # 方式二 pip install --proxy=https://username:password@hkproxy.bunian.cn:62200 kubernetes pip3 install --proxy hkproxy.bunian.cn:62200 kubernetes# 方式一 export hkproxy.bunian.cn:62200 pip3 install kubernetes # 方式二 pip install --proxy=https://username:password@hkproxy.bunian.cn:62200 kubernetes pip3 install --proxy hkproxy.bunian.cn:62200 kubernetes
4.2、永久方式
vi ~/.bashrcHTTP_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200HTTPS_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200export HTTP_PROXY HTTPS_PROXYsource ~/.bashrcvi ~/.bashrc HTTP_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200 HTTPS_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200 export HTTP_PROXY HTTPS_PROXY source ~/.bashrcvi ~/.bashrc HTTP_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200 HTTPS_PROXY=http://<usr_name>:<password>@hkproxy.bunian.cn:62200 export HTTP_PROXY HTTPS_PROXY source ~/.bashrc
取消临时代理
上面一直在说设置代理,那如果我们临时设置了代理以后,用完后又需要取消代理设置怎么办?方法如下:
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxyunset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxyunset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy
© 版权声明
本站文章由不念博客原创,未经允许严禁转载!
THE END