webase搭建

06-13 1112阅读

(一)FISCO BCOS联盟链 安装

依赖安装

openssl, curl 安装

安装ubuntu依赖

webase搭建
(图片来源网络,侵删)
sudo apt install -y openssl curl

Java环境安装

# ubuntu系统安装java 1.8以上都可以
sudo apt-get -y install openjdk-11-jdk

配置系统变量

  JDK 8和JDK11及以上的版本配置相差不多,JDK 8多了一个JRE的变量,具体配置如下:

# JDK 8

export JAVA_HOME=/usr/local/java/jdk1.8.0_301

export JRE_HOME=$JAVA_HOME/jre

export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib

export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

# JDK 11

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

export CLASSPATH=$JAVA_HOME/lib

export PATH=$PATH:$JAVA_HOME/bin

  为配置方便,可以修改系统的配置文件:

系统级:对当前系统下所有用户生效,可以编辑/etc/profile或/etc/bash.bashrc两个文件中的其中一个,内容与上述的一致,这里不再赘述:

sudo vim /etc/profile

# 在文章末尾添加变量

...

# 配置生效

source /etc/profile

安装fisco链

第一步. 创建操作目录, 下载安装脚本

## 创建操作目录
cd ~ && mkdir -p fisco && cd fisco
​
## 下载脚本
curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.8.0/build_chain.sh && chmod u+x build_chain.sh

第二步. 搭建单群组4节点联盟链

在fisco目录下执行下面的指令,生成一条单群组4节点的FISCO链。 请确保机器的30300~30303,20200~20203,8545~8548端口没有被占用。

注解

  • 国密版本请执行 bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545 -g -G

  • 其中-g表示生成国密配置,-G表示使用国密SSL连接

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

    第三步. 启动FISCO BCOS链

    • 启动所有节点

      bash nodes/127.0.0.1/start_all.sh

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

      try to start node0
      try to start node1
      try to start node2
      try to start node3
       node1 start successfully
       node2 start successfully
       node0 start successfully
       node3 start successfully

      第四步. 检查进程

      • 检查进程是否启动

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

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

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

        配置及使用控制台

        一、获取控制台并回到fisco目录

        cd ~/fisco && curl -LO https://github.com/FISCO-BCOS/console/releases/download/v2.8.0/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

          二、拷贝控制台配置文件

          若节点未采用默认端口,请将文件中的20200替换成节点对应的channel端口。

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

          三、配置控制台证书

          把上面生成的node节点的sdk证书拷贝到控制台

          注解

          • 使用1.x版本控制台时:

            搭建国密版时,如果使用国密SSL请执行 cp nodes/127.0.0.1/sdk/gm/* console/conf/搭建国密版时,请修改 applicationContext.xml 中 encryptType 修改为1

            cp -r nodes/127.0.0.1/sdk/* console/conf/

            四、启动并使用控制台

            • 启动

              cd ~/fisco/console && bash start.sh

              输出下述信息表明启动成功 否则请检查conf/config.toml中节点端口配置是否正确

              =============================================================================================
              Welcome to FISCO BCOS console(2.6.0)!
              Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
               ________  ______   ______    ______    ______         _______    ______    ______    ______
              |        \|      \ /      \  /      \  /      \       |       \  /      \  /      \  /      \
              | $$$$$$$$ \$$$$$$|  $$$$$$\|  $$$$$$\|  $$$$$$\      | $$$$$$$\|  $$$$$$\|  $$$$$$\|  $$$$$$\
              | $$__      | $$  | $$___\$$| $$   \$$| $$  | $$      | $$__/ $$| $$   \$$| $$  | $$| $$___\$$
              | $$  \     | $$   \$$    \ | $$      | $$  | $$      | $$    $$| $$      | $$  | $$ \$$    \
              | $$$$$     | $$   _\$$$$$$\| $$   __ | $$  | $$      | $$$$$$$\| $$   __ | $$  | $$ _\$$$$$$\
              | $$       _| $$_ |  \__| $$| $$__/  \| $$__/ $$      | $$__/ $$| $$__/  \| $$__/ $$|  \__| $$
              | $$      |   $$ \ \$$    $$ \$$    $$ \$$    $$      | $$    $$ \$$    $$ \$$    $$ \$$    $$
               \$$       \$$$$$$  \$$$$$$   \$$$$$$   \$$$$$$        \$$$$$$$   \$$$$$$   \$$$$$$   \$$$$$$
              ​
              =============================================================================================

              五、常用命令

              1.合约相关命令

              • 利用CNS部署和调用合约(推荐)

                • 部署合约: deployByCNS

                • 调用合约: callByCNS

                • 查询CNS部署合约信息: queryCNS

              • 普通部署和调用合约

                • 部署合约: deploy

                • 调用合约: call

                2.其他命令

                • 查询区块高度:getBlockNumber

                • 查询共识节点列表:getSealerList

                • 查询交易回执信息: getTransactionReceipt

                • 切换群组: switch

                  3.快捷键

                  • Ctrl+A:光标移动到行首

                  • Ctrl+D:退出控制台

                  • Ctrl+E:光标移动到行尾

                  • Ctrl+R:搜索输入的历史命令

                  • ↑:向前浏览历史命令

                  • ↓:向后浏览历史命令

                    4.help

                    输入help或者h,查看控制台所有的命令。

                    [group:1]> help
                    * help([-h, -help, --h, --H, --help, -H, h])  Provide help information
                    * addObserver                               Add an observer node
                    * addSealer                                 Add a sealer node
                    * call                                      Call a contract by a function and parameters
                    * callByCNS                                 Call a contract by a function and parameters by CNS
                    * create                                    Create table by sql
                    * delete                                    Remove records by sql
                    * deploy                                    Deploy a contract on blockchain
                    * deployByCNS                               Deploy a contract on blockchain by CNS
                    * desc                                      Description table information
                    * quit([quit, q, exit])                     Quit console
                    * freezeAccount                             Freeze the account
                    * freezeContract                            Freeze the contract
                    * generateGroup                             Generate a group for the specified node
                    * generateGroupFromFile                     Generate group according to the specified file
                    * getAccountStatus                          GetAccountStatus of the account
                    * getAvailableConnections                   Get the connection information of the nodes connected with the sdk
                    * getBatchReceiptsByBlockHashAndRange       Get batched transaction receipts according to block hash and the transaction range
                    * getBatchReceiptsByBlockNumberAndRange     Get batched transaction receipts according to block number and the transaction range
                    * getBlockByHash                            Query information about a block by hash
                    * getBlockByNumber                          Query information about a block by number
                    * getBlockHashByNumber                      Query block hash by block number
                    * getBlockHeaderByHash                      Query information about a block header by hash
                    * getBlockHeaderByNumber                    Query information about a block header by block number
                    * getBlockNumber                            Query the number of most recent block
                    * getCode                                   Query code at a given address
                    * getConsensusStatus                        Query consensus status
                    * getContractStatus                         Get the status of the contract
                    * getCryptoType                             Get the current crypto type
                    * getCurrentAccount                         Get the current account info
                    * getDeployLog                              Query the log of deployed contracts
                    * getGroupConnections                       Get the node information of the group connected to the SDK
                    * getGroupList                              Query group list
                    * getGroupPeers                             Query nodeId list for sealer and observer nodes
                    * getNodeIDList                             Query nodeId list for all connected nodes
                    * getNodeInfo                               Query the specified node information.
                    * getNodeVersion                            Query the current node version
                    * getObserverList                           Query nodeId list for observer nodes.
                    * getPbftView                               Query the pbft view of node
                    * getPeers                                  Query peers currently connected to the client
                    * getPendingTransactions                    Query pending transactions
                    * getPendingTxSize                          Query pending transactions size
                    * getSealerList                             Query nodeId list for sealer nodes
                    * getSyncStatus                             Query sync status
                    * getSystemConfigByKey                      Query a system config value by key
                    * getTotalTransactionCount                  Query total transaction count
                    * getTransactionByBlockHashAndIndex         Query information about a transaction by block hash and transaction index position
                    * getTransactionByBlockNumberAndIndex       Query information about a transaction by block number and transaction index position
                    * getTransactionByHash                      Query information about a transaction requested by transaction hash
                    * getTransactionByHashWithProof             Query the transaction and transaction proof by transaction hash
                    * getTransactionReceipt                     Query the receipt of a transaction by transaction hash
                    * getTransactionReceiptByHashWithProof      Query the receipt and transaction receipt proof by transaction hash
                    * grantCNSManager                           Grant permission for CNS by address
                    * grantCommitteeMember                      Grant the account committee member
                    * grantContractStatusManager                Grant contract authorization to the user
                    * grantContractWritePermission              Grant the account the contract write permission.
                    * grantDeployAndCreateManager               Grant permission for deploy contract and create user table by address
                    * grantNodeManager                          Grant permission for node configuration by address
                    * grantOperator                             Grant the account operator
                    * grantSysConfigManager                     Grant permission for system configuration by address
                    * grantUserTableManager                     Grant permission for user table by table name and address
                    * insert                                    Insert records by sql
                    * listAbi                                   List functions and events info of the contract.
                    * listAccount                               List the current saved account list
                    * listCNSManager                            Query permission information for CNS
                    * listCommitteeMembers                      List all committee members
                    * listContractStatusManager                 List the authorization of the contract
                    * listContractWritePermission               Query the account list which have write permission of the contract.
                    * listDeployAndCreateManager                Query permission information for deploy contract and create user table
                    * listDeployContractAddress                 List the contractAddress for the specified contract
                    * listNodeManager                           Query permission information for node configuration
                    * listOperators                             List all operators
                    * listSysConfigManager                      Query permission information for system configuration
                    * listUserTableManager                      Query permission for user table information
                    * loadAccount                               Load account for the transaction signature
                    * newAccount                                Create account
                    * queryCNS                                  Query CNS information by contract name and contract version
                    * queryCommitteeMemberWeight                Query the committee member weight
                    * queryGroupStatus                          Query the status of the specified group of the specified node
                    * queryThreshold                            Query the threshold
                    * queryVotesOfMember                        Query votes of a committee member.
                    * queryVotesOfThreshold                     Query votes of updateThreshold operation
                    * recoverGroup                              Recover the specified group of the specified node
                    * registerCNS                               RegisterCNS information for the given contract
                    * removeGroup                               Remove the specified group of the specified node
                    * removeNode                                Remove a node
                    * revokeCNSManager                          Revoke permission for CNS by address
                    * revokeCommitteeMember                     Revoke the account from committee member
                    * revokeContractStatusManager               Revoke contract authorization to the user
                    * revokeContractWritePermission             Revoke the account the contract write permission
                    * revokeDeployAndCreateManager              Revoke permission for deploy contract and create user table by address
                    * revokeNodeManager                         Revoke permission for node configuration by address
                    * revokeOperator                            Revoke the operator
                    * revokeSysConfigManager                    Revoke permission for system configuration by address
                    * revokeUserTableManager                    Revoke permission for user table by table name and address
                    * switch([s])                               Switch to a specific group by group ID
                    * select                                    Select records by sql
                    * setSystemConfigByKey                      Set a system config value by key
                    * startGroup                                Start the specified group of the specified node
                    * stopGroup                                 Stop the specified group of the specified node
                    * unfreezeAccount                           Unfreeze the account
                    * unfreezeContract                          Unfreeze the contract
                    * update                                    Update records by sql
                    * updateCommitteeMemberWeight               Update the committee member weight
                    * updateThreshold                           Update the threshold
                    ---------------------------------------------------------------------------------------------

                    注:

                    • help显示每条命令的含义是:命令 命令功能描述

                    • 查看具体命令的使用介绍说明,输入命令 -h或--help查看。例如:

                      [group:1]> getBlockByNumber -h
                      Query information about a block by block number.
                      Usage:
                      getBlockByNumber blockNumber [boolean]
                      * blockNumber -- Integer of a block number, from 0 to 2147483647.
                      * boolean -- (optional) If true it returns the full transaction objects, if false only the hashes of the transactions.

                      5.切换群组

                      运行switch或者s,切换到指定群组。群组号显示在命令提示符前面。

                      [group:1]> switch 2
                      Switched to group 2.
                      ​
                      [group:2]>

                      扩容节点

                      FISCO BCOS引入了游离节点、观察者节点和共识节点,这三种节点类型可通过控制台相互转换。

                      • 共识节点:参与共识的节点,拥有群组的所有数据(搭链时默认都生成共识节点)。

                      • 观察者节点:不参与共识,但能实时同步链上数据的节点。

                      • 游离节点:已启动,待等待加入群组的节点。处在一种暂时的节点状态,不能获取链上的数据。

                        将指定节点分别转换成共识节点、观察者节点、游离节点,相关操作命令如下:

                        • addSealer:根据节点NodeID设置对应节点为共识节点

                        • addObserver:根据节点NodeID设置对应节点为观察节点

                        • removeNode:根据节点NodeID设置对应节点为游离节点

                        • getSealerList:查看群组中共识节点列表

                        • getObserverList:查看群组中观察节点列表

                        • getNodeIDList:查看节点已连接的所有其他节点的NodeID

                          一、为节点生成证书并启动

                          每个节点都需要有一套证书来与链上的其他节点建立连接,扩容一个新节点,首先需要为其签发证书。

                          1.为新节点生成私钥证书

                          接下来的操作都在nodes/127.0.0.1目录下进行

                          1. 获取证书生成脚本

                          curl -#LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/gen_node_cert.sh

                          注解

                          • 如果因为网络问题导致长时间无法下载,请尝试curl -#LO https://gitee.com/FISCO-BCOS/FISCO-BCOS/raw/master-2.0/tools/gen_node_cert.sh

                            1. 生成新节点私钥证书

                            # -c指定机构证书及私钥所在路径
                            # -o输出到指定文件夹,其中node4/conf中会存在机构agency新签发的证书和私钥
                            # 成功会输出 All completed 提示
                            bash gen_node_cert.sh -c ../cert/agency -o node4

                            国密版本请执行下面的指令生成证书。

                            bash gen_node_cert.sh -c ../cert/agency -o node4 -g ../gmcert/agency/

                            2.准备节点配置文件

                            1. 拷贝node0/config.ini、node0/start.sh和node0/stop.sh到node4目录;

                            cp node0/config.ini node0/start.sh node0/stop.sh node4/
                            1. 修改node4/config.ini。对于[rpc]模块,修改channel_listen_port=20204和jsonrpc_listen_port=8549;对于[p2p]模块,修改listen_port=30304并在node.中增加自身节点信息;

                            $ vim node4/config.ini
                            [rpc]
                                ;rpc listen ip
                                listen_ip=127.0.0.1
                                ;channelserver listen port
                                channel_listen_port=20204
                                ;jsonrpc listen port
                                jsonrpc_listen_port=8549
                            [p2p]
                                ;p2p listen ip
                                listen_ip=0.0.0.0
                                ;p2p listen port
                                listen_port=30304
                                ;nodes to connect
                                node.0=127.0.0.1:30300
                                node.1=127.0.0.1:30301
                                node.2=127.0.0.1:30302
                                node.3=127.0.0.1:30303
                                node.4=127.0.0.1:30304
                            1. 节点3拷贝节点1的node0/conf/group.1.genesis(内含群组节点初始列表)和node0/conf/group.1.ini到node4/conf目录下,不需改动;

                            cp node0/conf/group.1.genesis node0/conf/group.1.ini node4/conf/
                            1. 执行node4/start.sh启动节点;

                            bash node4/start.sh
                            1. 确认node4与其他节点连接已经建立,加入网络操作完成。

                            tail -f node4/log/log*  | grep "connected count"
                            # 以下日志表明节点node4与其他4个节点建立了连接
                            info|2020-12-22 20:44:36.113611|[P2P][Service] heartBeat,connected count=4
                            info|2020-12-22 20:44:46.117942|[P2P][Service] heartBeat,connected count=4
                            info|2020-12-22 20:44:56.120799|[P2P][Service] heartBeat,connected count=4

                            二、节点加入群组

                            1.获取node4的nodeid

                            cat node4/conf/node.nodeid

                            得到类似下面的字符串就是nodeid,nodeid是节点公钥的16进制表示,国密请执行cat node4/conf/gmnode.nodeid

                            94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e

                            2.使用控制台将node4加入群组1

                            1. 回到cd ~/fisco/console路径,bash start.sh进入控制台

                              2.使用addObserver将node4作为观察节点加入群组1

                            [group:1]> getObserverList
                            []
                            ​
                            [group:1]> addObserver 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
                            {
                                "code":1,
                                "msg":"Success"
                            }
                            ​
                            [group:1]> getObserverList
                            [
                                94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
                            ]
                            1. 使用addSealer将node4作为共识节点加入群组1

                            [group:1]> getSealerList
                            [
                                6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
                                7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
                                a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
                                e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed
                            ]
                            ​
                            [group:1]> addSealer 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
                            {
                                "code":1,
                                "msg":"Success"
                            }
                            ​
                            [group:1]> getSealerList
                            [
                                6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
                                7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
                                a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
                                e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed,
                                94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
                            ]

                            注:

                            如果需要加入其他群组,再进行以上命令进行加入。

                            安装WeBase-Front中间件

                            1. 下载安装包

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

                              unzip webase-front.zip
                              cd webase-front

                            3.拷贝sdk证书文件(build_chain的时候生成的)

                            将节点所在目录nodes/${ip}/sdk下的所有文件拷贝到当前conf目录,供SDK与节点建立连接时使用(SDK会自动判断是否为国密,且是否使用国密SSL)

                            • 链的sdk目录包含了ca.crt, sdk.crt, sdk.key和gm文件夹,gm文件夹包含了国密SSL所需的证书

                            • 拷贝命令可使用cp -r nodes/${ip}/sdk/* ./conf/

                            • 注,只有在建链时手动指定了-G(大写)时节点才会使用国密SSL

                              1. 服务启停

                                服务启停命令:

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

                              访问

                              访问 http://{deployIP}:{frontPort}/WeBASE-Front

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]