系统环境:centos 7 64位
docker
docker-compose
不要使用 centos yum 仓库带的 docker,版本过低。
安装docker 官方的repo 里面的版本
$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
yum update
yum install docker-engine
systemctl enable docker
systemctl restart docker
useradd fabric
# 建立如下项目目录.
mkdir /home/fabric/fabric
以 root 用户安装
wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
tar -xzvf go1.8.1.linux-amd64.tar.gz
mv ./go /usr/local
//修改 etc/profile,增加 一下内容
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
source /etc/profile
#安装后,确认 go 1.8 安装成功
go version
go version go1.8 darwin/amd64
#如果无法科学上网,使用如下步骤:
# 1. 以 root安装 gopm
export GOPATH=/usr/local
go get -u github.com/gpmgo/gopm
#确认在/usr/local/bin 目录下有 gopm
# 2. 以 fabric 用户,通过 gopm 安装 goimports
export GOPATH=/home/fabric/fabric
gopm get -g -d golang.org/x/tools/cmd/goimports
#再使用 go install 安装 goimports
go install golang.org/x/tools/cmd/goimports
#确认在/home/fabric/fabric/bin 目录下有 goimports
以 fabric 用户 安装 gocov
GOPATH=/home/fabric/fabric
gopm get -g -d golang.org/x/tools/cover
gopm get -g -d github.com/axw/gocov/gocov
go install github.com/axw/gocov/gocov
# 确认 /home/fabric/fabric/bin 目录下有 gocov
安装 gocov-xml
GOPATH=/home/fabric/fabric
gopm get -g -d github.com/AlekSi/gocov-xml
go install github.com/AlekSi/gocov-xml
#确认 /home/fabric/fabric/bin 目录下有 gocov-xml
以 root 用户安装
#centos 下需要安装
yum install -y gcc libtool libltdl-dev libtool-ltdl-devel openssl
vim ~/.bashrc
export GOPATH=/home/fabric/fabric
# 使得环境变量生效
source ~/.bashrc
cd $GOPATH
cd $GOPATH
mkdir -p src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
#编译生成 protoc-gen-go
cd $GOPATH
gopm get -g -d github.com/golang/protobuf/protoc-gen-go
go install github.com/golang/protobuf/protoc-gen-go
#确认在$GOPATH/bin出现protoc-gen-go执行文件
cd $GOPATH/src/github.com/hyperledger/fabric
make docker
如果出现 Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock 这个错误。
解决方案:
1. 把 fabric 用户加入到 sudo 组
a. 以 root 用户登录
b. vim /etc/sudoers
c. 增加 fabric ALL=(ALL) ALL 一行到root ALL=(ALL) ALL下面
2. sudo usermod -a -G docker $USER
3. newgrp - docker
4. newgrp - groups ${USER} | cut -d' ' -f1
参考:
https://techoverflow.net/2017/03/01/solving-docker-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket/
cp $GOPATH/bin/protoc-gen-go $GOPATH/src/github.com/hyperledger/fabric/build/docker/gotools/bin/
cp $GOPATH/bin/gocov $GOPATH/src/github.com/hyperledger/fabric/build/docker/gotools/bin/
cd /root
git clone https://github.com/hyperledger/fabric-ca.git
cd fabric-ca
make docker
一键启动
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh up mytestchannel
cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen
build/bin/configtxgen
CGO_CFLAGS=" " GOBIN=/root/fabric/src/github.com/hyperledger/fabric/build/bin go install -tags "nopkcs11" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-snapshot-eba4a20 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.0 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/common/configtx/tool/configtxgen
Binary available as build/bin/configtxgen
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
./generateCfgTrx.sh mytestchannel
[root@fabric e2e_cli]# ./generateCfgTrx.sh mytestchannel
Channel name - mytestchannel
Building configtxgen
build/bin/configtxgen
CGO_CFLAGS=" " GOBIN=/root/fabric/src/github.com/hyperledger/fabric/build/bin go install -tags "nopkcs11" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-snapshot-eba4a20 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.0 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/common/configtx/tool/configtxgen
Binary available as build/bin/configtxgen
Generating genesis block
2017/04/19 16:14:03 Loading configuration
2017/04/19 16:14:03 Looking for configtx.yaml in: /root/fabric/src/github.com/hyperledger/fabric/common/configtx/tool
2017/04/19 16:14:03 Found configtx.yaml there
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Generating genesis block
2017/04/19 16:14:03 Writing genesis block
Generating channel configuration transaction
2017/04/19 16:14:03 Loading configuration
2017/04/19 16:14:03 Looking for configtx.yaml in: /root/fabric/src/github.com/hyperledger/fabric/common/configtx/tool
2017/04/19 16:14:03 Found configtx.yaml there
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Checking for MSPDir at: .
2017/04/19 16:14:03 Generating new channel configtx
2017/04/19 16:14:03 Creating no-op MSP instance
2017/04/19 16:14:03 Obtaining default signing identity
2017/04/19 16:14:03 Creating no-op signing identity instance
2017/04/19 16:14:03 Serialinzing identity
2017/04/19 16:14:03 signing message
2017/04/19 16:14:03 signing message
2017/04/19 16:14:03 Writing new channel tx
先把make 出的 image 进行 tag 到 latest
docker tag hyperledger/fabric-orderer:x86_64-1.0.0-snapshot-<xxxxxxx> hyperledger/fabric-orderer
docker tag hyperledger/fabric-peer:x86_64-1.0.0-snapshot-<xxxxxxx> hyperledger/fabric-peer
然后启动 docker 容器
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
CHANNEL_NAME=mytestchannel docker-compose up -d
Error processing tar file(bzip2 data invalid: bad magic value in continuation file):
解决办法 ,更新gnu-tar
brew install gnu-tar --with-default-names
brew install libtool openssl
make linter
出现如下错误:
LINT: Running code checks..
Checking ./bccsp
./scripts/golinter.sh: line 22: goimports: command not found
make: *** [linter] 错误 127
但是执行$GOPATH/src/github.com/hyperledger/fabric/scripts/golinter.sh
是可以正常执行的
make gotools
#如果无法科学上网,需要使用代理
git config --global http.proxy "192.168.0.50:8016"
git config --global https.proxy "192.168.0.50:8016"
#或者在可以 git 的地方,把 gotools 的源码 git 下来,然后复制到相应目录下
git clone https://go.googlesource.com/tools
#当前目录下生成 tools 目录,
#把目录复制到$GOPATH/src/github.com/hyperledger/fabric/gotools/build/gopath/src/golang.org/x/目录下。
#重新 make gotools
cd $GOPATH/src/github.com/hyperledger/fabric
make gotools
sysctl -w net.ipv4.ip_forward=1
#重启 docker 服务
systemctl restart docker
vim $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/docker-compose.yaml
#修改 docker-compose.yaml 文件。在 cli 部分增加 host 映射
extra_hosts:
- "orderer0:10.211.55.8"
- "peer0:10.211.55.8"
- "peer1:10.211.55.8"
- "peer2:10.211.55.8"
- "peer3:10.211.55.8"
#修改 script.sh 脚本,进行 peer 的判断,映射端口号:
if [ $1 -eq 0 ]; then
CORE_PEER_ADDRESS=peer$1:7051
elif [ $1 -eq 1 ]; then
ORE_PEER_ADDRESS=peer$1:8051
elif [ $1 -eq 2 ]; then
ORE_PEER_ADDRESS=peer$1:9051
elif [ $1 -eq 3 ]; then
ORE_PEER_ADDRESS=peer$1:10051
fi
git reset --hard <commitlevel号>