Hyperledger Fabric v1.1.0安装记录(国内源版)

Hyperledger Fabric v1.1.0安装记录(国内源版)

1. 安装虚拟机

虚拟机软件采用:VirtualBox

操作系统选择:Ubuntu 14.04

内存:4G

CPU:2核

硬盘:20G

2.(可选)更改ssh配置使得root可以通过SSH登录

为root设置密码

sudo passwd root

编辑/etc/ssh/sshd_config配置文件,允许root用户通过SSH登录

sudo vi /etc/ssh/sshd_config
修改内容
PermitRootLogin yes

重启sshd服务

sudo service ssh restart

3. 安装必要的工具

sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common git make gcc

4. 安装Docker(17.06.2-ce or greater is required)

4.1 使用国内的阿里源安装Docker

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get -y update

sudo apt-get install docker-ce

4.2 添加阿里云的Docker hub镜像

sudo mkdir -p /etc/docker

vi /etc/docker/daemon.json

在daemon.json中添加

{

    "registry-mirrors" : ["https://obou6wyb.mirror.aliyuncs.com"]  

}

4.3 重新启动Docker服务

5. 安装docker-compose(version 1.14.0 or greater)

curl -L https://get.daocloud.io/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m`>/usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

docker-compose version

6. 安装Golang环境(Go version 1.10.x is required

cd ~

wget https://studygolang.com/dl/golang/go1.10.1.linux-amd64.tar.gz

tar -C /usr/local -xzf go1.10.1.linux-amd64.tar.gz

mkdir go

Go环境变量设置
vi /etc/profile

添加

           export GOPATH=~/go

           export PATH=$PATH:/usr/local/go/bin

使环境变量生效

source /etc/profile

go version

7. 安装Node.js和NPM(version 8.9.x or greater,但目前不支持9.x)

cd ~

wget https://npm.taobao.org/mirrors/node/v8.11.2/node-v8.11.2-linux-x64.tar.xz

mkdir node

tar xvf node-v*.tar.?z --strip-components=1 -C ./node

rm -rf node-v*

mkdir node/etc

echo 'prefix=/usr/local' > node/etc/npmrc

sudo mv node /opt/

sudo chown -R root: /opt/node

sudo ln -s /opt/node/bin/node /usr/local/bin/node

sudo ln -s /opt/node/bin/npm /usr/local/bin/npm

node -v

npm -v

8. python版本确认(2.7, npm install需要)

python --version

9. hyperledger fabric源代码下载

mkdir -p ~/go/src/github.com/hyperledger

cd ~/go/src/github.com/hyperledger/

git clone https://github.com/hyperledger/fabric.git

cd ~/go/src/github.com/hyperledger/fabric/

git checkout v1.1.0

10. hyperledger fabric docker镜像下载

cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/

source download-dockerimages.sh -c x86_64-1.1.0 -f x86_64-1.1.0

docker pull hyperledger/fabric-kafka:latest

docker pull hyperledger/fabric-zookeeper:latest

docker images

11. 启动Fabric网络完成chaincode测试(运行例子:e2e_cli)

注意:修改示例源代码中的一个错误(少了一个下划线)

cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/base/

vi peer-base.yaml

将以下内容:
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2ecli_default
修改为:
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default
运行示例

cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/

./network_setup.sh up

成功运行后显示:


image

查看启动的容器

docker ps
可以看到启动了14个容器

root@fabric:~/go/src/github.com/hyperledger/fabric/examples/e2e_cli# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0a431c0eb49b dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode -peer.addΒ 2 hours ago Up 2 hours dev-peer1.org2.example.com-mycc-1.0
40e46c280dd5 dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 "chaincode -peer.addΒ 2 hours ago Up 2 hours dev-peer0.org1.example.com-mycc-1.0
3af964e100dc dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b "chaincode -peer.addΒ 2 hours ago Up 2 hours dev-peer0.org2.example.com-mycc-1.0
44d6376c1892 hyperledger/fabric-tools "/bin/bash -c './scrΒ 2 hours ago Up 2 hours cli
fb2560a9f070 hyperledger/fabric-orderer "orderer" 2 hours ago Up 2 hours 0.0.0.0:7050->7050/tcp orderer.example.com
406bf8616a16 hyperledger/fabric-kafka "/docker-entrypoint.Β 2 hours ago Up 2 hours 9093/tcp, 0.0.0.0:32806->9092/tcp kafka2
42c8a52d90fa hyperledger/fabric-kafka "/docker-entrypoint.Β 2 hours ago Up 2 hours 9093/tcp, 0.0.0.0:32805->9092/tcp kafka0
643a2e3d0674 hyperledger/fabric-kafka "/docker-entrypoint.Β 2 hours ago Up 2 hours 9093/tcp, 0.0.0.0:32804->9092/tcp kafka1
3cfb4e12c46d hyperledger/fabric-kafka "/docker-entrypoint.Β 2 hours ago Up 2 hours 9093/tcp, 0.0.0.0:32803->9092/tcp kafka3
dc9006941dae hyperledger/fabric-zookeeper "/docker-entrypoint.Β 2 hours ago Up 2 hours 0.0.0.0:32800->2181/tcp, 0.0.0.0:32798->2888/tcp, 0.0.0.0:32797->3888/tcp zookeeper0
6b38b28db643 hyperledger/fabric-zookeeper "/docker-entrypoint.Β 2 hours ago Up 2 hours 0.0.0.0:32802->2181/tcp, 0.0.0.0:32801->2888/tcp, 0.0.0.0:32799->3888/tcp zookeeper1
8e7879cd3a5e hyperledger/fabric-zookeeper "/docker-entrypoint.Β 2 hours ago Up 2 hours 0.0.0.0:32796->2181/tcp, 0.0.0.0:32795->2888/tcp, 0.0.0.0:32794->3888/tcp zookeeper2
11393db54042 hyperledger/fabric-peer "peer node start" 2 hours ago Up 2 hours 0.0.0.0:10051->7051/tcp, 0.0.0.0:10052->7052/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
896a220ea3a4 hyperledger/fabric-peer "peer node start" 2 hours ago Up 2 hours 0.0.0.0:8051->7051/tcp, 0.0.0.0:8052->7052/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
8fa87ebdfcdf hyperledger/fabric-peer "peer node start" 2 hours ago Up 2 hours 0.0.0.0:7051-7053->7051-7053/tcp peer0.org1.example.com
bce7b0b2ec7b hyperledger/fabric-peer "peer node start" 2 hours ago Up 2 hours 0.0.0.0:9051->7051/tcp, 0.0.0.0:9052->7052/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com

查询测试

打开一个命令行窗口,关联cli节点
docker exec -it cli bash

查询a账户余额:
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

查询结果如下:

2018-06-09 20:24:13.850 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-09 20:24:13.850 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-09 20:24:13.850 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-09 20:24:13.850 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-09 20:24:13.850 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-09 20:24:13.850 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08EDEEF0D80510...6D7963631A0A0A0571756572790A0161 
2018-06-09 20:24:13.850 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 09621D7F31527CC5C54040210F606B75B8CBEB132480A46F7175E7526BB2AA01 
Query Result: 90
2018-06-09 20:24:13.864 UTC [main] main -> INFO 008 Exiting.....

可以看到账户a中余额为90

查询b账户余额:
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}'
结果:

2018-06-09 20:31:34.011 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-09 20:31:34.011 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-09 20:31:34.011 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-09 20:31:34.011 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-09 20:31:34.011 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-09 20:31:34.011 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABE070A6608031A0B08A6F2F0D80510...6D7963631A0A0A0571756572790A0162 
2018-06-09 20:31:34.012 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 7E501205104DC7747C820B38E427B7CDFCE985960B7C3648DAC6604D84E3F57C 
Query Result: 210

b账户余额为210

转账测试(b向a转账30):

peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","b","a","30"]}'

返回结果

2018-06-09 20:36:49.199 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-09 20:36:49.199 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-09 20:36:49.202 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-09 20:36:49.202 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-09 20:36:49.202 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-09 20:36:49.203 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABE070A6608031A0B08E1F4F0D80510...696E766F6B650A01620A01610A023330 
2018-06-09 20:36:49.203 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: ADBF4A197225417D9EA86D06BEC6FA975029848160158DA7E5BFF1E99A7BA71C 
2018-06-09 20:36:49.217 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0ABE070A6608031A0B08E1F4F0D80510...3BE53BB45BA118523F2027F42F0B6929 
2018-06-09 20:36:49.217 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 6FC7047121A5D628E5A93AD6F95E6043E4E4E8BA4A8D7931D6CF206EC20F82CC 
2018-06-09 20:36:49.351 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response:<status:200 message:"OK" > payload:"\n \032@\nMHC\322JD\240\216\325\243\244\363\320\212\036\207\325\211C\010<\211iM\206\357;\321\305\022Z\nF\022\024\n\004lscc\022\014\n\n\n\004mycc\022\002\010\003\022.\n\004mycc\022&\n\007\n\001a\022\002\010\004\n\007\n\001b\022\002\010\004\032\010\n\001a\032\003120\032\010\n\001b\032\003180\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement:<endorser:"\n\007Org1MSP\022\252\006-----BEGIN CERTIFICATE-----\nMIICKTCCAc+gAwIBAgIRAJB4lmWqlHlI2zkXJm58FkAwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwNjA5MTgwODIxWhcNMjgwNjA2MTgwODIx\nWjBqMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzENMAsGA1UECxMEcGVlcjEfMB0GA1UEAxMWcGVlcjAub3Jn\nMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHCfdWvJn2Sp\nJIL3Rvgfdkf2vqRQ9nBPBKlN/cwj6JwgczX28snKmutRNWQcIGw8U1FncR5eFQKB\nKvwZIGFos+CjTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1Ud\nIwQkMCKAINea69E1VPRsWH3f7E1BEoSN8o1RiLtLoyHztSAYucMgMAoGCCqGSM49\nBAMCA0gAMEUCIQCB8GLaewodQIZPBbcAvslPKqt0ffCumEQI99Y2YW5NnAIgOehq\nBdz+h+Bj7+SnW+Hg113sgv8sdJmHqfQLQc1ZrsE=\n-----END CERTIFICATE-----\n" signature:"0E\002!\000\360\327\030\t\320\005\376\227\326r\326t\321\367\361E\242\202\251Q\023\302\306\336U]!*\030-\236a\002 3:e\2108$}\214\307\034\323\246\004\315C&;\345;\264[\241\030R? '\364/\013i)" > 
2018-06-09 20:36:49.351 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200 
2018-06-09 20:36:49.352 UTC [main] main -> INFO 00c Exiting.....

说是成功了,那就再查询一下a账户和b账户的余额吧:

peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

2018-06-09 20:38:47.828 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-09 20:38:47.828 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-09 20:38:47.828 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-09 20:38:47.828 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-09 20:38:47.828 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-09 20:38:47.829 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08D7F5F0D80510...6D7963631A0A0A0571756572790A0161 
2018-06-09 20:38:47.829 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: AF7513323F67F783382AF1BA9D1181DB21769E2EC880782CBE6C3EC43AF70116 
Query Result: 120
2018-06-09 20:38:47.841 UTC [main] main -> INFO 008 Exiting.....
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","b"]}' 

2018-06-09 20:39:46.775 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-09 20:39:46.775 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-09 20:39:46.775 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-09 20:39:46.775 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-09 20:39:46.775 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-09 20:39:46.776 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C0892F6F0D80510...6D7963631A0A0A0571756572790A0162 
2018-06-09 20:39:46.776 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: D4AD6FD26B84F35708093CA84ADB0AFBE49039558DFB4D58AC7048E118AEFF45 
Query Result: 180
2018-06-09 20:39:46.789 UTC [main] main -> INFO 008 Exiting.....

a账号剩余120,b账号剩余180元,结果正确

12. 关闭fabric网络,结束测试

先从cli节点的bash退出到宿主系统下
exit

关闭fabric网络:

cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/

./network_setup.sh down
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,132评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,802评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,566评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,858评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,867评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,695评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,064评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,705评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,915评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,677评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,796评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,432评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,041评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,992评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,223评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,185评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,535评论 2 343

推荐阅读更多精彩内容