git fabric 1.0.0 官方源码进行编译,生成 docker images(rc2 版本2017年6月26日)

git fabric 1.0.0 官方源码进行编译,生成 docker images(rc2 版本2017年6月26日)

系统环境: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

一.添加 fabric 用户和设置存放源码的目录

useradd fabric
# 建立如下项目目录.
mkdir /home/fabric/fabric

二.安装 go 的开发环境和必须的组件

以 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

四.设置fabric环境变量

vim ~/.bashrc
export GOPATH=/home/fabric/fabric
# 使得环境变量生效
source ~/.bashrc

五.进入项目目录

cd $GOPATH

六. 建立 go 源码目录结构(一定要建立 src/github.com/hyperledger ,否则无法使用 go 进行编译)

cd $GOPATH
mkdir -p src/github.com/hyperledger

七.拉取 fabric 的源码

cd $GOPATH/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git

八.编译生成 protoc-gen-go

#编译生成 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执行文件

九. 编译 fabric docker 环境

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/

十.如果出现文件或者命令没找到的错误,复制go 的相关文件到 fabric 编译环境

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/ 

十一.编译 fabric ca 环境

cd /root
git clone https://github.com/hyperledger/fabric-ca.git
cd fabric-ca
make docker

十二. 部署和测试 e2e 应用

一键启动
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh up mytestchannel

A. 生成配置文件

cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen

B. 执行后,控制台的输出内容如下:

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

C. Run the generateCfgTrx.sh shell script

cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
./generateCfgTrx.sh  mytestchannel

D.控制台输出

[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

E.启动 fabric 网络

先把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

十三.问题的解决

A.在 mac os 下出现如下错误:

Error processing tar file(bzip2 data invalid: bad magic value in continuation file): 

解决办法 ,更新gnu-tar

brew install gnu-tar --with-default-names

B. 在 mac os 下出现’ltdl.h’ file not found错误

brew install libtool openssl

C. 出现goimports: command not found错误

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

D. make 过程中出现 IPv4 forwarding is disabled. Networking will not work. 这个警告。

sysctl -w net.ipv4.ip_forward=1
#重启 docker 服务
systemctl restart docker

E. 运行 e2e 例子的时候出现如下错误:

1.无法创建 channel
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

F. 相关知识点

1. git 拉取某个特定版本
git reset --hard <commitlevel号>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值