tsui66 / blog

11 stars 2 forks source link

为终端设置Shadowsocks代理, 解决golang dep ensure依赖包安装被墙 #2

Open tsui66 opened 6 years ago

tsui66 commented 6 years ago

写这篇文章的目的,很简单,解决golang dep安装依赖包被墙无法正常开发的问题,做个记录。如果你也遇到这类问题,就请往下看。

NOTE: 开发环境操作系统为OSX

首先,你要有个自己shadowsocks账号;如果你还没有,以下是我个人的意见:

好了,现在你已经准备好了一切,但是你在golang项目运行dep ensure时不一定如意:

接下来,我们要解决的问题是在终端也能翻墙!

安装 polipo 工具

brew install polipo

polipo程序开机自启动

vim /usr/local/opt/polipo/homebrew.mxcl.polipo.plist

需要给polipo命令加上命令行参数 socksParentProxy=localhost:1080, 完整配置如下:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>homebrew.mxcl.polipo</string>
      <key>RunAtLoad</key>
      <true/>
      <key>KeepAlive</key>
      <true/>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/opt/polipo/bin/polipo</string>
        <string>socksParentProxy=localhost:1080</string>
      </array>
    </dict>
  </plist>

紧接着执行以下命令:

ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist

polipo 启动

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist

设置别名

bash中有一个很好的东西,就是别名alias. Linux用户修改~/.bashrc,Mac用户修改~/.bash_profile文件或者~/.zshrc,增加如下设置:

alias proxy="export http_proxy=http://localhost:8123;export https_proxy=http://localhost:8123" //会话全局设置
alias unproxy="unset http_proxy" //撤销当前会话的http_proxy代理
source ~/.zshrc

接下来,你只要运行proxy就可以全局代理了,取消代理使用unproxy

如果你到这还遇到问题,那请参考以下资料:

liukun4515 commented 6 years ago

设置别名是不是有点错误? 两个都使用了 http,第一个应该是 https://xxxxx把

tsui66 commented 6 years ago

@liukun4515 按你的意思是alias proxy="export http_proxy=http://localhost:8123;export https_proxy=https://localhost:8123" //会话全局设置?

cq951027 commented 4 years ago

alias proxy="export http_proxy=http://localhost:1806;export https_proxy=http://localhost:1806" 大佬 我这边配置了代理 浏览器可以Google 但是终端依然ping不通

tsui66 commented 4 years ago

@cq951027 嘗試下 export https_proxy=http://127.0.0.1:1087;export http_proxy=http://127.0.0.1:1087;export all_proxy=socks5://127.0.0.1:1086

cq951027 commented 4 years ago

@Quinton 谢谢 试了下还是不行 有可能ping是icmp的 不走代理