CentOS Build Fabric-1.0

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Since April 2017 fabric-1.0 Alpha has been released, Fabric-1.0 has experienced alpha, ALPHA2, Beta, RC1, 1.0 and other versions. Compared with fabric-0.6, fabric-1.0 has undergone great changes in architecture and roles, and its node type is divided into peer, Orderer, CA, client, so building a fabric-1.0 network is more complex for enthusiasts who have just come into contact with fabric. On the basis of building experiments on various versions of fabric-1.0, this paper summarizes the various construction methods of fabric-1.0.0.

First, prepare

1.1 Installing Git

sudo yum install git

1.2 Installation and Configuration Golang (>=1.7)

1.2.1 Uninstalling the lower version of Golang

sudo yum remove golangsudo yum autoremove

1.2.2 Download and unzip the go binary package

Download Link: https://golang.org/dl/
Download: https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
Because GFW, so backed up a copy on the Baidu Cloud: Link: http://pan.baidu.com/s/1c2lJrG0 Password: 7pye

Extract:

sudo tar -xvf go1.8.1.linux-amd64.tar.gz -C /usr/local/

1.2.3 Setting Environment variables

At the end of the/etc/profile file (valid for all users), add:

export GOROOT=/usr/local/goexport GOBIN=$GOROOT/binexport PATH=$PATH:$GOBINexport GOPATH=/home/hyperledger/gopath

Environment variables take effect:

source /etc/profile

1.2.4 Test

Perform

go version

1.3 Installing and configuring Docker (>=1.12)

Reference: https://docs.docker.com/engine/installation/linux/docker-ce/centos/

1.3.1 Uninstalling the lower version of Docker

sudo yum remove docker \                  docker-common \                  container-selinux \                  docker-selinux \                  docker-engine

1.3.2 mounting Docker-ce (from repository)

Installing Yum-utils and wget

sudo yum install -y yum-utilssudo yum install -y wget

Configure system mirroring (if not configured)

cd /etc/yum.repos.dsudo wget http://mirrors.163.com/.help/CentOS7-Base-163.reposudo yum clean allsudo yum makecachesudo yum update -y

Add Stable Repository

sudo yum-config-manager \    --add-repo \    https://download.docker.com/linux/centos/docker-ce.repo

Installing Docker-ce

sudo yum makecache fastsudo yum install docker-ce

Start Docker

sudo systemctl start docker

1.3.3 Configuring the use of the free sudo docker

Add Docker User group (if not present)

sudo groupadd docker

Add a user to the Docker user group

sudo gpasswd -a ubuntu docker

Restarting the Docker service

sudo service docker restart

Restart Group or restart X session

newgrp - docker或pkill X

1.3.4 Configuring Fast Docker Mirroring

sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f8c3f422.m.daocloud.io

Restarting the Docker service

sudo systemctl restart docker

1.3.5 Testing Docker

Enter Docker version to view versions


Docker-version

1.4 Installing and configuring Docker Compose (>=1.8.1)

Reference: https://docs.docker.com/compose/install/

1.4.1 Get

sudo curl -L "https://github.com/docker/compose/releases/download/1.12.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

or get from file (link: http://pan.baidu.com/s/1dFu4Jgl password: 329z)

Add Execute Permissions

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

1.4.2 Test

Execute Docker-compose version to get results



Docker-compose-version

1.5 Installing PIP and other packages

Installing GCC

sudo yum install -y gcc gcc-c++ kernel-develsudo yum install -y python-devel libxslt-devel libffi-devel openssl-devel

Download get-pip.py

wget https://bootstrap.pypa.io/get-pip.py

Install PIP

sudo python get-pip.py

Install additional Packages

sudo pip install --upgrade pipsudo pip install behave nose docker-composesudo pip install -I flask python-dateutil pytz pyyaml couchdb flask-cors request pyOpenSSL pysha3 grpciosudo pip install urllib3 ndg-httpsclient pyasn1 ecdsa python-slugify grpcio-tools jinja2 b3j0f.aop six

Second, compile the fabric source code

2.1 Get the Fabric source code

Clone source

cd $GOPATH/srcmkdir -p github.com/hyperledgercd github.com/hyperledgergit clone https://github.com/hyperledger/fabric.git

2.2 Building Configtxgen

cd $GOPATH/src/github.com/hyperledger/fabricmake configtxgen# if you see an error stating - 'ltdl.h' file not foundsudo apt install libtool libltdl-dev# then run the make againmake configtxgen

If the execution succeeds, it appears:



Make-configtxgen

2.3 Configuring Gotools

Because Gotools is required to download during the compilation process, it may fail to download if the VPN is not configured, so you will need to download the Gotools in advance.
Copy Gotools.tar to any directory
Create the/opt/gotools directory and extract it to this directory

sudo mkdir –p /opt/gotoolstar –xvf gotools.tar –C /opt/gotools

2.4 Pull Fabric-baseimage Image

docker pull hyperledger/fabric-baseimage:x86_64-0.3.0

2.5 Modifying Makefile

Modify the makefile file under the fabric directory
Add to



Makefile-01
makefile-02
makefile-03

If you do not have Java Chaincode or Java tools to download, you can modify


makefile-04

2.6 Compiling Fabric

2.6.1 compiling Orderer and peer

Compile orderer on the Orderer node

make orderer

Peer is compiled at peer node

make peer

When the compilation is complete, you can start the appropriate service

2.6.2 Compiling images

Compiling orderer images

make orderer-docker

Compiling a peer image

make peer-docker

2.6.3 Other

make all //编译所有组件make checks //运行所有的测试和检查make cryptogen //创建一个本地的加密生成工具make clean //清除所有编译项make dist-clean //清除所有编译项及移除本地持久化状态

Third, download the Docker image of fabric

3.1 Directly download Docker image

Take mirrors directly from the Docker image

docker pull hyperledger/fabric-peer:x86_64-1.0.0docker pull hyperledger/fabric-orderer:x86_64-1.0.0docker pull hyperledger/fabric-ccenv:x86_64-1.0.0docker pull hyperledger/fabric-ca:x86_64-1.0.0docker pull hyperledger/fabric-baseos:x86_64-0.3.0docker pull hyperledger/fabric-tools:x86_64-1.0.0docker tag docker.io/hyperledger/fabric-ca:x86_64-1.0.0 hyperledger/fabric-ca:latestdocker tag docker.io/hyperledger/fabric-peer:x86_64-1.0.0 hyperledger/fabric-peer:latestdocker tag docker.io/hyperledger/fabric-orderer:x86_64-1.0.0 hyperledger/fabric-orderer:latestdocker tag docker.io/hyperledger/fabric-ccenv:x86_64-1.0.0 hyperledger/fabric-ccenv:latestdocker tag docker.io/hyperledger/fabric-tools:x86_64-1.0.0 hyperledger/fabric-tools:latest

3.2 Using scripts in e2e_cli to get mirrors

cd $GOPATH/src/github.com/hyperledger/fabriccd examples/e2e_clichmod +x download-dockerimages.sh./download-dockerimages.sh

This process may be slow, workaround: Import from a Docker image that has already been downloaded

3.3 Importing and exporting mirrors

Suppose a machine's image has been downloaded
Export image

docker save 7182c260a5ca > ./fabric-ccenv-x86_64-1.0.0.tar

Copy to another machine, import the image

docker load < /home/hyperledger/Images/fabric-ccenv-x86_64-1.0.0.tar

Execute again. The/download-dockerimages.sh does not download the image from the Docker hub, and the execution is completed soon

Iv. implementation of the fabric example

4.1 Starting the Network

Download Fabric-sample

cd $GOPATH/src/github.com/hyperledgergit clone https://github.com/hyperledger/fabric-samples

Download Platform-specific Binaries

cd fabric-samplescurl -sSL https://goo.gl/iX9dek | bash

Start

cd fabric-samples/first-network./byfn.sh -m generate./byfn.sh -m up

4.2 Cleanup

Clean container

docker rm -f $(sudo docker ps -aq)

Or

docker-compose -f docker-compose-cli.yaml down

Clean image

docker rmi <IMAGE ID> <IMAGE ID> <IMAGE ID>

Such as:

docker rmi 362 c76 c10

Five, CA server configuration

5.1 Getting and compiling FABRIC-CA

5.1.1 Installing Libtool and Libtdhl-dev

sudo yum install libtool-ltdl-devel

5.1.2 Download Fabric-ca

cd $GOPATH/src/github.com/hyperledger/git clone https://github.com/hyperledger/fabric-ca

5.1.3 Installation Fabric-ca

sudo go get -u github.com/hyperledger/fabric-ca/cmd/...

5.1.4 Start Fabric-ca-server

fabric-ca-server start -b admin:adminpw

5.2 Registration Test

Enroll Root User

export FABRIC_CA_CLIENT_HOME=/home/hyperledger/gopath/src/github.com/hyperledger/fabric-ca/client/adminfabric-ca-client enroll -u http://admin:adminpw@localhost:7054

Register Peer0

fabric-ca-client register --id.name peer0 --id.type peer --id.affiliation org1 --id.secret peer0pw

Enroll Peer0

export FABRIC_CA_CLIENT_HOME=/home/hyperledger/gopath/src/github.com/hyperledger/fabric-ca/client/peer0fabric-ca-client enroll -u http://peer0:peer0pw@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/localMspConfig

Register Orderer0

export FABRIC_CA_CLIENT_HOME=/home/hyperledger/gopath/src/github.com/hyperledger/fabric-ca/client/adminfabric-ca-client register --id.name orderer0 --id.type client --id.affiliation org2 --id.secret orderer0pw

Enroll Orderer0

export FABRIC_CA_CLIENT_HOME=/home/hyperledger/gopath/src/github.com/hyperledger/fabric-ca/client/orderer0fabric-ca-client enroll -u http://orderer0:orderer0pw@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/localMspConfig

The PEER0 certificate and ORDERER0 certificate are generated, a copy of Signcerts in Localmspconfig is named Admincerts, and the certificate is packaged to the appropriate node

5.3 Getting FABRIC-CA images

5.3.1 Compiling FABRIC-CA image

cd $GOPATH/github.com/hyperledger/fabric-camake docker

5.3.2 obtaining a CA image from the Docker hub

Refer to Section 3.1

5.4 Booting the FABRIC-CA server through mirroring

Configure Docker-compose.yaml

version: '2'services:  root-ca-server:    container_name: root-ca-server    image: hyperledger/fabric-ca    command: /usr/local/bin/fabric-ca-server start -b admin:adminpw    volumes:    - ./fabric-ca-server:/etc/hyperledger/fabric-ca-server    ports:      - 7054:7054

Start

docker-compose up -d

Vi. Generating Certificates

Edit generatecert.sh, modify image, organization name, port


Generatecert

Execute./generatecert.sh Generate Crypto-config Directory

Seven, configuration Configtx.yaml

Edit Configtx.yaml
Configure the organization name for Orderer and peer, consistent with the organization name when the certificate is registered


Confitx-profile

Configure the Orderer organization's name, MSP's Id,msp directory


Configtx-orderers

Configure ORG1 name, MSP name, MSP directory, and anchor IP and port (for inter-organization communication)


Configtx-anchor-peers

Configure the Orderer mode (starting with solo mode), IP and port


Configtx-orderer

If you configure the Kafka mode and the Kafka cluster, you need to configure the Kafka cluster


Configtx-kafka

Viii. generation of Genesis blocks

Update-asorg parameters in generateartifacts.sh

Execute generateartifacts.sh Generate Genesis block, script generated information is saved in channel-artifacts

Nine, start the fabric cluster

9.1 Starting the fabric cluster in the local environment

9.1.1 Start Orderer

Start Orderer (see RUN_ORDERER.SH)

$ ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 \    ORDERER_GENERAL_GENESISMETHOD=file \    ORDERER_GENERAL_GENESISFILE=./orderer0/genesis.block \    ORDERER_GENERAL_LOCALMSPID=OrdererMSP \    ORDERER_GENERAL_LOCALMSPDIR=localMspConfig \    ../build/bin/orderer

9.1.2 Start Peer

Start peer (see RUN_PEER0.SH)

$ CORE_PEER_TLS_ENABLED=false \    CORE_NEXT=true CORE_PEER_ENDORSER_ENABLED=true \    CORE_PEER_GOSSIP_USELEADERELECTION=true \    CORE_PEER_GOSSIP_ORGLEADER=false \    CORE_PEER_GOSSIP_SKIPHANDSHAKE=true \    CORE_PEER_ID=peer0 \    CORE_PEER_ADDRESS=<peer_ip>:7051 \    CORE_PEER_GOSSIP_EXTERNALENDPOINT=<peer_ip>:7051\CORE_PEER_MSPCONFIGPATH=$GOPATH/src/github.com/hyperledger/fabric/peer/localMspConfig \CORE_PEER_LOCALMSPID=org1 \../build/bin/peer node start --peer-defaultchain=false

Start each orderer and peer as described above to start the fabric cluster

9.2 Starting a fabric cluster with a docker image

9.2.1 Start Orderer

Start Orderer (see START_ORDERER0.SH)

 $ docker run--NAME=ORDERER0 \--restart=unless-stopped \-P 7050:7050 \-w/opt/gopath/src/github.com/hype Rledger/fabric \-v/home/hyperledger/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto/orderer:/ Var/hyperledger/orderer \ e orderer_general_loglevel=debug \ e orderer_general_listenaddress=0.0.0.0 \-e ORDER Er_general_genesismethod=file \ e orderer_general_genesisfile=/var/hyperledger/orderer/orderer.block \ e ORDERER_G ENERAL_LOCALMSPID=ORDERERMSP \ e orderer_general_localmspdir=/var/hyperledger/orderer/localmspconfig \ e ORDERER_G Eneral_tls_enabled=false \-E orderer_general_tls_privatekey=/var/hyperledger/orderer/localmspconfig/keystore/ ORDERERSIGNER.PEM \-E orderer_general_tls_certificate=/var/hyperledger/orderer/localmspconfig/signcerts/ ORDERER0SIGNER.PEM \-E orderer_general_tls_rootcas=[/var/hyperledger/orderer/localmspconfig/cacerts/ ORDERERORG0.PEM] \ hyperledger/fabric-orderer:latest orderer 

9.2.2 Start Peer

Copy the Configtx.yaml to the fabric/common/configtx/tool/directory (note the files that were backed up)
Generates a channel file named Upchannel02 to create a channel

./build/bin/configtxgen -outputCreateChannelTx upchannel02.tx -channelID upchannel02 -profile TwoOrgs

Start peer (see START_PEER0.SH)

$ docker run--NAME=PEER0 \--restart=unless-stopped \-P 7051:7051 \-w/opt/gopath/src/github.com/hyperledger/f Abric/peer \-v/var/run/:/host/var/run/\-v/home/hyperledger/gopath/src/github.com/hyperledger/fabric/examples/e2 e_cli/examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/\-v/home/hyperledger/gopath/src/ github.com/hyperledger/fabric/examples/chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/ Chaincode/go \-v/home/hyperledger/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto/peer/peer0/ Localmspconfig:/etc/hyperledger/fabric/msp/sampleconfig \-v/home/hyperledger/gopath/src/github.com/hyperledger/ fabric/examples/e2e_cli/crypto:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/\-E CORE_PEER_ID=peer0 \-e core_peer_address=101.231.114.238:7051 \ e core_peer_gossop_endpoint=peer0 \ e Core_peer_gossip_externalen dpoint=101.231.114.238:7051 \ e core_peer_localmspid=org1 \-e CORE_vm_endpoint=unix:///host/var/run/docker.sock \-e core_logging_level=debug \ e core_peer_tls_enabled=false \ e CO Re_next=true \ e core_peer_endorser_enabled=true \ e core_peer_gossip_useleaderelection=true \-e CORE_PEER_GOS Sip_orgleader=false \ e core_peer_gossip_skiphandshake=true \ e core_peer_profile_enabled=true \-e GOPATH=/opt /gopath \-E core_peer_mspconfigpath=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/ Localmspconfig \ hyperledger/fabric-peer:latest Peer node start--peer-defaultchain=false

After peer starts, another window enters

$ docker exec –it peer0 bash

Go to Docker Bash, you can enter the relevant command

9.2.3 using Docker-compose to start the fabric cluster

Edit the Docker-compose.yaml file to start different services on different roles nodes
Start the fabric cluster

$ docker-compose up -d

X. Related orders

See scripts.sh

# 创建channel$ peer channel create -o 172.18.163.117:7050 -c mychannel -f channel-artifacts/channel.tx# 获取通道文件$ peer channel fetch oldest -o 172.18.163.117:7050 -c mychannel# 更新组织$ peer channel update -o 172.18.163.117:7050 -c mychannel -f channel-artifacts/Org1MSPanchors.tx# 加入channel$ peer channel join -b mychannel_oldest.block# 安装chaincode$ peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02# 实例化chaincode$ peer chaincode instantiate -o <orderer_ip>:7050 -C upchannel02 -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('org1.member','org2.member')"#调用chaincode$peer chaincode invoke -o <orderer_ip>:7050 -C upchannel02 -n mycc -c '{"Args":["invoke","a","b","10"]}'#查询chaincode$ peer chaincode query -C upchannel02 -n mycc -c '{"Args":["query","a"]}'

Xi. problems in the configuration process

11.1 Version and startup mode issues

The version and startup mode of each orderer and peer-initiated fabric needs to be consistent
Otherwise there will be some errors

Identity store rejected *:37166 : Identity doesn’t match the computed pkiID

11.2 Port Issues

When you start peer, you need to ensure that ports 7051 and 7053 are not occupied, or the peer will automatically exit when it starts

11.3 Firewall Issues

If the Execute channel or the Chaincode command is encountering a GRPC error, typically a port is not open or a firewall problem, add this port to the firewall allow list to

$ sudo firewall-cmd --zone=public --add-port=7050/tcp --permanent$ sudo firewall-cmd --reload

or use iptables related commands

11.4 Chaincode mismatch

In the installation Chaincode met fingerprint Dismatch error.
Workaround:
You can avoid this problem by remotely installing to another peer on a peer bash
Or
Chaincode Source is now packaged, packaged code package sent to the other peer, to install
Pack cc

$ peer chaincode package -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 ccpack.out

Installing CC

$ peer chaincode install ccpack.out

11.5 Chaincode not found in the channel

Problem description

Error: Error endorsing invoke: rpc error: code = 2 desc = failed to obtain cds for anchor01 - could not find chaincode with name 'anchor01'

This is because the deploy transaction is submitted and waits for some time to execute again
If another peer succeeds, this peer still has this problem, then restart peer (do not delete data at this time)

11.6 restarting peer

If you re-join a channel and you need to restart peer, delete the data directory, which is the directory configured in Filesystempath

11.7 Trading speed is slow

In the test process encountered the submission of the transaction, the status of a long time can not be updated, restarted peer to query the update, because peer for a period of time there is no transaction, a orderer will be disconnected from the peer, so peer can not receive Orderer broadcast request.
Workaround: Configure the Orderer address in Configtx.yaml for each organization Orderer intranet IP, or modify the external firewall configuration to keep the connection

Contact Us

If you have any questions, please contact:
Dazh_xu@163.com

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.