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
网友评论