Ubuntu命令行设置ipfs开发环境

部署一台Ubuntu服务器

设置科学上网,因为ipfs已被墙

购买科学上网服务,SSR服务,如bosXXX和rixXXXX,得到一堆ssr服务地址

部署Ubuntu SSR客户端

  1. 下载ssr客户端
1
2
3
4
5
wget https://onlyless.github.io/ssr
sudo mv ssr /usr/local/bin
sudo chmod 766 /usr/local/bin/ssr
ssr install
ssr config
  1. 配置ssr地址
1
2
3
4
5
6
7
8
{
"server" : "your serverip",
"server_port" : yourport,
"password" : "your password",
"method" : "your method",
"protocol" : "your protocol",
"obfs" : "your obfs",
}
  1. 重启
1
ssr restart
  1. 配置开机启动, vim /etc/rc.local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo ssr start
exit 0

安装Privoxy

  1. 因为ssr是sock5代理,不接受http/https流量,使用的时候需要将其转化成http/https流量

  2. 安装Privoxy

1
apt-get install privoxy
  1. 配置Privoxy,打开其配置文件/etc/privoxy/config,修改以下几个地方
  • 找到4.1. listen-address,确认privoxy监听的端口号
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#  Example:
#
# Suppose you are running Privoxy on a machine which has the
# address 192.168.0.1 on your local private network
# (192.168.0.0) and has another outside connection with a
# different address. You want it to serve requests from inside
# only:
#
# listen-address 192.168.0.1:8118
#
# Suppose you are running Privoxy on an IPv6-capable machine and
# you want it to listen on the IPv6 address of the loopback
# device:
#
# listen-address [::1]:8118
#
listen-address localhost:8118
#
# 4.2. toggle
# ============
#
# Specifies:
#
# Initial state of "toggle" status
#
# Type of value:
#
# 1 or 0
#
# Default value:
  • 找到5.2. 设置sock5转发
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#      Unencrypted connections to systems in these address ranges
# will be as (un)secure as the local network is, but the
# alternative is that you can't reach the local network through
# Privoxy at all. Of course this may actually be desired and
# there is no reason to make these exceptions if you aren't sure
# you need them.
#
# If you also want to be able to reach servers in your local
# network by using their names, you will need additional
# exceptions that look like this:
#
# forward localhost/ .
#
#
forward-socks5 / 127.0.0.1:1080 .
# 5.3. forwarded-connect-retries
# ===============================
#
# Specifies:
#
  1. 重启Privoxy
1
/etc/init.d/privoxy restart
  1. 编写两个bash脚本,start_proxy.sh,stop_proxy.sh;用source start_proxy.sh/stop_proxy.sh 来开启和关闭代理
1
2
3
4
5
6
# start_proxy.sh
export http_proxy="127.0.0.1:8118"
export https_proxy="127.0.0.1:8118"

git config --global http.proxy http://127.0.0.1:8118 # 可以用sock5://127.0.0.1:1008
git config --global https.proxy https://127.0.0.1:8118
1
2
3
4
5
6
# stop_proxy.sh
export http_proxy=
export https_proxy=

git config --global --unset http.proxy
git config --global --unset https.proxy
  1. 开始代理,测试是否可以穿墙
1
2
source start_proxy.sh
curl https://www.google.com # 测试

安装开发工具

  1. 安装工具 git
1
apt-get install git
  1. 安装golang
1
2
3
4
5
wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.2.linux-amd64.tar.gz
ln -s /usr/local/go/bin/go /usr/local/go
ln -s /usr/local/go/bin/gofmt /usr/local/gofmt
ln -s /usr/local/go/bin/godoc /usr/local/godoc
  1. 创建一个golang工作目录,比如~/gopath,编辑.bashrc,在文件最后添加以下内容;确保.profile 会调用.bashrc
1
2
export GOPATH="$HOME/gopath"
export PATH="$GOPATH/bin:$PATH"

下载编译源码

  1. 下载源码。虽然已经翻墙,但也不能直接编译,原因是ipfs使用的包管理工具gx不支持http代理。
1
go get -u -d -v github.com/ipfs/go-ipfs
  1. 编译ipfs包管理工具GX

    1. 下载GX

      1
      2
      go get -u -v -d github.com/whyrusleeping/gx
      go get -u -v -d github.com/whyrusleeping/gx-go
    2. 修改 github.com/ipfs/go-ipfs-api/shell.go

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      func NewShell(url string) *Shell {
      c := &gohttp.Client{
      Transport: &gohttp.Transport{
      Proxy: gohttp.ProxyFromEnvironment, // 这里是添加的一行
      DisableKeepAlives: true,
      },
      }

      return NewShellWithClient(url, c)
      }
    3. 编译GX,编译完后可以在$(GOPATH)/bin目录找到gx和gx-go程序

      1
      2
      go install github.com/whyrusleeping/gx
      go install github.com/whyrusleeping/gx-go
  2. 用gx下载所有的依赖包

1
gx install --global
  1. 进入go-ipfs目录,编译ipfs,编译完后可以在$(GOPATH)/bin目录找到ipfs程序
1
make install