• ubuntu1604 golang环境


    copy来的,这里记录一下

    1. 升级系统: sudo apt-get upgrade
    2. 安装docker
    下载docker-ce: https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_18.03.1~ce-0~ubuntu_amd64.deb
    sudo dpkg -i docker-ce_18.03.1~ce-0~ubuntu_amd64.deb
    sudo groupadd docker
    sudo usermod -aG docker <YouUser>

    3. 安装docker-compose
    sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose


    4. 

    5.1 安装与设置go语言开发环境
    sudo tar -zxf go1.10.1.linux-amd64.tar.gz -C /usr/local/
    vim ~/.bash_aliases
    export GOROOT=/usr/local/go
    export GOPATH=/home/jya/go
    export GOBIN=$GOPATH/bin/
    export PATH=.:$PATH:$GOROOT/bin:$GOBIN
    export PATH=${PATH}:/home/jya/src/fabric-samples/bin


    5.2下载源码
    https://github.com/hyperledger/fabric-sdk-java.git
    https://github.com/hyperledger/fabric-sdk-go.git
    https://github.com/hyperledger/fabric-samples.git
    https://github.com/hyperledger/fabric.git


    6. 安装基本工具: sudo apt-get install -y build-essential git make curl unzip g++ libtool openssl go-dep
    sudo apt-get install python-pip
    sudo pip install --upgrade pip
    go get golang.org/x/tools/cmd/goimports

    cd $GOPATH/src/golang.org/x/
    git clone https://github.com/golang/tools.git
    go install golang.org/x/tools/go/packages
    go install golang.org/x/tools/imports
    go install golang.org/x/tools/cover
    go install golang.org/x/tools/go/loader

    mkdir $GOPATH/src/golang.org/ && cd $GOPATH/src/github.com/
    git clone https://github.com/golang/lint.git
    go install golang.org/x/lint/golint



    mkdir $GOPATH/src/github.com/maxbrunsfeld/
    cd $GOPATH/src/github.com/maxbrunsfeld/
    git clone https://github.com/maxbrunsfeld/counterfeiter.git
    go install github.com/maxbrunsfeld/counterfeiter

    mkdir $GOPATH/src/github.com/axw && cd $GOPATH/src/github.com/axw
    git clone https://github.com/axw/gocov.git
    go install github.com/axw/gocov
    go install github.com/axw/gocov/gocov (必须执行)

    mkdir $GOPATH/src/github.com/vektra && cd $GOPATH/src/github.com/vektra
    git clone https://github.com/vektra/mockery.git
    go install github.com/vektra/mockery
    go install github.com/vektra/mockery/cmd/mockery


    mkdir $GOPATH/src/github.com/golang && cd $GOPATH/src/github.com/golang
    git clone https://github.com/golang/protobuf.git
    make all
    cp $GOPATH/bin/protoc-gen-go $GOPATH/src/github.com/hyperledger/fabric/.build/docker/gotools/bin/

    cd $GOPATH/src/github.com/golang
    git clone https://github.com/golang/dep.git
    go install github.com/golang/dep
    go install github.com/golang/dep/cmd/dep

    注意: dns-nameservers 10.41.132.9 有时域名解析失败,建议采用 10.30.1.9和8.8.8.8

    7. 设置docker守护进程的代理


    8. make all ,
    如果在执行check_deps时报错,可以将./scripts/check_deps.sh文件中 dep version dep check两个命令注释掉。



    部署fabric多机板
    1. sudo mkdir -p /etc/hyperledger/fabric/ && sudo chown -R jya /etc/hyperledger/

    2. 根据网络拓扑创建crypto-config.yaml配置文件,该文件可以以fabric-samples/first-network/crypto-config.yaml文件为蓝本,或者直接使用该文件。
    3.生成相关材料: cryptogen generate --config=./crypto-config.yaml --output ./crypto-config 。执行命令后,会在当前目录下生成文件夹 crypto-config,包含节点用户的秘钥以及证书文件,
    4. 通过scp命令将crypto-config文件夹拷贝到其它设备的/etc/hyperledger/fabric 目录下

    5 .创建/etc/hyperledger/fabric/configtx.ymal文件,该文件可以以fabric-samples/first-network/configtx.ymal文件为蓝本,或者直接使用该文件。


    6. 根据configtx.ymal生成创世区块以及通道等配置信息(位于10.43.33.120机器上)
    6.0 设置环境变量:export FABRIC_CFG_PATH=/etc/hyperledger/fabric
    6.1 创建channel-artifacts目录: mkdir -p /etc/hyperledger/fabric/channel-artifacts
    6.2 进入该目录: cd /etc/hyperledger/fabric/channel-artifacts
    6.3 创建创世区块: configtxgen -profile TwoOrgsOrdererGenesis -outputBlock genesis.block
    6.4 .创建通道事物: export CHANNEL_NAME=mychannel && configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel.tx -channelID $CHANNEL_NAME
    注意: 可以将mychannel替换成需要的通道名。
    6.5.定义org1的anchor peer: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
    6.6.定义org2的anchor peer: configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
    将会生成以下文件:channel.tx genesis.block Org1MSPanchors.tx Org2MSPanchors.tx

    7. 修改每台机器上的/etc/hosts文件,添加以下内容(需要根据自己的IP和网络拓扑决定)
    10.43.33.120 orderer.example.com
    10.43.33.122 peer0.org1.example.com
    10.43.33.122 peer0.org2.example.com
    10.43.33.125 peer1.org1.example.com
    10.43.33.125 peer1.org2.example.com

    8. 准备order节点启动所需的材料
    orderer 节点的执行环境目录下必须有以下文件及文件夹:./crypto-config、./msp、./tls、orderer.yaml、genesis.block
    orderer.yaml文件可以参考fabric-samples/config/orderer.yaml 文件,注意:
    需要将 ListenAddress: 127.0.0.1 改成 ListenAddress: 0.0.0.0
    需要将 TwoOrgsOrdererGenesis
    cd /etc/hyperledger/fabric/
    cp channel-artifacts/genesis.block channel-artifacts/
    cp -r ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/ ./
    如果上述命令启动orderer时报错,可以考虑执行下面的命令: cp -r ./crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/ .

    cp -r ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ ./
    创建日志目录: sudo mkdir -p /var/hyperledger/ && sudo chown -R jya /var/hyperledger/
    启动orderer节点: orderer start
    注意: 如果报 [orderer/commmon/multichannel] newLedgerResources -> PANI 004 Error creating channelconfig bundle: initializing channelconfig failed: could not create channel Orderer sub-group config: 以下错误,则需要删除 /data/hyperledger/目录,具体见orderer.yaml文件中的FileLedger的配置项

    注意: 需要将 orderer.yaml配置文件中的 LocalMSPID: SampleOrg改成 LocalMSPID: OrdererMSP,否则有可能报



    启动order节点: orderer start


    9. 启动peer0.org1节点。
    peer 节点的执行环境目录下必须有以下文件及文件夹:./msp、./tls、core.yaml、channel.tx 、 core.yaml
    9.1 在peer创建/etc/hyperledger/fabric/ 目录:
    sudo mkdir -p /etc/hyperledger/fabric/ && sudo chown -R jya /etc/hyperledger/ 。
    9.2 创建core.yaml配置文件,该文件可以以fabric-samples/config/core.yaml文件为蓝本,或者直接使用该文件。
    9.3 拷贝证书及可执行文件(在10.43.33.120机器上执行以下命令):
    scp -r ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ 10.43.33.122:/etc/hyperledger/fabric/
    scp -r ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/ 10.43.33.122:/etc/hyperledger/fabric/
    拷贝peer可执行文件: scp -r ./peer 10.43.33.122:/etc/hyperledger/fabric/
    9.4 创建日志目录: sudo mkdir -p /var/hyperledger/ && sudo chown -R jya /var/hyperledger/
    9.5 启动peer节点: peer node start

    10. 启动peer0.org2节点。
    peer 节点的执行环境目录下必须有以下文件及文件夹:./msp、./tls、core.yaml、channel.tx 、 core.yaml
    9.1 在peer创建/etc/hyperledger/fabric/ 目录:
    sudo mkdir -p /etc/hyperledger/fabric/ && sudo chown -R jya /etc/hyperledger/ 。
    9.2 创建core.yaml配置文件,该文件可以以fabric-samples/config/core.yaml文件为蓝本,或者直接使用该文件。
    scp bin/peer config/core.yaml 10.43.33.125:/etc/hyperledger/fabric/
    9.3 拷贝证书信息(在10.43.33.120机器上执行以下命令):
    scp -r ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ 10.43.33.125:/etc/hyperledger/fabric/
    scp -r ./crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/ 10.43.33.125:/etc/hyperledger/fabric/
    scp bin/peer config/core.yaml 10.43.33.125:/etc/hyperledger/fabric/(在10.43.33.119机器上执行命令)
    9.5 创建日志目录: sudo mkdir -p /var/hyperledger/ && sudo chown -R jya /var/hyperledger/
    9.5 启动peer节点: peer node start

    11. 在peer0.org1节点(10.43.33.122)上创建并加入channel
    export CORE_PEER_LOCALMSPID="Org1MSP"
    export CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel.tx --tls true --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 注意:如果报错,则需要却掉 --tls true 选项。
    加入channel: peer channel join -b mychannel.block

    12 更新peer0.org1的anchor节点
    export FABRIC_CFG_PATH=/etc/hyperledger/fabric
    peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --cafile /etc/hyperledger/fabric/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem


    13. 在peer0.org1节点(10.43.33.122)上安装并初始化chainchdoe(建议最好打包chaincode再安装,而不是直接调用peer chaincode install命令,否则有可能导致其它节点同样的chaincode无法实例化)
    chaincode一般放在GOPATH/src目录当中,并且引用时需要使用与GOATH/src的相对路径, -p参数尽量放在最后。
      安装chaincode: peer chaincode install -n mychannel -v 1.0 -p chaincode/chaincode_example02/go
    初始化chaincode: peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mychannel -c '{"Args":["init","A","10","B","10"]}' -P "OR ('Org1MSP.member')" -v 1.0

    14. 调用chaincode: $ peer chaincode query -C mychannel -n mychannel -c '{"Args":["query","A"]}'



    常见错误:
    创建channel时报错:
    Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
    可能是因为创建channel时指定了 --tls true 参数,去掉即可。


    错误描述:
    [channel: mychannel] Rejecting broadcast of config message from 10.43.33.122:45346 because of error: Failed to reach implicit threshold of 1 sub-policies, required 1 remaining: permission denied
    解决办法: 将orderer.yaml配置文件中的 LocalMSPID: SampleOrg改成 LocalMSPID: OrdererMSP,

    错误描述:
    在org1组织的peer0节点上加入通道(peer channel join -b mychannel.block)时,报错:
    MSP error: expected MSP ID SampleOrg, received Org1MSP
    姐姐办法,将 core.yaml配置文件中的 LocalMSPID: SampleOrg改成 LocalMSPID:Org1MSP,

    错误描述:
    安装chaincode时报错: Error: error getting chaincode code mychannel: <go, [env]>: failed with error: "exec: not started"
    解决拌饭: 可能是因为没有安装go语言开发环境。

  • 相关阅读:
    数据要求说明书
    详细设计说明书
    《机器学习》西瓜书 课后习题参考答案
    机器学习基础 基本术语
    (转)android UI进阶之仿iphone的tab效果
    (转)android UI进阶之弹窗的使用
    (转) Android UI学习 Tab的学习和使用
    (转) android UI进阶之布局的优化(二)
    名言警句
    php的IP转换成整型函数ip2long()出现负数
  • 原文地址:https://www.cnblogs.com/dablyo/p/10688216.html
Copyright © 2020-2023  润新知