Hyperledger Fabric combat stand-alone deployment

Preface

Regarding Hyperledger/fabric1.0 environment deployment, I personally stepped on a lot of pits, from official sample examples, to solo multi-machine local deployment, to the actual production environment of kafka multi-machine deployment, and various bugs emerged on the way, even if you follow Like online tutorials, there are still a lot of bugs. In view of the fact that many friends have no foundation, I personally also want to write an experiment record, so I also post a simple introductory blog.
This tutorial is purely straightforward teaching, but also some suggestions, I hope it will be helpful to everyone. (The Markdown editor is used for the first time, and the typesetting is not good.)

0. Basic instructions

Tutorial is based linux distributions centos7.x, CentOS Linux release 7.6.1810 (Core )
execute the command cat /etc/centos-release
kernel version 3.10.0-957.21.3.el7.x86_64 (3.10.0 corresponding primary version)

Execution Command uname -rCorresponding to the execution input in linux
According to the textbook "HyperLedger Fabric Development Actual Combat: Quickly Master Blockchain Technology" compiled by Yang Yi, the kernel version 3.10 or above is recommended.
PS: All personal computers are windows, and the next virtual machine can run Linux. Recommend the book "Uncle Bird's Private Kitchen" 》, linux national excellent course on Mukenet, linux fast application course

1.Go language installation

1. Undoubtedly download the go language installation package

Most of them are running virtual machines under windows, or connecting to the server remotely (Xshell is recommended, which is more convenient to transfer files between the host and the virtual machine), so download the go installation package directly from windows

Download address The go language download address
go download interface is used in a virtual machine, so choose the linux installation package to download to the windows interface.
Upload to Linux, the xshell I used here, directly input the "rz" command in the virtual machine to upload the file to the
virtual machine.

Enter rz interface
Enter the command line lsto see that the file already exists.
Enter the command line to tar -C /usr/local -zxf go1.12.7.linux-amd64.tar.gz
decompress the file, the go file will appear under /usr/local

2. Edit environment variables

The command line is vim /etc/profile
inserted at the end

#go
export PATH=$PATH:/usr/local/go/bin 
export GOROOT=/usr/local/go 
export GOPATH=$HOME/go 
export PATH=$PATH:$HOME/go/bin

Ps vim is a text editor for Linux. After entering the text editing interface,
1. Press esc, and press the up and down keys to the last line
2. Copy the above command
3. Press "i" to enter the editor mode, paste
4. Press esc, enter and :wqsave Exit the vim editing interface.
5. Enter the command line on the linux terminal to source /etc/profilemake the environment variable take effect
. 6. Inquire whether go is installed and a go versionpop-upgo version go1.12.7 linux/amd64

2.Docker installation

Just copy and paste input without brain, you can input in any directory

1. Command line yum install -y yum-utils device-mapper-persistent-data lvm2
2. Command line yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3. Command line yum install docker-ce
4. Command line docker versionoutput, the client and server installation is successful.
5. Add boot up `

systemctl start docker
systemctl enable docker

6. Add the user to the docker group, and run docker under a non-root user without the sudo command
sudo usrmod -aG docker user(user is your Linux username, mine is user, here is user, user@localhost ~)
7. Restart the docker service sudo service docker restart
8. Restart the group newgrp - docker(section 6 can not be troublesome)

3. Configure docker-compose (emphasis, good stuff)

1. Enter the command line sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose(not install curl, enter the command line to yum install -y curlinstall)
2. Enter the command line to cd /usr/local/bin/switch to the interface of the installation package
There will be a docker-compose file, which can be entered and lsviewed.
3. command line sudo chmod +x docker-composeto increase the file permissions
4. The command line docker-compose versionto see if there is a corresponding output version.

docker-compose version 1.24.1, build 4667896b

(Pip installation is not recommended, it is easy to report errors, docker-compose is a way to use .yaml template files to create multiple containers, which is very convenient, but you can't experience it by running an official script.)

4. Download the Fabric source code

1. mkdir -p ~/go/src/github.com/hyperledger && cd ~/go/src/github.com/hyperledger && git clone https://github.com/hyperledger/fabric.gitCopy and paste the command line and wait for the fabric directory to appear in the hyperledger (tips, if you can’t download it, you can try to change the link "https" to "git", the others remain unchanged)
2. cd fabricSwitch to the fabric directory
3. Switch version git checkout v1.0.0, Fabric1.0 is more suitable for getting started, and there are many official samples
. 4. The point is here, switch to the official script.
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
5. source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
If the permissions are not enough, enter sudo -E bash download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0this command to download the required image.
6. cd base && vim peer-base.yaml
Modify the following network name to be consistent with the directory. Otherwise, an error will be reported.

- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default

Switch tocd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/

7. ./network_setup.sh upRun the script that comes with fabric1.0 from the command line . If you run successfully, the word "good" is displayed.
ps: After entering the cli client through docker, check accounts, transfer accounts, can be operated or not.
When you deploy your own solo stand-alone, you don't need to use official scripts to create organization files, channels, install chain codes, instantiate and so on.
8. If an error is reported for missing files, cd ~/go/src/github.com/hyperledger/fabric/release/linux-amd64/check whether there is a bin binary file. If there is no content, download the bin file corresponding to fabric1.0 version. There are tools cryptogen and configtxgen to generate organization files and channel files. Generally, this issue does not occur, and the script is automatically generated. If you are interested in continuing the road of fabric, you can search Baidu for articles by the authors of aberic, deep blue and pathfinder. (aberic is the blog name of the author of Yang Yi. Pathfinder's blog has made some supplements to aberic, such as opening the port in advance.) Because it is just a preliminary understanding to run it through the official template.

Probably involved knowledge

1. docker container technology, master some simple commands of docker , docker learn
2. Familiar with the docker-compose command, understand the .yaml file, understand all the official example .yaml files, basically have a clear understanding. 3. Linux
operation commands 4. Go
language programming
5. Some knowledge of
git 6. Go web programming
7. Fabric-go-sdk
8. Knowledge and use of Couchdb database
9. Multi-machine deployment will use clusters and remote connections Server, understand some concepts of clusters.
10. Introduction to blockchain, fabric combat, fabric principle
This is why it is recommended to use xshell, not putty or cmd terminal ssh connection, because there are too many windows, xshell is better in this regard.
ps: It took a few hours to write things that were deployed in 10 minutes. I originally wanted to write 1.1 multi-machine deployment and kafka deployment. It is highly recommended to read Aberic's "HyperLedger Fabric Development Actual Combat: Quickly Master Blockchain Technology", and pay more attention to practical operations. Combined with Pathfinder's blog, there is basically no problem with environment deployment. 2019.9.10

Guess you like

Origin blog.csdn.net/hungrylion/article/details/100715707