全局
vi /etc/profile
#无用户名密码
export http_proxy=http://proxy_ip:prot
export https_proxy=https://proxy_ip:prot
#有用户名密码
export http_proxy=http://username:password@proxy_ip:prot
export https_proxy=https://username:password@proxy_ip:port
export ftp_proxy=http://username:password@proxyserver:port
如
export http_proxy=http://192.168.64.1:1080
export https_proxy=http://192.168.64.1:1080
# 或者建议这样配置
http_proxy=proxy.abc.com:8080
https_proxy=$http_proxy
ftp_proxy=user:password@proxy.abc.com:8080
no_proxy=*.abc.com,10.*.*.*,192.168.*.*,*.local,localhost,127.0.0.1
export http_proxy https_proxy ftp_proxy no_proxy
其中:
- http_proxy:http协议使用服务器地址;
- https_proxy:https协议使用安全地址;
- ftp_proxy:ftp协议使用服务器地址;
- user:使用的用户名;
- password:使用用户名的密码;
- proxy.abc.com:地址,可以是IP,也可以是域名;
- 8080:使用的端口;
- no_proxy:不使用主机或IP。
备注:
环境变量 | 描述 | 值示例 |
---|---|---|
http_proxy | 为http变量设置;默认不填开头以http协议传输 | 10.0.0.51:8080 user:pass@10.0.0.10:8080 socks4://10.0.0.51:1080 socks5://192.168.1.1:1080 |
https_proxy | 为https变量设置; | 同上 |
ftp_proxy | 为ftp变量设置; | 同上 |
all_proxy | 全部变量设置,设置了这个时候上面的不用设置 | 同上 |
no_proxy | 无需主机或域名; 可以使用通配符; 多个时使用“,”号分隔; | *.aiezu.com,10.*.*.*, 192.168.*.*,*.local,localhost,127.0.0.1 |
1、在/etc/profile文件 | ||
2、在~/.bashrc | ||
3、在~/.zshrc | ||
4、在/etc/profile.d/文件夹下新建一个文件xxx.sh |
写入如下配置:
export proxy="http://192.168.5.14:8118"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost, 127.0.0.1, ::1"
而对于要取消设置可以使用如下命令,其实也就是取消环境变量的设置:
unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy
生效配置文件
source /etc/profile
. /etc/profile
echo $http_proxy
echo $https_proxy
测试
因为
subversion的服务器配置
要配置subversion的服务器,需要修改$HOME/.subversion/servers文件,在此文件的[global]段加上:
http-proxy-host = 192.168.1.1
http-proxy-port = 8080
http-proxy-username = easwy
http-proxy-password = 123456
现在svn就可以使用服务器访问版本库了。
yum的服务器配置
针对yum配置:
经过测试其实只要设置上面的变量之后已经可以,但如果要单独设置,可以设置如下文件的变量:echo "proxy=http://127.0.0.1:8080/" >> /etc/yum.conf
如果想让CentOS中的yum可以通过服务器更新程序,则需要修改文件/etc/yum.conf,在此文件中加上:
proxy=http://easwy:123456@192.168.1.1:8080