有时候, 我们无法直接连接外部网络, 可能需要连接代理服务器, 才能访问外网, 进行软件包安装, 程序升级, 此时我们需要配置一些代理设置, 这样才能保证网络正常.
一, 全局服务器环境变量
置全局代理, 方法如下:
修改 /etc/profile 文件, 添加下面内容:
- http_proxy=http://username:[email protected]:8080/
- ftp_proxy=http://username:[email protected]:8080/
- export http_proxy
- export ftp_proxy
如果没有密码限制, 则以上内容可以修改为以下内容:
- http_proxy=http://yourproxy:8080/
- ftp_proxy=http://yourproxy:8080/
- export http_proxy
- export ftp_proxy
若只针对某个用户而言, 则修改 ~/.bash_profile 文件, 添加相同内容;
修改完成后, 注销重新登录即可.
二, yum 代理设置
用 vi 编辑器打开 yum 配置文件, 一般情况下: vi /etc/yum.conf
打开 yum 的配置文件之后, 在文件最后加上代理服务器的协议, 地址, 端口, 如果代理服务器需要用户认证话, 同时加上认证用户的用户名和密码.
代理服务器不需要认证: 加上 proxy = 协议:// 代理服务器地址: 端口 (如: proxy=http://192.168.1.1:80 http://192.168.1.1/ )
代理服务器需要认证用户: 加上 proxy = 协议:// 代理服务器地址: 端口 (如: proxy=http://192.168.1.1:80 http://192.168.1.1/ )
proxy_username = 代理服务器用户名
proxy_password = 代理服务器密码
保存退出后, 就可以使用 yum 轻松的安装软件了.
三, Git 代理设置
- Git config --global https.proxy https://proxyuser:[email protected]/ 域名: port
- Git config --global http.proxy http://proxyuser:[email protected]/ 域名: port
示例:
假设某人在百度工作, 公司代理服务器是(proxy.baidu.com), 端口是(8080), 代理配置如下
1, 代理服务器需要鉴权配置
Git config --global https.proxy https://username:[email protected]:8080
2, 代理服务器不需要鉴权配置
Git config --global https.proxy https://proxy.baidu.com:8080
四, 代理配置中的一些特殊字符
如果密码中有 @等特殊字符, 会出错, 比如
Git config --global http.proxy http://username:[email protected]@proxy.baidu.com:8080 http://username:abc@123@proxy.baidu.com:8080/
解析时会从第一个 @解析, 提示 @[email protected]找不到, 此时要对其中的特殊符号进行处理, 使用百分比编码 (Percent-encoding) 对特殊字符进行转换, 转换.
列表如下:
- ! --> %21 # --> # $ --> $ & --> & ' --> '
- ( --> %28 ) --> %29 * --> %2A + --> %2B , --> %2C
- / --> %2F : --> %3A ; --> %3B = --> %3D ? --> %3F
- @ --> %40 [ --> %5B ] --> %5D
例如: br/>代理账户: admin
代理密码:[email protected]
@为特殊字符
代理服务器: http://172.31.101.102:8080/
进行全局代理的时候, 需要按照如下配置
http://admin:abc%[email protected]:8080 http://admin:abc@123@172.31.101.120:8080/
来源: http://www.bubuko.com/infodetail-3324571.html