美文网首页区块链研习社
如何编译fabric和fabric-ca源码生成二进制可执行文件

如何编译fabric和fabric-ca源码生成二进制可执行文件

作者: 链播学院 | 来源:发表于2018-08-02 16:44 被阅读75次

    00 导言

          在上上讲《Fabric 环境搭建时bootstrap.sh帮我们做了什么?》中,我们知道bootstrap.sh帮我们做了三件事:
          1. 从github上克隆 hyperledger/fabric-samples并进入该目录,然后检出适当的版本
          2. 在fabric-samples目录下安装特定平台的 Hyperledger Fabric 二进制可执行文件 和配置文件
          3.下载 指定版本的Hyperledger Fabric 的docker镜像

          其中第二件事是执行curl去下载tar包并解压:

    $ curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.2.0/hyperledger-fabric-linux-amd64-1.2.0.tar.gz
    $ curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.2.0/hyperledger-fabric-ca-linux-amd64-1.2.0.tar.gz
    

          这两个tar包里面包含了下面这些二进制文件和一个脚本文件:

    • configtxgen
    • configtxlator
    • cryptogen
    • discover
    • idemixgen
    • orderer
    • peer
    • fabric-ca-client
    • get-docker-images.sh

          其实,这些二进制文件我们也可以通过编译fabric和fabric-ca的源码得到。下面我们就来说说怎么编译得到它们。

    01 下载fabric源码

          用git把fabric源码从github上克隆下来

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

    02 编译fabric源码

         编译之前请确保系统中已经安装了Go语言运行环境和正确的配置了环境变量。然后执行make release编译。

    $ cd fabric
    $ make release
    Building release/linux-amd64/bin/configtxgen for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/configtxgen -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/tools/configtxgen/metadata.CommitSHA=2be396e88" github.com/hyperledger/fabric/common/tools/configtxgen
    Building release/linux-amd64/bin/cryptogen for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/cryptogen -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/tools/cryptogen/metadata.CommitSHA=2be396e88" github.com/hyperledger/fabric/common/tools/cryptogen
    Building release/linux-amd64/bin/idemixgen for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/idemixgen -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/tools/idemixgen/metadata.CommitSHA=2be396e88" github.com/hyperledger/fabric/common/tools/idemixgen
    Building release/linux-amd64/bin/discover for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/discover -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/cmd/discover/metadata.CommitSHA=2be396e88" github.com/hyperledger/fabric/cmd/discover
    Building release/linux-amd64/bin/configtxlator for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/configtxlator -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/tools/configtxlator/metadata.CommitSHA=2be396e88" github.com/hyperledger/fabric/common/tools/configtxlator
    Building release/linux-amd64/bin/peer for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/peer -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.2.1 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=2be396e88 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.4.10 -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 -X github.com/hyperledger/fabric/common/metadata.Experimental=true" github.com/hyperledger/fabric/peer
    Building release/linux-amd64/bin/orderer for linux-amd64
    mkdir -p release/linux-amd64/bin
    CGO_CFLAGS=" " GOOS=linux GOARCH=amd64 go build -o /home/blockchain/go/src/github.com/hyperledger/fabric/release/linux-amd64/bin/orderer -tags "experimental" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.2.1 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=2be396e88 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.4.10 -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 -X github.com/hyperledger/fabric/common/metadata.Experimental=true" github.com/hyperledger/fabric/orderer
    mkdir -p release/linux-amd64/bin
    

    03 查看是否编译成功

          编译好的二进制可执行文件放哪里了呢?放在了下面这个目录:

    $ cd $GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin/
    $ ls -l 
    总用量 117048
    -rwxr-xr-x 1 blockchain blockchain 16749240 8月   1 18:26 configtxgen
    -rwxr-xr-x 1 blockchain blockchain 17886416 8月   1 18:26 configtxlator
    -rwxr-xr-x 1 blockchain blockchain  8641432 8月   1 18:26 cryptogen
    -rwxr-xr-x 1 blockchain blockchain 17576512 8月   1 18:26 discover
    -rwxr-xr-x 1 blockchain blockchain      829 8月   1 18:26 get-docker-images.sh
    -rwxr-xr-x 1 blockchain blockchain  7138016 8月   1 18:26 idemixgen
    -rwxr-xr-x 1 blockchain blockchain 22027704 8月   1 18:26 orderer
    -rwxr-xr-x 1 blockchain blockchain 29819976 8月   1 18:26 peer
    

    04 下载fabric-ca源码

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

    05 编译fabric-ca源码

    $ cd fabric-ca
    $ make fabric-ca-server
    $ make fabric-ca-client
    

    06 查看是否编译成功

    $ cd bin
    $ ls -l
    总用量 40876
    -rwxr-xr-x 1 blockchain blockchain 19626520 8月   2 16:40 fabric-ca-client
    -rwxr-xr-x 1 blockchain blockchain 22228224 8月   2 16:40 fabric-ca-server
    

    07 总结

          实际开发中,我们也许并不需要自己手动去编译生成这些文件,可以直接执行bootstrap.sh这个脚本帮我们下载好。但作为学习研究,我们还是有必要知道这些二进制文件是怎么来的。知其然也知其所以然嘛!正如每个具有哲学精神的我们(diao si)每天都在问的三个问题:"我是谁?我从哪里来?我在干什么?"

    相关文章

      网友评论

      • bc56f690bfc1:是否可以理解成为了方便,直接下载可执行文件。如果为了与系统的高度稳定性,还是下载源代码进行编译更好一些。
      • cd4f86e72842:学习fabric

      本文标题:如何编译fabric和fabric-ca源码生成二进制可执行文件

      本文链接:https://www.haomeiwen.com/subject/pkervftx.html