Deploy your own blockchain-hyperledger/fabric-02__ block chain

Source: Internet
Author: User
Tags error handling docker compose

1, Environmental structure Description:

The system uses the container to run, the construction process is simple, each component division of labor is clear:
1.docker-compose:docker container management;
2.Go Lang Sdk:go language development, compilation environment;
3.git:git Mirror Clone and commit;
4.Rest client:rest API test;
The main operations of the container are: Membersrv and peer;

2. Deployment Environment Readiness

3. Installation and Deployment
3.1 Pulling the mirror from the Dockerhub
A. Install and deploy Docker and Docker-compose, detailed procedures are described in using Docker Compose Deployment Services.
B. Pull the image

[Root@docker fabric] #docker pull hyperledger/fabric-peer:latest #拉取peer的镜像
[root@docker fabric] #docker Pull hyperledger/fabric-membersrvc:latest# Pull Memberserver Mirror
[Root@docker fabric]# Docker images# confirm Mirror Pull succeeded
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx                           latest              19146d5729dc        2 days ago          181.6 MB
docker.io/hyperledger/fabric-membersrvc   latest              b3654d32e4f9        9 weeks ago         1.417 GB
docker.io/hyperledger/fabric-peer         latest              21cb00fb27f4        9 weeks ago         1.423 GB

3.2 Docker-compose.yml Writing

[root@docker fabric]# pwd/opt/fabric [root@docker fabric]# ls docker-compose.yml Docker-compose.yml.old INFO [root@docker fabric]# more Docker-compose.yml Membersrvc:image:hyperledger/fabric-member
    SRVC ports:-"7054:7054" COMMAND:MEMBERSRVC vp0:image:hyperledger/fabric-peer Ports:-"7,050:7,050" -"7051:7051"-"7053:7053" Environment:-core_peer_addressautodetect=true-core_vm_endpoint=unix:///var/ run/docker.sock-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 volumes:-/var/run/:/var/run/ Links:-MEMBERSRVC command:sh-c "sleep 5; Peer node start--peer-chaincodedev "[Root@docker fabric]# 

3.3 Start
Save Docker-compose.yml to/opt/fabric directory, run docker-compose up command to start 2 containers (Memberserver and peer).
Here, we can have a fabric (although only one peer) that starts and runs Chaincode and has permission management:

[Root@docker fabric]# docker-compose up
Creating fabric_membersrvc_1
Creating fabric_vp0_1
attaching to Fabric_membersrvc_1, Fabric_vp0_1

Until the startup log shows the following, it indicates that the startup was successful:

Run Docker-compose PS to see the service and the corresponding port mappings:

In addition, common operations:

[Root@docker fabric]# docker-compose logs-f vp0# View Log
[Root@docker fabric]# docker-compose exec vp0 bash#exec to Vp0

3.4 Running and publishing Chaincode
A. Enter into peer $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go directory:

[Root@docker fabric]# docker-compose exec vp0 bash


We found that there are many use case Chaincode programs in this directory (based on the Go language), and we chose chaincode_example2 for deployment and testing.
B. Deploy Chaincode_example.
Copy Chaincode_example02 to $gopath/src

root@e33e7f4dceb3:/opt/gopath/src# CP $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_ Example02/chaincode_example02.go $GOPATH/src/

C. Compiling in $GOPATH/SRC

root@e33e7f4dceb3:/opt/gopath/src# go build./chaincode_example02.go 
root@e33e7f4dceb3:/opt/gopath/src# ls
chaincode_example02  chaincode_example02.go  github.com

The compilation succeeds in generating the Chaincodeexample02 file in the GOPATH/SRC directory. D. release chaincode to generate CHAINCODE_EXAMPLE02 files in the GOPATH/SRC directory. D. Release Chaincode run under GOPATH/SRC
CORE_CHAINCODE_ID_NAME=MYCC core_peer_address=0.0.0.0:7051./chaincode_example02

Until the word "Received registered" appears, it represents success.
3.5 Deploy,invoke and Query Chaincode
A.login
CLI mode:

Peer network login #用户名和密码在 Membersrvc.yaml file


Rest mode:

B.deploy
CLI mode

  Core_security_enabled=true core_security_privacy=true Peer Chaincode deploy-u jim-n mycc-c ' {"Args": ["Init", "a", "100" , "B", "200"]} '


Rest mode:

C.invoke
CLI mode

  Core_security_enabled=true core_security_privacy=true Peer Chaincode invoke-u jim-l golang-n mycc-c ' {"Args": ["Invoke "," A "," B "," 10 "]} '

A to B turn 10 dollars, you can see a into 90,b into 210

Aval = Bval = 210

Rest mode:

D. Query
CLI mode:

Peer Chaincode query-l golang-n mycc-c ' {"Args": ["Query", "B"]} '-U Jim

Rest mode:

Query to B got 10 dollars, check a, will get-10.

Summarize:
1. The above process demonstrates the fabric construction process;
2. Demonstrated the deployment of chaincode, consensus implementation and inquiry;
3. Demonstrates interaction with peer via CLI and Rest API;

Tip: Chaincode chaincode_example02.go use case program Community Download (https://raw.githubusercontent.com/hyperledger/fabric/master/ EXAMPLES/CHAINCODE/GO/CHAINCODE_EXAMPLE02/CHAINCODE_EXAMPLE02.GO) is problematic, compilation fails, and query times out:

Vp0_1         | 07:49:12.906 [rest] processchaincodeinvokeorquery, Erro af8 Error when querying chaincode:Error:Failed t o Execute transaction or query (Timeout expired while executing transaction)

Peer will appear:

14:57:01.368 [Shim] Debu: [Ca1a01d3]handling chaincodemessage of Type:range_query_state (state:ready) Error starting Sim ple chaincode:error Handling message: [Ca1a01d3-33e8-4fc2-be69-5ff8064f9b1a]chaincode handler FSM cannot handle message (range_query_state) with payload size (ten) while in State:ready

Workaround:
Use $GOPATH/SRC/GITHUB.COM/HYPERLEDGER/FABRIC/EXAMPLES/CHAINCODE/GO/CHAINCODE_EXAMPLE02, do not download.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.