neo blockchain book
  • NEOHOPE's Blockchain Book
  • 概述
    • 本书内容
    • 读者定位
    • 本书约定
    • 项目对比
    • 名词释义
  • 基本原理
    • 区块链
    • 智能合约
    • 交易所
    • 系统架构
  • 基础算法
    • 默克尔树
    • Bloom过滤器
    • 公钥私钥及椭圆曲线
  • 共识算法
    • 分布式系统
    • Paxos与Raft算法
    • 拜占庭容错算法
  • Bitcoin
    • 整体架构
    • 状态转换
    • 区块确认
    • 分叉处理
    • P2P
    • 脚本
    • 钱包
    • 使用
    • 编译(Ubuntu)
    • 私链搭建(Linux)
    • 私链搭建(Docker)
  • Ethereum
    • 整体架构
    • 状态转换
    • 区块确认
    • 使用
    • Remix IDE环境搭建(Ubuntu16)
    • 智能合约编写01
    • 智能合约编写02
    • 智能合约编写03
    • 智能合约编写04
    • 编译(MacOS)
    • 私链搭建
  • EOS
    • 整体架构
    • 使用
    • 智能合约使用(单机单节点单钱包)
    • 智能合约使用(单机单节点多钱包)
    • 编写简单的智能合约
    • 编写有数据存储的智能合约
    • 编译(Linux)
    • 私链搭建(单机多节点)
    • 私链搭建(多机多节点)
  • Fabric
    • 整体架构
    • 身份管理
    • 共识达成
    • 使用
    • 智能合约介绍
    • 智能合约使用01
    • 智能合约使用02
    • 编译(MacOS)
    • 私链搭建(Ubuntu)
    • 在私链中添加一个机构
  • Cosmos
    • 整体架构
    • Zone与Hub
    • 使用
  • IPFS
    • 整体架构
    • 使用
    • 编译(MacOS)
    • 私链搭建
  • 然后呢?
由 GitBook 提供支持
在本页
  • 安装需要的软件
  • 设置环境变量
  • 准备环境
  • 运行私链
  • 查看容器列表
  • 查看交易细节
  • 清理工作
  1. Fabric

私链搭建(Ubuntu)

安装需要的软件

#ubuntu18
sudo apt-get install curl docker docker-compose golang nodejs npm python

软件

版本

docker

17.06.2-ce+

docker-compose

1.14.0+

go

1.9.x+

nodejs

8.9.x

bon

5.6.0

python

2.7.x

设置环境变量

#~/.bashrc
export GOPATH=$HOME/gopath
export PATH=$PATH:$GOPATH/bin

准备环境

#下载脚本
wget https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh

#运行脚本,可以考虑将里面的docker命令前增加su
./bootstrap.sh

运行私链

cd fabric-samples/first-network

#初始化配置
./byfn.sh -m generate

#这个脚本,做了以下事情:
#创建证书
#生成第一个区块
#生成MSP的锚节点
#启动管道mychannel
#管道包括了两个组织,org1和org2
#org1有两个节点peer0,peer1
#org2有两个节点peer0,peer1
#然后在org1和org2的peer0节点部署了智能合约
#查询合约
#合约转账
#查询合约
sudo ./byfn.sh -m up
##### Generate certificates using cryptogen tool #########
#########  Generating Orderer Genesis block ##############
#######    Generating anchor peer update for Org1MSP   ##########
#######    Generating anchor peer update for Org2MSP   ##########
===================== Channel "mychannel" is created successfully =====================
===================== peer0.org1 joined on the channel "mychannel" =====================
===================== peer1.org1 joined on the channel "mychannel" =====================
===================== peer0.org2 joined on the channel "mychannel" =====================
===================== peer1.org2 joined on the channel "mychannel" =====================
===================== Anchor peers for org "Org1MSP" on "mychannel" is updated successfully =====================
===================== Anchor peers for org "Org2MSP" on "mychannel" is updated successfully =====================
===================== Chaincode is installed on peer0.org1 =====================
===================== Chaincode is installed on peer0.org2 =====================
===================== Chaincode Instantiation on peer0.org2 on channel 'mychannel' is successful =====================
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
Query Result: 100
===================== Query on peer0.org1 on channel 'mychannel' is successful =====================
===================== Invoke transaction on peer0.org1 on channel 'mychannel' is successful =====================
===================== Chaincode is installed on peer1.org2 =====================
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
Query Result: 90
===================== Query on peer1.org2 on channel 'mychannel' is successful =====================
========= All GOOD, BYFN execution completed ===========

查看容器列表

sudo docker ps
CONTAINER ID        IMAGE                                                                                                  COMMAND                  CREATED             STATUS              PORTS                                              NAMES
92b34725eb84        dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab   "chaincode -peer.add…"   14 minutes ago      Up 14 minutes                                                          dev-peer1.org2.example.com-mycc-1.0
fc09cb911752        dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9   "chaincode -peer.add…"   15 minutes ago      Up 15 minutes                                                          dev-peer0.org1.example.com-mycc-1.0
bed1373228f0        dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b   "chaincode -peer.add…"   15 minutes ago      Up 15 minutes                                                          dev-peer0.org2.example.com-mycc-1.0
bfa16375cae2        hyperledger/fabric-tools:latest                                                                        "/bin/bash"              16 minutes ago      Up 16 minutes                                                          cli
97bbdad5a204        hyperledger/fabric-orderer:latest                                                                      "orderer"                16 minutes ago      Up 16 minutes       0.0.0.0:7050->7050/tcp                             orderer.example.com
9743b8716888        hyperledger/fabric-peer:latest                                                                         "peer node start"        16 minutes ago      Up 16 minutes       0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
d3ea4a45d1f3        hyperledger/fabric-peer:latest                                                                         "peer node start"        16 minutes ago      Up 16 minutes       0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.example.com
514337d43df4        hyperledger/fabric-peer:latest                                                                         "peer node start"        16 minutes ago      Up 16 minutes       0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.example.com
3ced253d6808        hyperledger/fabric-peer:latest              

查看交易细节

sudo docker logs dev-peer0.org2.example.com-mycc-1.0
ex02 Init
Aval = 100, Bval = 200

sudo docker logs dev-peer0.org1.example.com-mycc-1.0
ex02 Invoke
Query Response:{"Name":"a","Amount":"100"}
ex02 Invoke
Aval = 90, Bval = 210

sudo docker logs dev-peer1.org2.example.com-mycc-1.0
ex02 Invoke
Query Response:{"Name":"a","Amount":"90"}

清理工作

sudo ./byfn.sh -m down
上一页编译(MacOS)下一页在私链中添加一个机构

最后更新于7年前