Centos设置代理的方法
最近有一个 VPS 服务器需要访问 Github ,众所周知,国内网络的原因,无法直接访问,最简单的解决方法是用代理,下面我介绍一下如何在 centos 系统中设置代理(同样也适用于其他 Linux 发行版)
一、设置全局 http、https、ftp 协议的代理(临时生效) 打开终端输入下面的命令:
export http_proxy="http://username:password@proxy_ip:port"
export https_proxy="http://username:password@proxy_ip:port"
export ftp_proxy="http://username:password@proxy_ip:port"
复制 如果没有账号密码,只写代理服务器的 IP 地址和端口即可:
export http_proxy="http://proxy_ip:port"
export https_proxy="http://proxy_ip:port"
export ftp_proxy="http://proxy_ip:port"
复制 此方法可以临时通过代理进行上网,待重启、或重新连接后,代理配置失效。 手动取消代理:
unset http_proxy
unset https_proxy
unset ftp_proxy
复制 二、设置全局 http、https、ftp 协议的代理(永久生效) 1、编辑配置文件:
vi /etc/profile
复制 2、在配置文件的末尾添加代理配置:
export http_proxy="http://username:password@proxy_ip:port"
export https_proxy="http://username:password@proxy_ip:port"
export ftp_proxy="http://username:password@proxy_ip:port"
复制 如果没有账号密码,只写代理服务器的 IP 地址和端口即可:
export http_proxy="http://proxy_ip:port"
export https_proxy="http://proxy_ip:port"
export ftp_proxy="http://proxy_ip:port"
复制 3、使配置文件生效
source /etc/profile
复制 三、设置 yum 代理 1、修改 yum.conf 文件:
vi /etc/yum.conf
复制 2、在 yum.conf 文件末尾添加代理配置:
export http_proxy="http://username:password@proxy_ip:port"
export https_proxy="http://username:password@proxy_ip:port"
export ftp_proxy="http://username:password@proxy_ip:port"
免费代理IP有很多自行查找:
也可以安装其它软件使用一些免费IP
安装unzip
yum install -y unzip zip
wget https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh
bash install-release.sh
开启服务
systemctl enable v2ray
systemctl start v2ray
systemctl status v2ray
绿色或者黄色小灯亮起(running)表示已成功运行,修改配置文件
vi /usr/local/etc/v2ray/config.json
也可以将你本地的直接上传使用,重启服务
systemctl stop v2ray
systemctl start v2ray
设置到需要使用的方式即可