1. 绪言
-
首先还是说点废话吧,安装tendermint之前,你应该先安装好go。可以参考之前的博客:ubuntu18.04安装Go语言
-
跟go有关的很多库都被墙了,导致使用
go get
去下载的相关包,很容易报错。要么是他本身无法下载,要么是他的依赖无法下载,真的超级鸡肋。 -
go get
可以根据要求和实际情况从互联网上下载或更新指定的代码包及其依赖包,并对它们进行编译和安装。个人认为他等同于以下两个命令:
git clone # 下载想安装的代码包以及编译、安装所需要的其他代码包
go install # 安装代码包
- 所以一般遇到make 过程中报错,说找不到某个包的情况,我都是创建对应的文件夹,然后
git clone
解决的。
google.golang.org/grpc/credentials/credentials.go:35:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/home/hadoop/GOPATH/src/github.com/golang/protobuf/proto (from $GOPATH)
# 解决办法
$ mkdir -p ~/GOPATH/src/github.com/golang
$ cd ~/GOPATH/src/github.com/golang
$ git clone https://github.com/golang/protobuf.git
- 某些提示的代码包,尤其不是以
github.com
开头的,虽然你能在github上找到的对应的包,但是都需要更改git clone
时的文件名。以grpc
为例:
$ mkdir -p $GOPATH/src/google.golang.org/ # 创建存放路径
$ cd $GOPATH/src/google.golang.org/
$ git clone https://github.com/grpc/grpc-go grpc # clone下来的文件名为grpc-go,不满足要求,需要指定文件名grpc
2. 下载并编译tendermint
① 下载tendermint
$ mkdir -p $GOPATH/src/github.com/tendermint
$ cd $GOPATH/src/github.com/tendermint
$ git clone https://github.com/tendermint/tendermint.git
② 执行make get_tools
,编译tendermint
- 第一次执行
make get_tools
,编译tendermint就报错:
$ cd tendermint
$ make get_tools
... # 省略中间输出,最后报错,提示找不到golang.org/x/tools/cmd/goimports
package golang.org/x/tools/cmd/goimports: unrecognized import path "golang.org/x/tools/cmd/goimports" (https fetch: Get https://golang.org/x/tools/cmd/goimports?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
Makefile:81: recipe for target 'get_tools' failed
make: *** [get_tools] Error 1
- 下载
github.com/golang/tools
到$GOPATH/src/golang.org/x
目录并安装,其中tools中包含cmd/goimports
:
$ mkdir -p $GOPATH/src/golang.org/x/
$ cd $GOPATH/src/golang.org/x/
$ git clone https://github.com/golang/tools.git
$ go install golang.org/x/tools/cmd/goimports
参考链接:
GO 工具包安装方法
- 重新执行
make get_tools
,编译成功!全是各种Done
信息。
$ make get_tools
--> Installing tools
./scripts/get_tools.sh
--> Installing golang/dep (22125cfaa6ddc71e145b1535d4b7ee9744fefff2)...
--> Done
... # 其他的省略
$ git config --global http.proxy 'socks5://127.0.0.1:1080'
$ git config --global https.proxy 'socks5://127.0.0.1:1080'
③ 执行make get_vendor_deps
,让deps帮忙安装各种依赖包(可以直接跳过了,后面手动下载吧)
- 执行
make get_vendor_deps
,发现一直报错,就算自己使用shadowsocks
进行了翻墙也没有用!
$ make get_vendor_deps
--> Running dep
The following issues were found in Gopkg.toml:
✗ unable to deduce repository and source type for "google.golang.org/grpc": unable to read metadata: unable to fetch raw metadata: failed HTTP request to URL "http://google.golang.org/grpc?go-get=1": Get http://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:80: i/o timeout
ProjectRoot name validation failed
Makefile:90: recipe for target 'get_vendor_deps' failed
make: *** [get_vendor_deps] Error 1
- 以为是因为grpc没有安装的问题,所以安装了grpc。参考链接:拉取 google.golang.org/grpc 报错
- 首先
clone
grpc到本地:
$ mkdir -p $GOPATH/src/google.golang.org/
$ cd $GOPATH/src/google.golang.org/
$ git clone https://github.com/grpc/grpc-go grpc
- 第一次尝试安装
grpc
,发现报错,缺少很多相关的依赖包:
$ go install google.golang.org/grpc
google.golang.org/grpc/credentials/credentials.go:35:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/home/hadoop/GOPATH/src/github.com/golang/protobuf/proto (from $GOPATH)
... # 忽略剩余的报错信息
- 安装grpc的各种依赖包(注意看我的操作目录,你可使用
mkdir
和cd
实现相同的操作目录)
~/GOPATH/src/github.com/golang$ git clone git@github.com:golang/protobuf.git
~/GOPATH/src/golang.org/x$ git clone git@github.com:golang/net.git
~/GOPATH/src/golang.org/x$ git clone git@github.com:golang/sys.git
~/GOPATH/src/golang.org/x$ git clone git@github.com:golang/text.git
~/GOPATH/src/google.golang.org$ git clone git@github.com:google/go-genproto.git genproto
- 再次使用
go install google.golang.org/grpc
安装grpc,成功安装,但是仍然没有解决问题,执行make get_vendor_deps
依然报错。。。。。 - 艺华的回答:
make get_vendor_deps
就是替代你手动安装缺少的依赖包的过程,避免make install 时缺少依赖包。可以直接跳过make get_vendor_deps
,执行make install
,缺少什么包下载什么包,手动解决依赖。
④ 执行make install
,完成tendermint的安装
- 第一次执行
make install
,发现报错,缺少很多的依赖包。
$ make install
CGO_ENABLED=0 go install -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' ./cmd/tendermint
crypto/secp256k1/secp256k1.go:13:2: cannot find package "github.com/btcsuite/btcd/btcec" in any of:
/usr/local/go/src/github.com/btcsuite/btcd/btcec (from $GOROOT)
/home/hadoop/GOPATH/src/github.com/btcsuite/btcd/btcec (from $GOPATH)
... # 省略
Makefile:32: recipe for target 'install' failed
make: *** [install] Error 1
- 根据错误信息提示,
git clone
相关的依赖包,完成了手动解决依赖包的烦人过程!
$ mkdir -p ~/GOPATH/src/github.com/btcsuite
$ cd ~/GOPATH/src/github.com/btcsuite
$ git clone https://github.com/btcsuite/btcd.git
$ mkdir -p ~/GOPATH/src/github.com/go-kit
$ cd ~/GOPATH/src/github.com/go-kit
$ git clone https://github.com/go-kit/kit.git
$ mkdir -p ~/GOPATH/src/github.com/go-logfmt
$ cd ~/GOPATH/src/github.com/go-logfmt
$ git clone https://github.com/go-logfmt/logfmt.git
$ mkdir -p ~/GOPATH/src/github.com/golang
$ cd ~/GOPATH/src/github.com/golang
$ git clone https://github.com/golang/protobuf.git
$ mkdir -p ~/GOPATH/src/github.com/gorilla
$ cd ~/GOPATH/src/github.com/gorilla
$ git clone https://github.com/gorilla/websocket.git
$ mkdir -p ~/GOPATH/src/github.com/pkg
$ cd ~/GOPATH/src/github.com/pkg
$ git clone https://github.com/pkg/errors.git
$ mkdir -p ~/GOPATH/src/github.com/prometheus
$ cd ~/GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/client_golang.git
$ mkdir -p ~/GOPATH/src/github.com/beorn7
$ cd ~/GOPATH/src/github.com/beorn7
$ git clone https://github.com/beorn7/perks.git
$ mkdir -p ~/GOPATH/src/github.com/prometheus
$ cd ~/GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/client_model.git
# 同一目录,所以没有执行mkdir和cd
$ git clone https://github.com/prometheus/common.git
$ mkdir -p ~/GOPATH/src/github.com/matttproud
$ cd ~/GOPATH/src/github.com/matttproud
$ git clone https://github.com/matttproud/golang_protobuf_extensions.git
$ mkdir -p ~/GOPATH/src/github.com/rcrowley
$ cd ~/GOPATH/src/github.com/rcrowley
$ git clone https://github.com/rcrowley/go-metrics.git
$ mkdir -p ~/GOPATH/src/github.com/rs
$ cd ~/GOPATH/src/github.com/rs
$ git clone https://github.com/rs/cors.git
$ mkdir -p ~/GOPATH/src/github.com/prometheus
$ cd ~/GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/procfs.git
$ mkdir -p ~/GOPATH/src/github.com/spf13
$ cd ~/GOPATH/src/github.com/spf13
$ git clone https://github.com/spf13/viper.git
$ mkdir -p ~/GOPATH/src/github.com/syndtr
$ cd ~/GOPATH/src/github.com/syndtr
$ git clone https://github.com/syndtr/goleveldb.git
$ mkdir -p ~/GOPATH/src/github.com/tendermint
$ cd ~/GOPATH/src/github.com/tendermint
$ git clone https://github.com/tendermint/go-amino.git
$ mkdir -p ~/GOPATH/src/github.com/magiconair
$ cd ~/GOPATH/src/github.com/magiconair
$ git clone https://github.com/magiconair/properties.git
$ mkdir -p ~/GOPATH/src/github.com/hashicorp
$ cd ~/GOPATH/src/github.com/hashicorp
$ git clone https://github.com/hashicorp/hcl.git
$ mkdir -p ~/GOPATH/src/github.com/fsnotify
$ cd ~/GOPATH/src/github.com/fsnotify
$ git clone https://github.com/fsnotify/fsnotify.git
$ mkdir -p ~/GOPATH/src/github.com/davecgh
$ cd ~/GOPATH/src/github.com/davecgh
$ git clone https://github.com/davecgh/go-spew.git
$ mkdir -p ~/GOPATH/src/github.com/golang
$ cd ~/GOPATH/src/github.com/golang
$ git clone https://github.com/golang/snappy.git
$ mkdir -p ~/GOPATH/src/github.com/mitchellh
$ cd ~/GOPATH/src/github.com/mitchellh
$ git clone https://github.com/mitchellh/mapstructure.git
$ mkdir -p ~/GOPATH/src/github.com/pelletier
$ cd ~/GOPATH/src/github.com/pelletier
$ git clone https://github.com/pelletier/go-toml.git
$ mkdir -p ~/GOPATH/src/github.com/spf13
$ cd ~/GOPATH/src/github.com/spf13
$ git clone https://github.com/spf13/afero.git
$ git clone https://github.com/spf13/cobra.git
$ git clone https://github.com/spf13/cast.git
$ git clone https://github.com/spf13/pflag.git
$ git clone https://github.com/spf13/jwalterweatherman.git
# 针对/home/hadoop/GOPATH/src/golang.org/x/crypto/chacha20poly1305
~/GOPATH/src/golang.org/x$ git clone https://github.com/golang/crypto.git
~/GOPATH/src/golang.org/x$ git clone https://github.com/golang/net.git
~/GOPATH/src/golang.org/x$ git clone https://github.com/golang/sys.git
~/GOPATH/src/golang.org/x$ git clone https://github.com/golang/text.git
# 针对/home/hadoop/GOPATH/src/google.golang.org/genproto/googleapis/rpc/status
~/GOPATH/src/google.golang.org$ git clone https://github.com/google/go-genproto.git genproto
# 针对/home/hadoop/GOPATH/src/gopkg.in/yaml.v2
$ mkdir -p ~/GOPATH/src/gopkg.in
$ cd ~/GOPATH/src/gopkg.in
$ git clone https://github.com/go-yaml/yaml.git yaml.v2
- 执行
make install
,成功安装tendermint!
$ make install
CGO_ENABLED=0 go install -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' ./cmd/tendermint
3. 验证及使用简单的tendermint
① 查看tendermint版本
- 使用如下命令查看
tendermint
的版本,顺带验证tendermint
安装是否成功!
$ tendermint version
0.31.5-4253e67c
- 查看
tendermint
的相关命令,我们经常会使用到的是init
和node
$ tendermint
② 运行tendermint
- 将为单个本地节点创建所需的文件,即初始化tendermint
$ tendermint init
I[2019-04-29|21:40:31.004] Generated private validator module=main keyFile=/home/hadoop/.tendermint/config/priv_validator_key.json stateFile=/home/hadoop/.tendermint/data/priv_validator_state.json
I[2019-04-29|21:40:31.004] Generated node key module=main path=/home/hadoop/.tendermint/config/node_key.json
I[2019-04-29|21:40:31.005] Generated genesis file module=main path=/home/hadoop/.tendermint/config/genesis.json
- 使用简单的进程内应用程序启动tendermint
$ tendermint node --proxy_app=kvstore
I[2019-04-29|21:58:35.556] Version info module=main software=0.31.5 block=10 p2p=7
I[2019-04-29|21:58:36.525] Starting Node module=main impl=Node
I[2019-04-29|21:58:36.558] Started node module=main nodeInfo="{ProtocolVersion:{P2P:7 Block:10 App:1} ID_:3e1868bb9081b6dd43a8485e71ec7fd326259317 ListenAddr:tcp://0.0.0.0:26656 Network:test-chain-1w2a1c Version:0.31.5 Channels:4020212223303800 Moniker:master Other:{TxIndex:on RPCAddress:tcp://0.0.0.0:26657}}"
# block开始流入
I[2019-04-29|21:43:05.790] Executed block module=state height=1 validTxs=0 invalidTxs=0
I[2019-04-29|21:43:06.078] Committed state module=state height=1 txs=0 appHash=0000000000000000
I[2019-04-29|21:43:07.987] Executed block module=state height=2 validTxs=0 invalidTxs=0
I[2019-04-29|21:43:08.032] Committed state module=state height=2 txs=0 appHash=0000000000000000
...
- **注意:**官网后面关于curl的命令我运行一致不正确。。。。不知道是因为没有安装
abci-cli
的原因?还是应为下面的错误。
E[2019-04-29|22:28:06.558] Couldn't connect to any seeds module=p2p
- 针对上面的错误,有个博客(tendermint简单启动)说是因为单节点启动,没有其他节点可以连接。
- 莫名其妙的成功了? 估计是自己去除了~/.bashrc中关于http_proxy的相关配置,还重启了电脑,所以竟然成功了!说明
Couldn't connect to any seeds
确实是因为单节点启动的原因!