在 hyperledger fabric 新增 User后重新编译 Docker 开发环境所需 Images
Hyperledger并不属于公有链(Public Chain,如:比特币),他是需要经过用户审查及认证才能加入区块链交易的私有链;它透过CA(Certificate Authority)来进行公钥、私钥、数字签章的发行,同时也要管理使用者的账户,确保实名制。除了第一道的用户认证关卡外,还有两个确保区块链信息安全的关卡。在储存交易记录的区块(Block)安全与隐私上,Hyperledger利用PK
在 hyperledger/fabric 新增 User后重新编译 Docker 开发环境所需 Images
作者:陳兆麟
Email:chenlin2@ms9.hinet.net
Hyperledger并不属于公有链(Public Chain,如:比特币),他是需要经过用户审查及认证才能加入区块链交易的私有链;它透过CA(Certificate Authority)来进行公钥、私钥、数字签章的发行,同时也要管理使用者的账户,确保实名制。除了第一道的用户认证关卡外,还有两个确保区块链信息安全的关卡。在储存交易记录的区块(Block)安全与隐私上,Hyperledger利用PKI加密机制的公、私钥来执行数字签章,进行区块的加密。第三个则是共识机制,3分之2的账本参与节点互相验证区块内的交易记录。通过共识机制同意的交易记录,就可以写入(Append Only)的共享账本来确保交易数据的不可窜改(Immutable)以及永久保存(Finality)。以下范例是 Hyperledger/fabric 在 docker 开发环境新增用户的流程 。
开发环境: Win7 (64 bit, RAM >=8G) , vagrant , blockchain, docker,golang
1. win7 安装 cygwin
(https://cygwin.com/install.html)
将安装之执行文件目录 (C:\cygwin64\bin) 设定在控制台系统 path 变量
win7 安装 virtualbox (VirtualBox-5.1.6-110634-Win.exe)
win7 安装 git (https://git-scm.com/downloads)
2.安装 fabric (0.6 release)
进入Win7 command shell:
$
mkdir -p d:\GoProjects\src\github.com\hyperledger
$
cd d:\GoProjects\src\github.com\hyperledger
$
git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric (0.6 release)
$
cd d:\GoProjects\src\github.com\hyperledger\fabric\devenv
$
vi Vagrantfile
新增 :
config.vm.network “forwarded_port”, guest: 22, host: 22
config.vm.network “forwarded_port”, guest: 3000, host: 3000
修正 :
vb.name = “hyperledger” (hyperledger 为 virtualbox 虚拟机器名称)
$vagrant up (第一次在 virtual box 产生虚拟机器 hyperledger需要一段时间)
3. 使用 putty (附录 1) 登录 hyperledger VM (username: vagrant,password:vagrant)
4. 在hyperledger VM使用 nvm 安装 node 最新版 (参考附录 4)
$
nvm use 6.7.0 (选择 node 版本)
$
node -v
v6.7.0
$
npm -v
3.10.3
5. 验证hyperledger已挂载 Win7 目录
hyperledger挂载点
($GOPATH/src/github.com/hyperledger/fabric)
已挂载 win 7 local machine目录
(d:\GoProjects\src\github.com\hyperledger\fabric)
可用 touch 指令新增 empty file (例如 touch abcd) 测试是否挂载成功
6. 新增使用者
$
cd $
GOPATH/src/github.com/hyperledger/fabric
$ vi membersrvc/membersrvc.yaml (新增使用者ruby:6avZQLwcUeaa)
$vi ./core/chaincode/chaincodetest.yaml
7. 重新编译 fabric-peer & fabric-membersrvc
$
make peer-image
$
make membersrvc-image
$
docker images
$
docker tag hyperledger/fabric-membersrvc:latest chenlin2/fabric-membersrvc:new
$
docker tag hyperledger/fabric-peer:latest chenlin2/fabric-peer:new (更名)
$
docker push chenlin2/fabric-peer:new (上传 docker hub)
$
docker push chenlin2/fabric-membersrvc:new
8.参考附录 (2) 在 Win7安装 Docker Toolbox (安装最新版)
(Win 10 可直接安装 Docker 请参考附录3 )
9. 桌面点选 (Docker Quickstart Terminal)
$
docker -v
Docker version 1.12.0, build 8eab29e
$
docker-machine ls (Docker Quickstart Terminal接口执行,确认虚拟机default 已安装)
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default virtualbox Running tcp://192.168.99.101:2376 v1.10.3
$
docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\user.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM FOR /f “tokens=*” %i IN (‘docker-machine env default’) DO %i
$
FOR /f “tokens=*” %i IN (‘docker-machine env default’) DO %i
$ docker-machine ls (确定虚拟机已经启动)
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.3
10. 使用 putty (见附录 1)登录虚拟机器
ip:192.168.99.100 (username=docker password=tcuser)
$
mkdir -p /c/Users/user/ictest/docker_blockchain
$
vi docker-compose.yml (如附录 5)
$
docker-compose up -d (启动 container)
11.登录至 dockerblockchain_vp0_1 容器
$docker exec -it dockerblockchain_vp0_1 bash
#
cd examples/chaincode/go/chaincode_example02
#
ls
chaincode_example02.go
#
go build ./ (编译 chaincode_example02.go)
#
ls
chaincode_example02 chaincode_example02.go
#
export CORE_CHAINCODE_ID_NAME=mycc
#
export CORE_PEER_ADDRESS=0.0.0.0:7051
#
./chaincode_example02 & (chaincode 启动接收外界送来的交易)
12. 在 win7下载安装 Postman
https://www.getpostman.com/apps (Postman-win64-4.7.1-Setup.exe)
Postman 具有好用的人机界面,藉REST API 在VP布署Chaincode
13. 检视已建立的 blockchain network
REST API字段输入:http://192.168.99.100:7050/network/peers
192.168.99.100 (来自虚拟机器default之IP), 7050定义于docker-compose.yml
14. User至vp (validating peer )注册验证新增user (ruby:6avZQLwcUeaa)是否有效
REST API字段输入: http://192.168.99.100:7050/registrar
{
“enrollId”: “ruby”,
“enrollSecret”: “6avZQLwcUeaa”
}
附录:
1.Win7 安装 putty:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
http://download.ithome.com.tw/article/index/id/1649
2.Win7 安裝Docker Toolbox:
https://www.docker.com/products/docker-toolbox
http://knight-.iteye.com/blog/2254627
http://rominirani.com/2015/08/15/docker-toolbox-setup-windows/
https://getcarina.com/docs/troubleshooting/troubleshooting-windows-docker-vm-startup/
http://dockone.io/article/594
3.Win 10 安裝Docker
http://blog.miniasp.com/post/2016/08/01/Docker-for-Windows-1-12-Released.aspx
4.hyperledger VM 安装 nvm & node
http://www.liquidweb.com/kb/how-to-install-nvm-node-version-manager-for-node-js-on-ubuntu-14-04-lts/
https://www.liquidweb.com/kb/how-to-install-node-js-via-nvm-node-version-manager-on-ubuntu-14-04-lts/
5.docker-compose.yaml
membersrvc:
image: chenlin2/fabric-membersrvc:new
command: membersrvc
vp0:
image: chenlin2/fabric-peer:new
ports:
-
“7050:7050”
environment:
-
CORE_PEER_ADDRESSAUTODETECT=true
-
CORE_VM_ENDPOINT=http://172.17.0.1:2375
-
CORE_LOGGING_LEVEL=DEBUG
-
CORE_PEER_ID=vp0
-
CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
-
CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
-
CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
-
CORE_SECURITY_ENABLED=true
-
CORE_SECURITY_ENROLLID=test_vp0
-
CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
links:
-
membersrvc
command: sh -c “sleep 5; peer node start –peer-chaincodedev”
6.陈兆麟 facebook
https://zh-cn.facebook.com/chaolin.chen.18
參考文獻:
1.https://github.com/hyperledger/fabric/tree/master/examples/chaincode/go/chaincode_example02
2.https://hyperledger-fabric.readthedocs.io/en/latest/Setup/Network-setup/
3.https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md
4.https://github.com/IBM-Blockchain/learn-chaincode
5.https://github.com/hyperledger/fabric/blob/master/docs/Setup/Network-setup.md
6.https://github.com/hyperledger/fabric/blob/master/docs/API/CoreAPI.md#rest-api
7.http://blockgeeks.com/guides/what-is-blockchain-technology-a-step-by-step-guide-than-anyone-can-understand/
8.https://developer.ibm.com/tv/the-creation-of-hyperledger-fabric-v1-for-stable-blockchain-networks/
9.https://yeasy.gitbooks.io/blockchain_guide/content/intro/what.html
10.http://www.ithome.com.tw/news/109182
11.https://1drv.ms/f/s!AkBmzWP0h-Vxbr7h1uTNsTMcPWI
12.https://1drv.ms/b/s!AkBmzWP0h-VxazOBOsVz8nGMLpM
13.https://1drv.ms/b/s!AkBmzWP0h-VxbLK7FOjH9IL5HHc
14.https://www.youtube.com/watch?v=24JAF9Eu1mk&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=74
15.https://www.youtube.com/watch?v=wSmJ-rwUo8I&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=73
16.https://www.youtube.com/watch?v=SOsn6MvGH60&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=72
更多推荐
所有评论(0)