Hyperledger Fabric 1.0 from scratch (4) - Fabric source code and image file processing

2 : Fabric source code and image file processing

2.1 Download Fabric source code

The reason for downloading the Fabric source code is to use the columns and tools mentioned in the source code. The go language environment is required for tool compilation, so the source code directory needs to be placed under $GOPATH. Through the go installation configuration in 1.3, $GOPATH is set to /opt/gopath.

We can use the Git command to download the source code, or we can use the go get command. To be lazy, we can directly use the go get command to get the latest Fabric source code: 

go get github.com/hyperledger/fabric

[Note: Friends who use an offline environment or an intranet environment can directly select the corresponding version to download on github, and then upload it to the specified directory through ftp]

This may take a long time to wait. After the completion, we can find all the latest source code in ~/go/src/github.com/hyperledger/fabric. Since Fabric has been updated all the time, we do not need the latest and latest source code, we need to switch to the source code of v1.0.0 version:

1 cd /opt/gopath/src/github.com/hyperledger/fabric/
2 git checkout -b v1.0.0 

In this step, you can also directly download the source code to the local on github, and then upload it to the hyperledger directory through ftp.

If there is no git command, you also need to execute the following command to build a local git environment.

yum  install git

 

 The final directory in the FTP view normally looks like this:

 

 

2.2 Download Fabric related image files

There are several ways to perform this operation. If you are testing the Fabric cluster solution, you can directly enter the fabric/examples/e2e_cli directory and run ./download-dockerimages.sh to download the necessary image files for the project. In general, in order to ensure that the image corresponds to the version number of the source code demo downloaded to hyperledger, this method is a more appropriate solution.

However, in order to facilitate future upgrades and the version can be controlled by oneself, another solution will be introduced this time, which is also recommended by the author.

This time, Fabric related images can be downloaded from the official DockerHub mirror website , retrieve HyperLedger , take hyperledger/fabric-peer as an example, and enter its download page. The official download method is as follows:

docker pull hyperledger/fabric-peer

 

However, because the docker image download will use lastest by default if the specified tag is not given, and this solution may eventually fail to download, therefore, select its tags tag on the fabric-peer download page to view the latest fabric-peer version number, According to the operating system we are using, we choose the x86_64-1.0.0 version, so the final docker download command executed is as follows:

docker pull hyperledger/fabric-peer:x86_64-1.0.0

 

 The main mirrors required in the fabric environment are as follows:

hyperledger/fabric-tools
hyperledger/fabric-orderer
hyperledger/fabric-peer
hyperledger/fabric-couchdb
hyperledger/fabric-kafka
hyperledger/fabric-ca
hyperledger/fabric-ccenv
hyperledger/fabric-baseimage

 

 According to the above solution, you can download all these necessary images from the docker service to the local, and finally use docker-compose to start the corresponding image service.

[Note: For friends in an offline environment or an intranet environment, please operate this step through other servers that can connect to the public network. Later, these images can be packaged and restored on the server in the intranet environment. For details, see the follow-up description]

In order to facilitate the configuration of docker-compose, we change all image tags to latest, and execute the command in the following format:

docker tag IMAGEID (image id) REPOSITORY:TAG (repository: tag)

 

 example

docker tag 0403fd1c72c7 docker.io/hyperledger/fabric-tools:latest

 

 After all image files and version numbers are modified, execute the following command:

docker images

 

 The resulting view should look like this:

 

 If there is a problem with the downloaded image, you can execute the following command to delete the image with the specified Image ID

docker rmi <image id>
or
docker rmi -f<image id>

 

 The command to delete all mirrors is as follows:

docker rmi $(docker images -q)
or
docker rmi -f $(docker images -q)

 

 

2.3 Mirror backup and copy (this step is not necessary, if there is no such requirement, you can skip this step)

The number of HyperLedger/Fabric images mentioned above is large and the capacity requirement is large. A set of basic service images can reach about 10G. If it is deployed on multiple servers, it will take a lot of time. Therefore, for the above images that have been downloaded to the local, we need to use the docker save command to backup, and use the scp command to copy these image files to other servers.

Take the image hyperledger/fabric-peer as an example:

Before executing sava, you need to query the Image ID of the current image package. The execution command is as follows:

docker images

 

Get the following results, you can see that the Image ID of the fabric-peer we have downloaded is 6830dcd7b9b5

We can execute the following command to generate the tar package of the image in the /tmp directory:

docker save 6830dcd7b9b5> /tmp/docker/fabric-images/peer.tar

The above command structure is docker save IMAGEID (image id) > (file path and file name)

According to the above commands, we perform packaging operations on other downloaded fabric images, and finally execute ls in the /tmp/docker/fabric-images directory to view the image files in the current directory. Under normal circumstances, you will see the following view:

This view is only partially intercepted, and this view is only used as a reference for the ls command result.

Through FTP, you can see that the directory is roughly as follows:

When all image files are packaged, the image can be sent in the following command format:

scp fabric-peer.tar root@10.111.171.217:/tmp/docker/fabric-images

The above command can be used to remotely copy the image file to the 10.111.171.217 remote server /tmp/docker/fabric-images directory. Here is the intranet ip. If it is in the intranet environment, the copy speed will be very fast. It depends on the server's own network conditions.

[Note: The offline environment or the intranet environment should still be copied manually. In addition, if the transmission speed of the intranet is not satisfactory, you should also use manual copying.]

When the remote server receives all the image files, execute the following command to load these image files:

docker load < /tmp/docker/fabric-peer.tar

After the image is loaded, you can change the image tags to lastest according to the previous 3 solutions.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324876320&siteId=291194637