Fabric Hyperledger 1.4.1 National Secret Modification Version Centos Stand-alone Deployment and Test Process

Fabric Hyperledger 1.4.1 National Secret Modification Version Centos Stand-alone Deployment and Test Process

Description: This paper reference on CSDN author cola less ice in record time fabric state secret build process node version of this article. At the same time, I also thank Xiao Zhang on CSDN , never panicking for selfless answers and help in the deployment process; Finally, I would like to thank dddengyunjie on CSDN for releasing a national secret transformation version and help in normal work.

1. Preparation conditions

  • Install git, docker, docker-compose, go, etc. according to the requirements of the official Fabric Hyperledger documentation, which will not be described here.

    • Note: Go language version is better than 1.14.1 or above, otherwise there may be problems

    • Note: Do not install yum install for docker installation, so the installed version is too low (must be above 17.06). If it has been installed, there is an article below on how to delete and reinstall it. Of course, you can read this article to install it without installation.

      Docker installation on CSDN is too slow, use domestic mirroring service to install quickly

      It is recommended to use Alibaba Cloud data source.

      Or curl -fsSL https://get.docker.com/ | shinstall docker (not recommended in China, slow speed).

  • You need to use bzip2tools when packaging images , if not installed, runyum -y install bzip2

  • To set GOPATH, this article assumes that it is set to /root/gopath. Note that GO111MODULEthe environment variable to make it the default is autolike, do not change on.

2. Download the modified source code

1. Create a directory

mkdir -p $GOPATH/src/github.com/hyperledger

2. Download

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

Note: The domestic download is relatively slow, you can directly copy a downloaded package file from another place (if the package and copy the dependent library is better, we will not do it here).

It is recommended to use tarcommands for packing and unpacking .

Note: This transformation is actually a national secret transformation of Hyperledger Fabric v1.4.2.

Note: The directory structure is fixed, the project directory must be $GOPATH/src/github.com/hyperledger/fabric

Three, installation dependencies and build tool examples

Here is how to download some missing dependencies and build some tools.

1. Dependencies under golang.org/x

Here you need to download the following two libraries:

mkdir -p $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/crypto.git
git clone https://github.com/golang/sys.git

At the same time, this is also a download demo example.

2. Build the protoc-gen-go tool

cd $GOPATH/src
mkdir golang
cd golang
git clone https://github.com/golang/protobuf.git
cd protobuf/protoc-gen-go/
go build
go install
ls $GOPATH/bin

Here is also an example to demonstrate, used when the domestic server cannot be directly built. Of course there is an easier way, such as copying directly from elsewhere (recommended method).

3. Build mockery tool

mkdir -p $GOPATH/src/github.com/vektra
cd $GOPATH/src/github.com/vektra
git clone --branch v1.1.2 https://github.com/vektra/mockery.git
cd mockery/cmd/mockery
go install mockery.go
ls $GOPATH/bin

Here the mockery tool is built separately is useful.

Fourth, replace the invalid URL in the script in the source code

1、Makefile

Switch to the project directory

cd $GOPATH/src/github.com/hyperledger/fabric
vim Makefile

CHAINTOOL_URLThe value that needs to be replaced with:

https://hyperledger.jfrog.io/hyperledger/fabric-maven/org/hyperledger/fabric-chaintool/$(CHAINTOOL_RELEASE)/fabric-chaintool-$(CHAINTOOL_RELEASE).jar

Reason: The original URL is no longer maintained, so it needs to be replaced.
For details of this Makefile, see the article on the Go language charging station: Easy to master Fabric construction through Fabric 1.4 Makefile .

2、gotools.mk

vim gotools.mk

Change go.fqp.mockery := github.com/vektra/mockery/cmd/mockerythis line to go.fqp.mockery := github.com/vektra/mockery/cmd. Remove the last mockery, because its directory on github has changed. However, the change here can only make it uninterrupted during make, and cannot actually build the mockerytool. The specific details will be discussed later when make docker

Five, compile the binary file

chmod +x scripts/*.sh
make release

makeYou will be prompted that there are fewer golang tool libraries, which libraries can be downloaded by the method in 3.1, or copied from elsewhere. Pay attention to the prompt, it is searched from the vendor, GOPATH and GOROOT directories of this project. After downloading, you can also copy the missing dependent libraries to the vendorcorresponding location in the directory (the next step is to use make docker).

The missing packages in this make are (not listed here):

golang.org/x/crypto/chacha20poly1305
golang.org/x/sys/cpu
......

Here only need to install cryptoand syspackage according to the above method .
Then we re make:

cd $GOPATH/src/github.com/hyperledger/fabric
make release
tree release

If there is no installation treecommand, just layer by layer ls.

Generated files in release/linux-amd64/binthe directory.

Note: First copy the directory elsewhere, because if you execute make cleanit, this directory will be deleted. Although we generally don't execute it, what if it is sometimes needed.

cp -r release/linux-amd64/bin ~/
ls ~/bin

As you can see, we have successfully replicated.

Six, compile the image

make docker

In the first step, it will download some basic images and wait a long time... It is not recommended to use a proxy image repository, just let it download by itself.

In the second step, it first compiles the peer, and then prompts that there are fewer dependent libraries. If the dependent library is not copied to the project vendor directory during make release, you need to copy it here first. Note that the order of finding dependencies is the local vendor, and the latter two are virtual directories, not the GOPATH and GOROOT of the machine.
What other libraries are also downloaded by the method in 3.1 above, and then copied to the corresponding directory in the vendor. Of course, you can also use the scp command to copy from other machines. Note that if there are few libraries here, copy any libraries, and other libraries in the same directory do not need to be copied.

Since we have already downloaded the packages cryptoand syspackages under golang.org/x/ before, the libraries that are missing in this operation can be copied from the local $GOPATH directory:

mkdir -p vendor/golang.org/x/crypto/internal/
cp -r $GOPATH/src/golang.org/x/crypto/chacha20poly1305 vendor/golang.org/x/crypto/
cp -r $GOPATH/src/golang.org/x/crypto/curve25519 vendor/golang.org/x/crypto/
cp -r $GOPATH/src/golang.org/x/crypto/chacha20 vendor/golang.org/x/crypto/
cp -r $GOPATH/src/golang.org/x/crypto/internal/subtle vendor/golang.org/x/crypto/internal/
cp -r $GOPATH/src/golang.org/x/crypto/poly1305 vendor/golang.org/x/crypto/
cp -r $GOPATH/src/golang.org/x/sys/cpu vendor/golang.org/x/sys/

Then the make dockerbuild is peer-imagesuccessful.

In the third step, it will build order-image.

In the fourth step, it will build gotools tools. Sometimes because of network problems, when building the first tool counterfeiteror other tools, it will prompt to get the dependency library connection timeout. We will talk about how to solve this problem manually later. In order to save time, you can turn it off directly by ctrl + c.

If there is no failure, the build will succeed. Then it will skip to step 5.

If you fail to build a tool in the middle, please read on:

Run ls -a, you can see that there are more directories under the project .builddirectory. The directory does not exist initially, it will be created automatically when the script runs here, and the built tools are generated in the .build/docker/gotools/bin/directory.

Here comes the point:

Less cola with ice in record time fabric state secret version build process node this article mentions a way, is the lack of tools to use the previous example method (such as mockery, protoc-gen-go tools) were hand-constructed, then copy .build/docker/gotools/bin/Go to the catalog. But after trying this method many times, I found that there is a problem:
after copying it and making docker, it will skip the construction of some tools in gotools (it can also run in this way), and will directly skip to step 5. Therefore, the recommended approach is to copy all the tools that have been built from elsewhere (for example, build them on a Hong Kong server as a copy source) instead of copying only one of the tools. The following example operation copies all tools from other servers at once:

cd .build/docker/gotools/bin/
scp useranme@hostname:/opt/gopath/src/github.com/hyperledger/fabric/.build/docker/gotools/bin/* ./

Wait for the copy to complete after entering the password.

I plan to put all the built tools on giteeit for everyone to download, and then add the warehouse address when they are done.

The warehouse address is: https://gitee.com/TianCaoJiangLin/gotools-bin

The fifth step, continue to run make docker, it will appear to download the chaintool tool interface, the domestic download speed is very slow. At this time, you can turn it off by ctrl + c, and copy the tools built elsewhere to the corresponding .build/bin/directory. The specific operation is no longer described.

Note: This tool is also put in my warehouse.

The sixth step, and then run again make docker, it will compile build-envand image-toolwait, generally there will be no problems, until the final success.

At this point, the use docker imageswill list all the mirrors, and you will see some mirrors with no names or names, which should be some useless mirrors generated during the failure process. We can delete them with the following command:

docker rmi image_id -f

Here image_id refers to the image ID, remember not to use it lightly make clean.

There is an imperfection here:
after the build is completed, we run

tree .build/docker/gotools/bin/

I will find that only 10 tools are listed instead gotools.mkof 11 tools in the list mockery. What should I do if one is missing? The general reason I mentioned in the replacement of invalid URL, but I am not clear about the specific details (limited ability).

One less one here mockerydoes not affect the actual operation, but if you are a perfectionist, you must be unable to get through here, what should you do?
The .build/docker/gotools/binAll tool to copy out the front of the building and then the mockerytool added. Then rebuild, manually copy the build tool:

mkdir -p ~/docker/gotools
cp -r .build/docker/gotools/bin ~/docker/gotools
cp $GOPATH/bin/mockery ~/docker/gotools/bin/
tree ~/docker/gotools/bin
make clean
make docker

In the building gotoolswhen ctrl + cto turn it off, then:

cp ~/docker/gotools/bin/* .build/docker/gotools/bin/
make docker

Note: Rebuilding here also needs to check some images that have no name or name, but delete them.

Seven, download fabric-sample and test

1. Download the fabric-sample of version 1.4.2

Because we may use CA in the future (although this article does not involve the national secret version of CA), we use fabric-sample v1.4.2 for testing. The startup script in the fabric-sample v1.4.1 sample network does not include CA. It is troublesome to write it yourself.

cd ~
git clone --branch v1.4.2 https://github.com/hyperledger/fabric-samples.git

2. Copy the binary file compiled above to the fabric-sample directory

To make releasethis step has been copied to the copy generated bin directory to the root directory fabirc-sample, the following command can be used

cp -r bin fabric-samples

3. Modifyconfigtx.yaml

Because the order node of the country's secret version is not supported OrdererCapabilities V1_4_2, we modify it to the fabric-sample v1.4.1same settings as:

vim first-network/configtx.yaml
  • The first Capabilitiespart of Channelthe V1_4_2: truechange V1_3: true.
  • The first Capabilitiespart of Ordererthe V1_4_2: truechange V1_1: true.
  • The first Capabilitiespart Applicationis V1_4_2: truecommented out.
  • The first Capabilitiespart of Applicationthe V1_3: falsechange V1_3: true.

4. Run the test

cd fabirc-sample/first-network
./byfn.sh up

If an error is reported during the process that the peer node has been crashing and unable to run (some machines or centos version may have this situation), it may be because there are some problems in the current version, which need to be set under some centos versions (or server settings) The environment variable of a peer. For specific details, please refer to an article by Alibaba Cloud : Analysis of SIGSEGV problems in the deployment of Hyperledger Fabric in Alibaba Cloud environment and sharing of experience in solving them

To change here base/peer-base.yaml, add: in the environment variable settings of the node - GODEBUG=netdns=go.

then:

./byfn.sh down
./byfn.sh up

8. Mirror export and import

If it is necessary to deploy the modified national secret version on multiple machines, it is impossible for each machine to follow this step, which is too time-consuming. My personal assumption is to export the compiled image as a local file, copy it to another machine and then import the image, and copy make releasethe binfolder generated above .

Reference article: docker copy image file

This idea has been realized by others, it is feasible, and the speed is much faster than make.

Finally: because the deployment test is an operation with many steps, it is relatively simple to write, and some steps are also unclear, especially the step of building tools. If there are any errors in the article or any problems encountered in the operation, please leave a message and discuss together.

Guess you like

Origin blog.csdn.net/weixin_39430411/article/details/107939859