搭建进度

搭建区块链网络

一、搭建单群组 FISCO BCOS 联盟链

1.安装依赖

2.创建操作目录, 下载安装脚本

3.搭建单群组4节点联盟链

4.启动FISCO BCOS链

5.检查进程

6.检查日志输出

二、配置及使用控制台

1.安装Java

2.安装maven(可以跳过)

3.下载共享库 native library(可以跳过)

4.获取控制台并回到fisco目录

5.拷贝控制台配置文件

6.配置控制台证书

启动!!!!

HelloWorld 一下吧


搭建区块链网络

一、搭建单群组 FISCO BCOS 联盟链

1.安装依赖

  • 首先需要安装 openssl curl
  • 开发部署工具build_chain.sh
  • 安装 unzip 工具
sudo yum install -y openssl openssl-devel使用以下命令来安装 unzip 工具:sudo yum install unzip

2.创建操作目录, 下载安装脚本

## 创建操作目录cd ~ && mkdir -p fisco && cd fisco## 下载脚本curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.9.1/build_chain.sh && chmod u+x build_chain.sh如果因为网络问题导致长时间无法下载build_chain.sh脚本请尝试 curl -#LO https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/releases/v2.9.1/build_chain.sh && chmod u+x build_chain.sh

3.搭建单群组4节点联盟链

bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545

命令执行成功会输出All completed。如果执行出错,请检查nodes/build.log文件中的错误信息

提示[WARN] /root/fisco/nodes DIR exists,please clean old DIR! 执行以下命令清除已有旧数据rm -rf /root/fisco/nodes

4.启动FISCO BCOS链

bash nodes/127.0.0.1/start_all.sh

启动成功会输出类似下面内容的响应。否则请使用netstat-an|greptcp检查机器的30300~30303,20200~20203,8545~8548端口是否被占用。

使用以下命令进行查找端口是否被占用netstat -anp | grep 30300
try to start node0try to start node1try to start node2try to start node3 node1 start successfully node2 start successfully node0 start successfully node3 start successfully

提示报错,如果docker启动失败的话请使用以下命令:

提示信息如:ERROR:Cannot connect to the Docker daemon at unix:///var/run/docker.sock.Is the docker daemon running?如何提示docker启动失败的话,执行以下命令:sudo systemctl start docker

5.检查进程

ps -ef | grep -v grep | grep fisco-bcos

正常情况会有类似下面的输出; 如果进程数不为4,则进程没有启动(一般是端口被占用导致的)

fisco 5453 11 17:11 pts/000:00:02 /home/ubuntu/fisco/nodes/127.0.0.1/node0/../fisco-bcos -c config.inifisco 5459 11 17:11 pts/000:00:02 /home/ubuntu/fisco/nodes/127.0.0.1/node1/../fisco-bcos -c config.inifisco 5464 11 17:11 pts/000:00:02 /home/ubuntu/fisco/nodes/127.0.0.1/node2/../fisco-bcos -c config.inifisco 5476 11 17:11 pts/000:00:02 /home/ubuntu/fisco/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini

6.检查日志输出

## 如下,查看节点node0链接的节点数tail -f nodes/127.0.0.1/node0/log/log*| grep connected## 正常情况会不停地输出连接信息,从输出可以看出node0与另外3个节点有连接。info|2019-01-21 17:30:58.316769| [P2P][Service] heartBeat,connected count=3info|2019-01-21 17:30:58.316769| [P2P][Service] heartBeat,connected count=3info|2019-01-21 17:31:18.317105| [P2P][Service] heartBeat,connected count=3## 执行下面指令,检查是否在共识tail -f nodes/127.0.0.1/node0/log/log*| grep +++## 正常情况会不停输出++++Generating seal,表示共识正常。info|2020-12-22 17:24:43.729402|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=2e133146...info|2020-12-22 17:24:47.740603|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=eb199760...

二、配置及使用控制台

1.安装Java

!!! 必须安装java14才可以本人安装时是2.9.2的控制台// 下载java14安装包jdk-14.0.2_linux-x64_bin.tar.gzhttps://www.oracle.com/cn/java/technologies/javase/jdk14-archive-downloads.html
// 下载保存到cd /usr/local/source/java// 解压命令tar -zxvf jdk-14.0.2_linux-x64_bin.tar.gz// 将解压后的包移动到路径下mv jdk-14.0.2 /usr/local/soft/
// 配置环境变量vi /etc/profile// 将以下命令复制到最后一行export JAVA_HOME=/usr/local/soft/jdk-14.0.2export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/libexport PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin// 刷新环境变量source /etc/profile

2.安装maven(可以跳过)

切换路径cd /usr/lib使用 yum 命令安装 Java 开发包:sudo yum install java-devel下载并解压 Maven 安装包wget https://mirror-hk.koddos.net/apache/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gztar -zxvf apache-maven-3.8.4-bin.tar.gz配置 Maven 环境变量sudo vi /etc/profile 将以下内容添加到 /etc/profile 文件末尾:export M2_HOME=[your-maven-directory]export PATH=$PATH:$M2_HOME/bin重新加载 /etc/profile 文件并应用更改:source /etc/profile检查 Maven 是否正确安装mvn -version之后,使用 Maven 在 CentOS 系统上下载 netty-tcnative例如,您可以使用以下命令从 Maven 中央仓库下载 netty-tcnative(版本为2.0.32.Final):mvn dependency:get -Dartifact=io.netty:netty-tcnative:2.0.32.Final

3.下载共享库 native library(可以跳过)

安装 netty-tcnativesudo yum install apr-devel openssl-develwget http://repo.maven.apache.org/maven2/io/netty/netty-tcnative/2.0.21.Final/netty-tcnative-2.0.21.Final-linux-x86_64.jar创建一个名为 netty-tcnative-2.0.21.Final-linux-x86_64.so 的链接文件,该文件指向 netty-tcnative-2.0.21.Final-linux-x86_64.jar 文件中的本机库ln -s /netty-tcnative-2.0.21.Final-linux-x86_64.jar \/usr/local/lib/libnetty-tcnative-2.0.21.Final-linux-x86_64.so在启动 FISCO BCOS 控制台之前,请确保将 /usr/local/lib 目录添加到系统路径中export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

4.获取控制台并回到fisco目录

cd ~/fisco && curl -LO https://github.com/FISCO-BCOS/console/releases/download/v2.9.2/download_console.sh && bash download_console.sh如果因为网络问题导致长时间无法下载,请尝试 cd ~/fisco && curl -#LO https://gitee.com/FISCO-BCOS/console/raw/master-2.0/tools/download_console.sh && bash download_console.sh

5.拷贝控制台配置文件

# 最新版本控制台使用如下命令拷贝配置文件cp -n console/conf/config-example.toml console/conf/config.toml

6.配置控制台证书

# 最新版本控制台使用如下命令拷贝配置文件cp -n console/conf/config-example.toml console/conf/config.tom

启动!!!!

cd ~/fisco/console && bash start.sh
centos 中启动fisco控制台时提示[root@gen-173-168-063-126 fisco]# cd console && bash start.shcreate BcosSDK failed, error info: init channel network error!org.fisco.bcos.sdk.network.NetworkException:* TRACE INFORMATION:----------------------------====> STEP1: try to connect nodes with ecdsa context...<==== STEP1-1: Load certificates for ecdsa context success...<==== connect nodes failed, reason:Failed to connect to all the nodes!* connect to 127.0.0.1:20200 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: 拒绝连接: /127.0.0.1:20200* connect to 127.0.0.1:20201 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: 拒绝连接: /127.0.0.1:20201如果提示这个,那么就是docker安装和原生安装发生了冲突,请从网络搭建重新进行操作
输出下述信息表明启动成功 否则请检查conf/config.toml中节点端口配置是否正确=============================================================================================Welcome to FISCO BCOS console(2.6.0)!Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console. ______________ __________________ _________________________|\|\ /\/\/\ | \/\/\/\| $$$$$$$$ \$$$$$$|$$$$$$\|$$$$$$\|$$$$$$\| $$$$$$$\|$$$$$$\|$$$$$$\|$$$$$$\| $$__| $$| $$___\$$| $$ \$$| $$| $$| $$__/ $$| $$ \$$| $$| $$| $$___\$$| $$\ | $$ \$$\ | $$| $$| $$| $$$$| $$| $$| $$ \$$\| $$$$$ | $$ _\$$$$$$\| $$ __ | $$| $$| $$$$$$$\| $$ __ | $$| $$ _\$$$$$$\| $$ _| $$_ |\__| $$| $$__/\| $$__/ $$| $$__/ $$| $$__/\| $$__/ $$|\__| $$| $$| $$ \ \$$$$ \$$$$ \$$$$| $$$$ \$$$$ \$$$$ \$$$$ \$$ \$$$$$$\$$$$$$ \$$$$$$ \$$$$$$\$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$=============================================================================================

HelloWorld 一下吧

#为了方便用户快速体验,HelloWorld合约已经内置于控制台中,位于控制台目录下contracts/solidity/HelloWorld.sol,参考下面命令部署即可。# 在控制台输入以下指令 部署成功则返回合约地址[group:1]> deploy HelloWorldtransaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23facontract address:0xb3c223fc0bf6646959f254ac4e4a7e355b50a344# 查看当前块高[group:1]> getBlockNumber1# 调用get接口获取name变量 此处的合约地址是deploy指令返回的地址[group:1]> call HelloWorld 0xb3c223fc0bf6646959f254ac4e4a7e355b50a344 get---------------------------------------------------------------------------------------------Return code: 0description: transaction executed successfullyReturn message: Success---------------------------------------------------------------------------------------------Return values:["Hello,World!"]---------------------------------------------------------------------------------------------# 查看当前块高,块高不变,因为get接口不更改账本状态[group:1]> getBlockNumber1# 调用set设置name[group:1]> call HelloWorld 0xb3c223fc0bf6646959f254ac4e4a7e355b50a344 set "Hello, FISCO BCOS"transaction hash: 0x7e742c44091e0d6e4e1df666d957d123116622ab90b718699ce50f54ed791f6e---------------------------------------------------------------------------------------------transaction status: 0x0description: transaction executed successfully---------------------------------------------------------------------------------------------OutputReceipt message: SuccessReturn message: Success---------------------------------------------------------------------------------------------Event logsEvent: {}# 再次查看当前块高,块高增加表示已出块,账本状态已更改[group:1]> getBlockNumber2# 调用get接口获取name变量,检查设置是否生效[group:1]> call HelloWorld 0xb3c223fc0bf6646959f254ac4e4a7e355b50a344 get---------------------------------------------------------------------------------------------Return code: 0description: transaction executed successfullyReturn message: Success---------------------------------------------------------------------------------------------Return values:["Hello,FISCO BCOS"]---------------------------------------------------------------------------------------------# 退出控制台[group:1]> quit