Hyperledger 超级账本是区块链的一个应用。
> yum install -y ca-certificates git make gcc
> yum update -y
2.1 安装Docker环境
> yum -y install docker
> systemctl start docker
> docker -version
2.2 配合阿里云的镜像
> vi /etc/docker/daemon.json
加入配置
{
"registry-mirrors": ["https://aj2rgad5.mirror.aliyuncs.com"]
}
重启Docker
> systemctl daemon-reload
> systemctl restart docker.service
Docker-Compose是一个部署多个容器的简单但是非常必要的工具.
3.1 安装python-pip
yum install python-pip
pip install --upgrade pip
pip install docker-compose
4.1 安装Golang
> 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
4.2 配置环境变量
> echo "export GOPATH=~/go" >> /etc/profile
> echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
> source /etc/profile
5.1 安装Node
> cd ~
> wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz
> xz -d node-v8.11.3-linux-x64.tar.xz
> tar xvf node-v8.11.3-linux-x64.tar
> mv node-v8.11.3-linux-x64 /usr/local/node
5.2 配置环境变量
> echo "export NODE_HOME=/usr/local/node" >> /etc/profile
> echo "export PATH=/usr/local/node/bin:$PATH" >> /etc/profile
> source /etc/profile
python是已经安装好的,需要2.7以上版本。
> python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> 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
> 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
过程中提示
Trying to pull repository docker.io/hyperledger/fabric-kafka ...
manifest for docker.io/hyperledger/fabric-kafka:x86_64-1.1.0 not found
Error response from daemon: no such id: hyperledger/fabric-kafka:x86_64-1.1.0
使用阿里云镜像下载kafka,zookeeper
> docker pull hyperledger/fabric-kafka:latest
> docker pull hyperledger/fabric-zookeeper:latest
当前有的image为
> docker images
docker.io/hyperledger/fabric-zookeeper latest 1ce465be7112 2 months ago 1.39 GB
docker.io/hyperledger/fabric-kafka latest 4fed436fc0a0 2 months ago 1.4 GB
docker.io/hyperledger/fabric-ca x86_64-1.1.0 72617b4fa9b4 3 months ago 299 MB
hyperledger/fabric-ca latest 72617b4fa9b4 3 months ago 299 MB
docker.io/hyperledger/fabric-tools x86_64-1.1.0 b7bfddf508bc 3 months ago 1.46 GB
hyperledger/fabric-tools latest b7bfddf508bc 3 months ago 1.46 GB
docker.io/hyperledger/fabric-orderer x86_64-1.1.0 ce0c810df36a 3 months ago 180 MB
hyperledger/fabric-orderer latest ce0c810df36a 3 months ago 180 MB
docker.io/hyperledger/fabric-peer x86_64-1.1.0 b023f9be0771 3 months ago 187 MB
hyperledger/fabric-peer latest b023f9be0771 3 months ago 187 MB
docker.io/hyperledger/fabric-javaenv x86_64-1.1.0 82098abb1a17 3 months ago 1.52 GB
hyperledger/fabric-javaenv latest 82098abb1a17 3 months ago 1.52 GB
docker.io/hyperledger/fabric-ccenv x86_64-1.1.0 c8b4909d8d46 3 months ago 1.39 GB
hyperledger/fabric-ccenv latest c8b4909d8d46 3 months ago 1.39 GB
docker.io/hyperledger/fabric-baseos x86_64-0.4.6 220e5cf3fb7f 4 months ago 151 MB
9.1 修改配置
vi ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/base/peer-base.yaml
– CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2ecli_default
==>
– CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default
9.2 运行
~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/network_setup.sh up
9.3 进入命令容器
> docker exec -it cli bash
9.4 查询账户
> peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
输出
2018-06-20 08:45:56.887 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-20 08:45:56.887 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-20 08:45:56.887 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-20 08:45:56.887 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-20 08:45:56.888 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-20 08:45:56.889 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08C4A8A8D90510...6D7963631A0A0A0571756572790A0162
2018-06-20 08:45:56.889 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: 6F021C906EB9F2662458B3F4E8F48934BBEFCEB295F0B14151FBAA5F11B3CA27
Query Result: 180
2018-06-20 08:45:56.896 UTC [main] main -> INFO 008 Exiting....
9.5 执行转账
> 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-20 08:48:03.416 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-06-20 08:48:03.417 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-06-20 08:48:03.419 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 003 Using default escc
2018-06-20 08:48:03.419 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 004 Using default vscc
2018-06-20 08:48:03.419 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 005 java chaincode disabled
2018-06-20 08:48:03.420 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0ABF070A6708031A0C08C3A9A8D90510...696E766F6B650A01620A01610A023130
2018-06-20 08:48:03.420 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: A6FD1C8FC3AAD3B940E794CC2B0488996DF4DAA4FD0D904B67B768340C4C7DF2
2018-06-20 08:48:03.430 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0ABF070A6708031A0C08C3A9A8D90510...89C6A8D31CB01054AE16D4FAA468353C
2018-06-20 08:48:03.430 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 99AA011F301071B8C8745AF441C1CB03BAAAA8149E89BEB6A412336E2158D8D0
2018-06-20 08:48:03.437 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> DEBU 00a ESCC invoke result: version:1 response: payload:"\n T\234\371\363`\271\237\376g\301\033&\315\2706h\330\364xg\377\300\231\341\365\304511Znv\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\005\n\007\n\001b\022\002\010\005\032\010\n\001a\032\003130\032\010\n\001b\032\003170\032\003\010\310\001\"\013\022\004mycc\032\0031.0" endorsement:\n\007Org1MSP\022\252\006-----BEGIN CERTIFICATE-----\nMIICKTCCAc+gAwIBAgIRAJvAYqXuvwoRP/G739BTE4UwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwNjIwMDgxNzQyWhcNMjgwNjE3MDgxNzQy\nWjBqMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzENMAsGA1UECxMEcGVlcjEfMB0GA1UEAxMWcGVlcjAub3Jn\nMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABG/LSCir5+Yw\nqpH++NOhApP8M9tPJK9MS3GfHOWE0pcX5EqLR4TE85CPXntfnb7VlO1YiHqGxQ2K\nL2zHFteNtUCjTTBLMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1Ud\nIwQkMCKAIH7B8kpnyqns5O611DlncnkZJAruFCemkquaIEK6C7t3MAoGCCqGSM49\nBAMCA0gAMEUCIQCtZSZpCk/J9A0oZVrx2dedn6UhKbYnWZrgQivUBTxPrQIgQzAf\nJRg5uFZRtA4OFDGGihE6aDFPCsI9EvrMFQlDuDk=\n-----END CERTIFICATE-----\n" signature:"0D\002 v\361\256\272\222l\310\024\267\276#\322\214\256\335\3439\026@;\023sP^\261\025{\267\033\210%\033\002 k\361|\325\326\325\212\254\323a\364v\231\2434\320\211\306\250\323\034\260\020T\256\026\324\372\244h5<" >
2018-06-20 08:48:03.437 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 00b Chaincode invoke successful. result: status:200
> ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/network_setup.sh down