Preface
Deployment environment: CentOS7.9
install the following tools in advance
- git client
- golang
- docker
- docker-compose
- curl tool
The following is the version for personal use
- git: 2.39.2
- golang: 1.18.6
- docker: 23.0.3
- dockkekr-compose: v2.17.2
- curl: 7.29.0
Official document reference link: jump link , different versions correspond to different official documents, please pay attention to the corresponding version of the document when referring , the docker version cannot be too low, the official requirement is 17.06.2-ce or later
Environment build
- Download fabric source code
git clone https://github.com/hyperledger/fabric.git
- Go to the root directory of the source code and view the current branch.
cd fabric/
git branch
- The source code you just downloaded is in the main branch by default.
- Switch to the branch corresponding to version 2.2
git checkout -b release-2.2 origin/release-2.2
git branch
- Enter the scripts folder of the fabric source code
cd scripts/
ls -l
You can see that there is a bootstrap.sh file
- Execute script to install
sh bootstrap.sh
- If you do not have executable permissions, use the following command to modify the permissions
chmod +x bootstrap.sh
The execution script mainly does the following things:
- Download the source code of fabric-samples and switch to the corresponding version
- Download hyperledger-fabric-linux-amd64-2.2.10.tar.gz. After decompression, the bin and config directories will be generated.
- Download hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz and unzip it to generate the bin directory.
- Download the docker image related to hyperledger fabric and modify the image tag to latest
- After the script is executed, the following content is mainly generated:
- fabric-samples source code
- Switching to fabric-samples will have two directories: bin and config
- docker image
- Modify the executable permissions of the bin and config directories, enter the fabric-samples source code root directory, and execute the following command
chmod -R +x bin/
chmod -R +x config/
- Enter the test-network directory of fabric-samples
cd test-network/
- Start with the following command
sh network.sh up
- Using the docker command, you can see that the following containers are started:
- Create channels
./network.sh createChannel -c mychannel
The following content appears, indicating that the channel is successfully created. After the channel is successfully created, it is added to the node.
- Deploy contract
./network.sh deployCC -ccn contract-name -ccv 1 -ccs 1 -ccp fabric-samples/asset-transfer-basic/chaincode-go -ccl go
The meanings of the parameters of the above command:
deployCC: This script comes with the source code, under fabric-samples/test-network/scripts/
-ccn: contract name
-ccv: contract version
-ccl: contract language, java, go, etc.
-ccs: the sequence of the contract, which must be an integer
-ccp: the path where the contract is located
Other parameters can be found in the fabric-samples/test-network/scripts/utils.sh script, which has a detailed description of each parameter .
For the deployed contract, you can define it yourself or use the official example. After the
above command of fabric-samples/asset-transfer-basic is successfully executed, the official example will finally output the following results:
- If you want to shut down the network, execute the following command
./network.sh down
The above command will close and remove all started docker images.
problem solved
- During the contract deployment process: dial tcp 142.251.42.241:443: connect: connection refused
Solution: Change the proxy address and execute the following commandgo env -w GOPROXY=https://goproxy.cn
Finish
The above is the construction of the Hyperledger Fabric 2.2 version environment. If you have any questions, please feel free to communicate.