From around June 2018, I started to get in touch with fabric, built a stand-alone or cluster environment, and wrote some documents. I found it when I was sorting out my computer recently, and I shared it here. . . .
System: linux ubuntu 16.04
Install Go
1.8 or higher
cd /www/download/
wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
Unzip, the folder after decompression is go
sudo tar -xzf go1.9.linux-amd64.tar.gz
sudo vi /etc/profile
export PATH=$PATH:/www/download/go/bin
export GOROOT=/www/download/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
source /etc/profile
go version
Install Docker
update source
sudo apt-get update
install docker
sudo apt-get install -y docker.io
Modify the permissions of the current user (the user I use is called content2)
sudo usermod -aG docker content2
Log out and log in again (or close the current black screen window and re-enter ), and then add Alibaba Cloud's Docker Hub image:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker -v
Install docker-compose
Docker-compose is a component that supports batch creation of Docker containers through template scripts.
sudo apt-get install -y docker-compose
docker-compose --version
Fabric source code download
阿里云服务器需要修改
修改 /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen 内容注释掉,作者修改后的内容如下
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.136
nameserver 100.100.2.138
# options timeout:2 attempts:3 rotate single-request-reopen
sudo mkdir -p ~/go/src/github.com/hyperledger
cd ~/go/src/github.com/hyperledger
sudo git clone -b release-1.0 https://github.com/hyperledger/fabric
Authorize the fabric folder
sudo chown content2.content2-R fabric
generate executable
cd ~/go/src/github.com/hyperledger/fabric
make configtxgen
Downloading the Fabric Docker image
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
Check the list of downloaded mirrors
docker images
Start the Fabric network and complete the ChainCode test
Execute the startup command in the ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli directory, it will start a channel of mychannel
./network_setup.sh up
After execution is complete, it will display
So far, the entire Fabric network has been connected.
Error prone to occur here,
Errors like this are because the channel has already been created and the naming conflicts. At this time, you need to clear the contents of the docker container and re-execute the above command.
1) Delete a container docker rm
2) Forcefully delete a container docker rm -f
3) Forcefully delete all containers docker rm -f $(docker ps -aq)
Test the Fabric network
Take Example02 installed now as an example. In the official example, the channel name is mychannel, and the chaincode name is mycc. We first enter the CLI, we reopen a command line window, enter:
docker exec -it cli bash
Query the balance of account a:
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Show balance is 90
Transfer the balance of account a to account b by 20 yuan:
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"]}'
Query the balance of account a, displaying 70
Close the Fabric network
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh down