Blockchain building alliance chain and console installation

1. Alliance Chain

1. Install dependencies

## macos 环境安装依赖
brew install openssl curl
## ubuntu 环境安装依赖
sudo apt install -y openssl curl
## centos 环境安装依赖
sudo yum install -y openssl openssl-devel

2. Build alliance chain

# 使用 -l 和 -p 生成单机联盟链  本地使用-e ./fisco-bcos
bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545

After successful execution, we will see that a nodes directory is generated under the current directory. There are two directories under the nodes directory, namely 127.0.0.1 and cert. We enter the 127.0.0.1 directory, execute bash start_all.sh, and see the output "start successfully", indicating that the node starts successfully. So far, if everything goes well, our chain has been created and started successfully
insert image description here
Check whether the startup is successful
ps -ef |grep -v grep |grep fisco-bcos
insert image description here
check the connection of the log directory
tail -f node0/log/log* | grep connected
insert image description here
check Consensus connection
tail -f node0/log/log* | grep +++
insert image description here

Scale up a new node

1. Copy and paste the cert of the master node to the new folder fisco-new

//如果复制之后fisco_new文件夹里没有cert就重新启动一下服务器
cp -r fisco/nodes/cert fisco-new/

2. Download gen_code_cert.sh to generate new nodes

cd fisco-new
curl -#LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/gen_node_cert.sh
mkdir 192.168.0.164

3. Generate the certificate of the new node (-c is the ca path provided by the generated node, agency is the name of the institution, and -o is the name of the node directory to be generated)

//创建目录
mkdir 192.168.0.164
//可能会报没有权限,直接添加权限
chmod u+x *.sh
//生成新节点的证书
./gen_node_cert.sh -c ./cert/agency -o 192.168.0.164/node_new

4. Copy config.ini, start.sh, and stop.sh of one of the master nodes to the (new node) node_new folder

cd 192.168.0.164
cp /home/fisco/nodes/127.0.0.1/node0/config.ini /5.home/fisco/nodes/127.0.0.1/node0/start.sh /home/fisco/nodes/127.0.0.1/node0/stop.sh node_new/

5. Modify node4/config.ini. For the [rpc] module, modify channel_listen_port=20204 and jsonrpc_listen_port=8549; for the [p2p] module, modify listen_port=30304 and add its own node information in node.;

vim config.ini

insert image description here

6. Start error and modify vim start.sh to your own directory

insert image description here

Execute node4/start.sh to start the node;

7. Confirm that the connection between node4 and other nodes has been established, and the operation of joining the network is completed.

tail -f node_new/log/log*  | grep "connected count"

8. The node joins the group (get the nodeid of node4)

cat node4/conf/node.nodeid

Get a string similar to the following is nodeid, nodeid is the hexadecimal representation of the node public key, please execute cat node4/conf/gmnode.nodeid for the national secret
insert image description here

9. Use the console to join node4 to group 1

Use addObserver to add node4 to group 1 as an observer node

insert image description here

Use addSealer to join node4 as a consensus node to group 1

insert image description here

3. -e Use the existing fisco binary to generate a stand-alone alliance chain cp -r fisco/nodes/cert fisco-new/

As mentioned above, if you test, you need to delete and rebuild the chain frequently. Every time you go to github to pull it, there will be no problem if the network is good, and it will take a long time if the network is slow. So we can use the existing binary to build the chain. Create a new directory named bin under the fisco directory, then put the binary nodes/127.0.0.2/fisco-bcos into the bin directory, and then delete the nodes under the fisco directory (if not deleted, execute build_chain.sh It will prompt that the nodes directory already exists). Then the directory structure is as follows
insert image description here

Execute the following command to use the existing fisco-bcos binary to generate chain nodes. The execution is successful. We can notice that there is no Downloading word in the output information, indicating that build_chain.sh did not go to github to pull the fisco-bcos binary.
bash build_chain.sh -l 127.0.0.2:4 -p 30300,20200,8545 -e bin/fisco-bcos

insert image description here

4. Use -g to generate national secret nodes

First, delete the fisco/nodes directory, and then execute the following command.
bash build_chain.sh -l 127.0.0.2:4 -p 30300,20200,8545 -e bin/fisco-bcos -g
insert image description here
The chain is generated successfully, check the nodes/127.0.0.2/node0/config.ini file, you can observe the sm_crypto The parameter is true, indicating that the current node is a national secret node.
insert image description here

5. Use the -v parameter to specify the version

Because of compatibility considerations, fisco-bcos binary high version is compatible with low version configuration. Here, we use the binary of fisco-bcos v2.7.2, and configure the compatible version as v2.5.0
bash build_chain.sh -l 127.0.0.2:4 -p 30300,20200,8545 -v v2.5.0 -e bin/fisco-bcos
insert image description here
The execution is successful, enter the nodes/127.0.0.2/node0 directory, check the config.ini file, you can see that the supported_version field value is 2.5.0. In the fisco/nodes/127.0.0.2 directory, execute ./fisco-bcos -v , you can see that the output binary version is v2.7.2.
insert image description here
insert image description here

6. Use the -f parameter to specify the ip list file to generate multi-machine nodes

When it is necessary to generate nodes of multiple hosts, it is inevitable to use the command line method, but the method of specifying the ip list in a file will be much simpler. First delete the nodes folder under the fisco directory. Then create the file iptable, the content is as follows. Among them, the specific function of the value of "agency1 1,2" can be ignored by novice friends for the time being, and will be explained in my follow-up console usage article.

iptable file content

127.0.0.2:4 agency1 1,2 30300,20200,8545
127.0.0.3:4 agency1 1,2 30300,20200,8545

Then execute the following command to generate the node.

bash build_chain . sh - f iptable - e bin / fisco - bcos

insert image description here

Enter the nodes directory, you can see that two node folders are generated 127.0.0.2, 127.0.0.3

insert image description here

7. Use -d to generate docker nodes

First delete the nodes directory under the fisco directory, and then execute the following command (because macos does not support docker deployment, so centos is used for demonstration here)
bash build_chain.sh -l 127.0.0.2:4 -p 30300,20200,8545 -d
insert image description here
execution Success, the node is generated successfully. Comparing the nodes_backup/127.0.0.1/node0/start.sh and nodes/127.0.0.2/node0/start.sh files, it can be found that one of the script startup methods is docker, and the other is non-docker. For details, please refer to FISCO official website
insert image description here
insert image description here

2. Configure and use the console

1. Prepare to be dependent

  • install java

sudo apt install -y default-jdk

  • Download Console console

curl -LO https://github.com/FISCO-BCOS/console/releases/download/v2.8.0/download_console.sh && bash download_console.sh

  • Unzip Console
tar zxvf console.tar.gz 
  • Copy the console configuration file
cp -n console/conf/config-example.toml console/conf/config.toml
  • Configure console certificate
cp -r nodes/127.0.0.1/sdk/* console/conf/
  • Start and use the console
#进入到console目录
bash start.sh

Output the following information to indicate that the startup is successful, otherwise please check whether the node port configuration in conf/config.toml is correct

insert image description here

  1. Get information from the console

#Get client version information
getNodeVersion
insert image description here

Get node information

getPeers

insert image description here

Deploy smart contracts

Add the smart contract file in the fisco/console/contracts/solidity directory and start it with the deploy file name

insert image description here

Execute smart contracts

insert image description here

3. Installation and use of WeBASE-Front

1. Download the installation package

wget https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/WeBASE/releases/download/v1.5.4/webase-front.zip

2. Unzip

unzip webase-front.zip
cd webase-front

3. Copy the sdk certificate file (generated during build_chain)

cp -rf nodes/127.0.0.1/sdk/* webase-front/conf/

4. Service start and stop

启动: bash start.sh
停止: bash stop.sh
检查: bash status.sh 

Guess you like

Origin blog.csdn.net/weixin_47174945/article/details/125391880