zoukankan      html  css  js  c++  java
  • Ubuntu18.04安装Fabric

    本文介绍Ubuntu 18.04环境下如何配置Fabric开发环境。

    安装Golang

    因为Fabric是基于Go语言开发的,所以首先需要配置好Golang开发环境。

    由于某些原因,国内无法从Golang官网上下载Golang,不过好在国内的Golang开发者们搭建的可供国内Golang爱好者分享的平台,可以从这里下载Golang的开发包。

    下载完成后,执行如下操作:

    $ sudo tar -zxvf ./go1.14.2.linux-amd64.tar.gz -C /usr/local
    $ sudo echo "export GOPATH=$HOME/go" >> /etc/profile
    $ sudo echo "export GOROOT=/usr/local/go" >> /etc/profile
    $ sudo echo "export PATH=$GOPATH/bin:$GOROOT/bin:$PATH"
    $ source /etc/profile
    

    安装docker

    在Fabric网络中,通过docker启动的话,可以简化很多设置,所以接下来我们来安装docker。这里使用阿里源,操作如下:

    # 安装一些必要的系统工具  
    $ sudo apt update
    $ sudo apt install -y git apt-transport-https ca-certificates curl software-properties-common
    # 安装GPG证书
    $ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    # 写入软件源信息
    sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
    # 更新并安装docker-ce
    $ sudo apt update -y
    $ sudo apt install -y docker-ce docker-compose
    $ sudo systemctl enable docker
    $ sudo systemctl start docker
    $ sudo usermod -aG docker $(whoami)
    

    下载Fabric-samples

    对于初学者,Fabric官方提供了可供初学者学习使用的Fabric-samples。该repo中提供了first-network,执行其中的byfn.sh脚本,可以确认fabric环境是否配置完成。

    Fabric-samples提供了bootstrap.sh脚本,执行该脚本不仅可以完成Fabric-samples的下载,还能将fabric网络运行时需要的docker镜像下载完成,操作如下:

    $ cd $GOPATH/src/github.com/hyperledger
    $ curl -sS https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o bootstrap.sh
    $ chmod +x bootstrap.sh  
    $ ./bootstrap.sh
    

    默认情况下,bootstrap.sh会下载最新版本的fabric。当然也可以通过bootstrap.sh --help来查看更多选项。

    bootstrap.sh执行完后,执行如下命令来查看环境是否搭建完成:

    $ cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network  
    $ ./byfn up
    

    之后,脚本会自动创建一个fabric网络,创建一个chaincode以及执行简单的操作。最后,执行成功之后,会出现下面的内容:

    
        ......
    ===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
    
    Installing chaincode on peer1.org2...
    + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
    + res=0
    + set +x
    2020-04-25 07:12:55.347 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
    2020-04-25 07:12:55.347 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
    2020-04-25 07:12:55.637 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" >
    ===================== Chaincode is installed on peer1.org2 =====================
    
    Querying chaincode on peer1.org2...
    ===================== Querying on peer1.org2 on channel 'mychannel'... =====================
    Attempting to Query peer1.org2 ...3 secs
    + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    + res=0
    + set +x
    
    90
    ===================== Query successful on peer1.org2 on channel 'mychannel' =====================
    
    ========= All GOOD, BYFN execution completed ===========
    
    
     _____   _   _   ____
    | ____| |  | | |  _ 
    |  _|   |  | | | | | |
    | |___  | |  | | |_| |
    |_____| |_| \_| |____/
    

    要关闭刚才启动的fabric网络,操作如下:

    $ ./byfn down

    本文采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。

  • 相关阅读:
    2019年4月
    20190423
    20190419
    20190418
    20190417
    free命令详解(转载)
    https改造过程中的一个坑
    GitLab 实现代码自动部署(转载自https://segmentfault.com/a/1190000011561808)
    js和php写日历
    shell递归遍历目录的方法
  • 原文地址:https://www.cnblogs.com/lianshuiwuyi/p/11819131.html
Copyright © 2011-2022 走看看