写在最前面:
本文写于2017年7月份,基于当时的环境、步骤,搭建起来的。随着时间的推移,版本的更新,本文中有的步骤可能与现在的步骤不一样,还请移步最新的中文官网
https://github.com/IBM-Blockchain/marbles/blob/master/README-cn.md
Marbles项目的底层网络是Hyperledger Fabric(分布式的超级账本),该项目最终会呈献给我们通过图形化界面,可以用来操作marbles。可以添加用户,添加marble,删除marble,交易marble,这些操作都会记录到区块链上。
启动项目之前需要一些指定的设置,并且我们选择搭建本地的Hyperledger Network来运行项目。我的系统环境:Ubuntu16.04。
需要安装(版本号要严格按照下面的来设置):
验证安装:
$ git --version
git version 2.7.4
$ go version
go version go1.8.3 linux/amd64
$ echo $GOPATH
/media/jiang/newspace/project/mygo
$ docker -v
Docker version 17.06.0-ce, build 02c1d87
$ docker-compose -v
docker-compose version 1.14.0, build c7bdf9e
$ node -v
v6.10.0
$ npm -v
3.10.10
定位到存放目录,执行命令:
git clone https://github.com/IBM-Blockchain/marbles.git --depth 1
git checkout v3.0
下载所需的Docker镜像(下载速度慢的 设置镜像代理试试?)
cd marbles/scripts
chmod +x download-dockerimages.sh
sudo ./download-dockerimages.sh
脚本完成后会在命令行面板里看到:
hyperledger/fabric-ca latest 35311d8617b4 3 weeks ago 240 MB
hyperledger/fabric-ca x86_64-1.0.0-alpha 35311d8617b4 3 weeks ago 240 MB
hyperledger/fabric-couchdb latest f3ce31e25872 3 weeks ago 1.51 GB
hyperledger/fabric-couchdb x86_64-1.0.0-alpha f3ce31e25872 3 weeks ago 1.51 GB
hyperledger/fabric-kafka latest 589dad0b93fc 3 weeks ago 1.3 GB
hyperledger/fabric-kafka x86_64-1.0.0-alpha 589dad0b93fc 3 weeks ago 1.3 GB
hyperledger/fabric-zookeeper latest 9a51f5be29c1 3 weeks ago 1.31 GB
hyperledger/fabric-zookeeper x86_64-1.0.0-alpha 9a51f5be29c1 3 weeks ago 1.31 GB
hyperledger/fabric-orderer latest 5685fd77ab7c 3 weeks ago 182 MB
hyperledger/fabric-orderer x86_64-1.0.0-alpha 5685fd77ab7c 3 weeks ago 182 MB
hyperledger/fabric-peer latest 784c5d41ac1d 3 weeks ago 184 MB
hyperledger/fabric-peer x86_64-1.0.0-alpha 784c5d41ac1d 3 weeks ago 184 MB
hyperledger/fabric-javaenv latest a08f85d8f0a9 3 weeks ago 1.42 GB
hyperledger/fabric-javaenv x86_64-1.0.0-alpha a08f85d8f0a9 3 weeks ago 1.42 GB
hyperledger/fabric-ccenv latest 91792014b61f 3 weeks ago 1.29 GB
hyperledger/fabric-ccenv x86_64-1.0.0-alpha 91792014b61f 3 weeks ago 1.29 GB
设置Fabric Node SDK
cd marbles/scripts
bash setup_sdk.sh
脚本执行完成后,会在scripts
目录下生成fabric-sdk-node
文件夹。
那么这个脚本都执行了什么操作呢,请看下面:
#!/bin/bash
set -e
# 1 下载 SDK
git clone https://github.com/hyperledger/fabric-sdk-node.git
sleep 1
cd ./fabric-sdk-node
git checkout v1.0.0-alpha
git branch
sleep 1
# 2 安装依赖
npm install
npm install -g gulp
gulp ca
# 3 拷贝docker-compose 文件到SDK指定文件夹
cd ../
cp ./docker-compose-marblesv3.yaml fabric-sdk-node/test/fixtures
# 4 拷贝配置文件到SDK指定文件夹
cp ./config.json fabric-sdk-node/test/integration/e2e
启动网络
docker rm -f $(docker ps -aq)
cd ./fabric-sdk-node/test/fixtures
docker-compose -f docker-compose-marblesv3.yaml up -d
一旦执行成功,执行docker ps
命令,会看到docker中有8个运行中的容器:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e61cf829f171 hyperledger/fabric-peer "peer node start -..." 3 minutes ago Up 2 minutes 0.0.0.0:7056->7051/tcp, 0.0.0.0:7058->7053/tcp peer1
0cc1f5ac24da hyperledger/fabric-peer "peer node start -..." 3 minutes ago Up 2 minutes 0.0.0.0:8056->7051/tcp, 0.0.0.0:8058->7053/tcp peer3
7ab3106e5076 hyperledger/fabric-peer "peer node start -..." 3 minutes ago Up 3 minutes 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0
2bc5c6606e6c hyperledger/fabric-peer "peer node start -..." 3 minutes ago Up 3 minutes 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer2
513be1b46467 hyperledger/fabric-ca "sh -c 'fabric-ca-..." 3 minutes ago Up 3 minutes 0.0.0.0:8054->7054/tcp ca_peerOrg2
741c363ba34a hyperledger/fabric-orderer "orderer" 3 minutes ago Up 3 minutes 0.0.0.0:7050->7050/tcp orderer0
abaae883eb13 couchdb "tini -- /docker-e..." 3 minutes ago Up 3 minutes 0.0.0.0:5984->5984/tcp couchdb
2c2d51fe88c0 hyperledger/fabric-ca "sh -c 'fabric-ca-..." 3 minutes ago Up 3 minutes 0.0.0.0:7054->7054/tcp ca_peerOrg1
设置网络
定位到fabric-sdk-node/
目录下
创建channel
rm -rf /tmp/hfc-*
rm -rf ~/.hfc-key-store
node test/integration/e2e/create-channel.js
加入channel
node test/integration/e2e/join-channel.js
定位到marbles/
下,安装npm依赖
npm install
定位到marbles/scripts/
下,安装Chaincode
node install_chaincode.js
定位到marbles/scripts/
下,初始化Chaincode
node instantiate_chaincode.js
启动命令
gulp marbles3
出现下面关键字,说明启动成功了(在浏览器打开localhost:3001
)
------------------------------------------ Server Up - localhost:3001 ------------------------------------------
------------------------------------------ Websocket Up ------------------------------------------