这是个人整理FISCO官方的笔记,欢迎各位大佬前来讨论,如有不对之处,请大佬指正。
安装ubuntu依赖
sudo apt install -y openssl curl
# 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= J A V A H O M E / l i b : JAVA_HOME/lib: JAVAHOME/lib:JRE_HOME/lib
export PATH= P A T H : PATH: PATH:JAVA_HOME/bin:$JRE_HOME/bin
# JDK 11
export JAVA_HOME=/usr/local/java/jdk-11.0.12
export CLASSPATH=$JAVA_HOME/lib
export PATH= P A T H : PATH: PATH:JAVA_HOME/bin
为配置方便,可以修改系统的配置文件:
系统级:对当前系统下所有用户生效,可以编辑/etc/profile或/etc/bash.bashrc两个文件中的其中一个,内容与上述的一致,这里不再赘述:
sudo vim /etc/profile
# 在文章末尾添加变量
…
# 配置生效
source /etc/profile
## 创建操作目录
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
在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
bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545
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
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.
________ ______ ______ ______ ______ _______ ______ ______ ______
| \| \ / \ / \ / \ | \ / \ / \ / \
| $$$$$$$$ \$$$$$$| $$$$$$\| $$$$$$\| $$$$$$\ | $$$$$$$\| $$$$$$\| $$$$$$\| $$$$$$\
| $$__ | $$ | $$___\$$| $$ \$$| $$ | $$ | $$__/ $$| $$ \$$| $$ | $$| $$___\$$
| $$ \ | $$ \$$ \ | $$ | $$ | $$ | $$ $$| $$ | $$ | $$ \$$ \
| $$$$$ | $$ _\$$$$$$\| $$ __ | $$ | $$ | $$$$$$$\| $$ __ | $$ | $$ _\$$$$$$\
| $$ _| $$_ | \__| $$| $$__/ \| $$__/ $$ | $$__/ $$| $$__/ \| $$__/ $$| \__| $$
| $$ | $$ \ \$$ $$ \$$ $$ \$$ $$ | $$ $$ \$$ $$ \$$ $$ \$$ $$
\$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$
=============================================================================================
Ctrl+A
:光标移动到行首Ctrl+D
:退出控制台Ctrl+E
:光标移动到行尾Ctrl+R
:搜索输入的历史命令输入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
---------------------------------------------------------------------------------------------
注:
[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.
运行switch或者s,切换到指定群组。群组号显示在命令提示符前面。
[group:1]> switch 2
Switched to group 2.
[group:2]>
FISCO BCOS引入了游离节点、观察者节点和共识节点,这三种节点类型可通过控制台相互转换。
将指定节点分别转换成共识节点、观察者节点、游离节点,相关操作命令如下:
每个节点都需要有一套证书来与链上的其他节点建立连接,扩容一个新节点,首先需要为其签发证书。
接下来的操作都在nodes/127.0.0.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
# -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/
node0/config.ini
、node0/start.sh
和node0/stop.sh
到node4目录;cp node0/config.ini node0/start.sh node0/stop.sh node4/
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
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/
node4/start.sh
启动节点;bash node4/start.sh
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
cat node4/conf/node.nodeid
得到类似下面的字符串就是nodeid,nodeid是节点公钥的16进制表示,国密请执行cat node4/conf/gmnode.nodeid
94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
回到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
]
[group:1]> getSealerList
[
6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed
]
[group:1]> addSealer 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
{
"code":1,
"msg":"Success"
}
[group:1]> getSealerList
[
6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed,
94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
]
注:
如果需要加入其他群组,再进行以上命令进行加入。