踩雷记录->虚拟机代理设置

事故起因

因为一些特殊原因,需要编译v8(Java引擎),应用在嵌入式设备中。

事发过程

按照google上 编译v8引擎的教程走,总是dead 在 “ gclient sync ” 这一步。

事故原因

代理设置不正确。
原来使用的代理是从主机VPN过来的,主机VPN只能通过socks协议走到虚拟机上。虽然这种办法能完成 gclient sync 的百分之七八十,但是最后剩下的一点办法也没有。

解决办法

虚拟机通过 privoxy 将 socks 协议转成 http 出去。

验证方法 wget www.google.com

成功的话,得到提示获取 index.html.1
请勿问为啥不用 ping www.google.com, 因为我现在也还 ping 不到。emo...

配置步骤

1. 修改prioxy config文件

forward-socks5 / localhost:1080 . // socks5 协议ip:port
listen-address 127.0.0.1:8080 // http ip:port

2. 设置虚拟机环境变量
添加以下到环境变量~/.bashrc中后,
$ source ~/.bashrc 环境生效
$ proxy_http_on 使用
$ proxy_off 取消代理
function proxy_off(){
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset FTP_PROXY
unset RSYNC_PROXY
unset all_proxy
unset ALL_PROXY
git config --global http.proxy ""
git config --global https.proxy ""
echo -e "已关闭代理"
curl cip.cc
}

function proxy_config(){
export no_proxy=$http_proxy
export NO_PROXY=$http_proxy
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export FTP_PROXY=$http_proxy
export RSYNC_PROXY=$http_proxy
export all_proxy=$http_proxy
export ALL_PROXY=$http_proxy
echo "proxy config done"
echo $http_proxy
}

function proxy_http_on() {
#export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export http_proxy="http://127.0.0.1:8080" # socks协议使用的是 socks://localhost:1080
proxy_config
git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"
echo -e "已开启代理(http)"
curl cip.cc
}

posted @ 2022-06-29 15:28  Banner13  阅读(388)  评论(1)    收藏  举报