The environment of Hyperledger Fabric v1.2 of the blockchain

In 2015, the Linux Foundation launched the Hyperledger project with the goal of developing cross-industry blockchain technology.
The Hyperledger project does not just define a single blockchain standard, it encourages the collaborative development of blockchain technology through the power of the open source community. Hyperledger Fabric is a blockchain project in Hyperledger. Similar to other blockchain technologies, Hyperledger Fabric contains a ledger, uses smart contracts and is a system that manages transactions through all participants.
The biggest difference between Hyperledger Fabric and other blockchain systems is private and permissioned. Unlike the open permissionless network system that allows unknown participants to join the network (the proof-of-work protocol is required to ensure the validity of transactions and maintain the security of the network), Hyperledger Fabric registers all members through the Membership Service Provider (MSP). Hyperledger Fabric also provides multiple pluggable options. Ledger data can be stored in a variety of formats, the consensus mechanism can be accessed or disconnected, and a variety of different MSPs can be supported at the same time.

Hyperledger Fabric provides the function of establishing channels, which allows participants to create a separate ledger for transactions. This function becomes especially important when some of the participants in the network are competitors. Because these participants do not want all transaction information-such as specific price information provided to some customers-to be open to all participants in the network. Only participants in the same channel will own the ledger in the channel, while other participants not in this channel can't see the ledger.

Hyperledger Fabric is a platform that provides distributed ledger solutions.
Hyperledger Fabric is supported by a modular architecture and has excellent confidentiality, scalability, flexibility and scalability.
Hyperledger Fabric is designed to support the direct plug-in of different modules and components, and can adapt to the intricate and complex economic ecosystems. Various scenes.
Hyperledger Fabric provides a unique scalable and extensible architecture, which is also a significant difference between Hyperledger Fabric and other blockchain solutions. If you are planning to deploy an enterprise-level blockchain with a complete review mechanism and an open source architecture, Hyperledger Fabric is a good starting point for you.

Refer to the official Chinese documentation of Hyperledger Fabric: https://hyperledgercn.github.io/hyperledgerDocs/

1. Preparing Linux system recommends Ubuntu 16.04 or 18.04

1.1. View apt source
vim /etc/apt/sources.list
//北邮镜像源
deb http://mirrors.byrio.org/ubuntu/ bionic main restricted
deb http://mirrors.byrio.org/ubuntu/ bionic-updates main restricted
deb http://mirrors.byrio.org/ubuntu/ bionic universe
deb http://mirrors.byrio.org/ubuntu/ bionic-updates universe
deb http://mirrors.byrio.org/ubuntu/ bionic multiverse
deb http://mirrors.byrio.org/ubuntu/ bionic-updates multiverse
deb http://mirrors.byrio.org/ubuntu/ bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse

//阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
1.2 Update source
apt-get update && apt-get upgrade

2. Install Golang Chinese

Go language official website: https://studygolang.com/dl

cd $HOME/ && wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz

//解压到/usr/local
tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gz

//修改环境变量
vim /etc/profile

//设置go的路径
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

//环境变量生效
source /etc/profile

//查看go版本
go version

3. Install git, cURL, libltdl-dev

apt-get -y install git
//查看git 版本 
git -version

apt-get -y install curl
//查看curl 版本
curl -version

apt-get -y install libltdl-dev

4. Install Docker

//安装软件包以允许apt通过HTTPS使用远程库
apt-get -y install apt-transport-https ca-certificates curl software-properties-common

//添加Docker的官方GPG密钥
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"

//再次更新apt包索引
apt-get -y update

//使用apt安装docker-ce
apt-get -y install docker-ce


//验证是否安装成功并查看版本
docker version 

Note: If you execute the second command, an error is reported
Insert picture description here

5. Install python-pip, docker-compose

apt-­get -y install python­-pip

//查看pip版本
pip -V


apt-get -y install docker­-compose

//查看docker-compose版本
docker­-compose ­-­version

6. Download fabric source code and Fabric-samples

6.1 Create a new mkdir folder manually
//获取fabirc并切换版本
git clone https://gitee.com/arxin/fabric.git

//进入fabric
cd /fabric

//查看当前已有的版本信息
git branch -a

//切换到1.2.0版本
git checkout -b v1.2.0

//获取fabric-samples并切换版本
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 1.2.0

Note: If the execution is unsuccessful, choose to use the accelerated link or use the code cloud

//加速地址
git clone https://github.com.cnpmjs.org/wlc1216/Hyperledger-fabric.git
//码云
git clone https://gitee.com/arxin/fabric.git
6.2 View the pull image
docker images
6.3 Network test
//进入first-network文件夹
cd ../fabric/fabric-samples/first-network

Insert picture description here

  • .env: store some environment variables
  • base: some public services for storing docker-compose
  • byfn.sh: execute script
  • configtx.yaml and crypto-config.yaml: According to the two tools generated before, generate the corresponding configuration files to start the network and put them in the channel-artifacts and crypto-config in the current directory
  • dockper-compose: used to start the network
  • scripts: store test scripts, do: create channel, join channel, install chain code, instantiate chain code, chain code interaction
//生成所需的证书和镜像
./byfn.sh -m generate  

//启动网络
./byfn.sh -m up  

Insert picture description here

//关闭网络
./byfn.sh -m down  

it is good! ! Congratulations on your successful appearance on this page
Insert picture description here

Note: docker-compose reports an error during the network startup processInsert picture description here
because the time taken by compse to read is too short

vi /etc/resolv.conf

Solution: comment out options timeout:2 attempts:3 rotate single-request-reopen with a hash sign in front of the line, then save and exit

7. Test the favirc network

In the official example, the name of the channel is mychannel and the name of the chain code is mycc

Use the docker exec command to enter the CLI container:

docker exec -it cli bash

In the /opt/gopath/src/github.com/hyperledger/fabric/peer directory, run the following command to query the balance of account a:

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

Insert picture description here
Below we can carry out the transfer operation, the operation is invoke, from a to b 20:

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","a","b","20"]}'

Insert picture description here

The transfer was successful! ! !

Note: Regarding the transfer is successful, but there is no synchronization problem

The reason should be the endorsement strategy. Both orgs must endorse and cannot be omitted.

AND('Org1.member','Org2.member','Org3.member') means that three subjects are required to sign and endorse

OR('Org1.member','Org2.member') means that the signature endorsement of one of the two subjects is required

OR('Org1.member',AND('Org2.member','Org3.member')) means that the signature endorsement of Org1 or the common signature endorsement of Org2 and Org3 is required

8. About node.js development

1. Install node.js and npm
curl ­sL https://deb.nodesource.com/setup_8.x | sudo ­-E bash ­-

//查看node版本
node -­­v

//查看npm版本
npm ­-v
1.1 Move to the fabcar directory
cd ../
cd fabcar
1.2 Install node module
npm install

Note: There may be node.js version problems, you can try to upgrade

npm upgrade or update to the specified version, run the command

npm install -g npm   或者  npm -g install [email protected]
1.3 Install grpc module to communicate with Hyperledger Fabric:
sudo npm install grpc
1.4 Start fabcar's Hyperledger Fabric network
./startFabric.sh

Reference part of the article
Thanks to @Hyperledger Internationalization Working Group
https://hyperledgercn.github.io/hyperledgerDocs/build_network_zh/
Thanks @马McccccL
https://blog.csdn.net/so5418418/article/details/78355868
Thanks @笔阁
https ://my.oschina.net/u/2275217/blog/3014598
https://www.tqwba.com/x_d/jishu/357137.html

Guess you like

Origin blog.csdn.net/wlc_1111/article/details/115319856