FiscoBcos搭建多机区块链网络第一种方法
2023-12-13 09:31:52
环境
fisco 2.8.0
ubuntu 20
前言
此次实验将使用 build_chain.sh
脚本搭建 六个节点,一个机构,两个群组的区块链网络。
基于 fisco官方文档进行操作搭建多机区块链网络
请预先准备好两台ubuntu机子
我的环境两个机子的ip地址分别是【确保机子之前能相关能连接,使用ping
命令进行测试连接】
192.168.19.133
192.168.19.137
然后每台机子的节点端口如下[因为是多机搭建,所以端口的属于各自的机子的]
节点名称 | 节点地址 | p2p_port | channel_port | jsonrpc_port |
---|---|---|---|---|
node0 | 192.168.19.133 | 30300 | 20200 | 8545 |
node1 | 192.168.19.133 | 30301 | 20201 | 8546 |
node2 | 192.168.19.133 | 30302 | 20202 | 8547 |
node3 | 192.168.19.137 | 30300 | 20200 | 8545 |
node4 | 192.168.19.137 | 30301 | 20201 | 8546 |
node5 | 192.168.19.137 | 30302 | 20202 | 8547 |
进行节点的配置并生成
在192.168.19.137
进行ipconf
的文件编写,依据上面的表格
root@192-168-19-137:/yijiu# cat ipconf
192.168.19.133:3 agencyOne 1 30300,20200,8545 #请根据自己的实际机子ip地址进行过填写
192.168.19.137:3 agencyOne 1 30300,20200,8545 # 使用机构1 ,并且都属于群组1
然后使用-f
参数进行节点的相关配置文件生成
bash build_chain.sh -f ipconf -e ./fisco-bcos
root@192-168-19-137:/yijiu# bash build_chain.sh -f ipconf -e ./fisco-bcos
Checking fisco-bcos binary...
Binary check passed.
==============================================================
Generating CA key...
==============================================================
Generating keys and certificates ...
Processing IP=192.168.19.133 Total=3 Agency=agencyOne Groups=1
Processing IP=192.168.19.137 Total=3 Agency=agencyOne Groups=1
==============================================================
Generating configuration files ...
Processing IP=192.168.19.133 Total=3 Agency=agencyOne Groups=1
Processing IP=192.168.19.137 Total=3 Agency=agencyOne Groups=1
==============================================================
Group:1 has 6 nodes
==============================================================
[INFO] FISCO-BCOS Path : ./fisco-bcos
[INFO] IP List File : ipconf
[INFO] Start Port : 30300 20200 8545
[INFO] Server IP : 192.168.19.133:3 192.168.19.137:3
[INFO] Output Dir : /yijiu/nodes
[INFO] CA Path : /yijiu/nodes/cert/
==============================================================
[INFO] Execute the download_console.sh script in directory named by IP to get FISCO-BCOS console.
e.g. bash /yijiu/nodes/192.168.19.133/download_console.sh -f
==============================================================
[INFO] All completed. Files in /yijiu/nodes
然后这时候,先不能直接启动,因为节点文件都存在与 192.168.19.137
机子里,然后还需要将192.168.19.133
的节点文件拷贝到192.168.19.133
机子里
root@192-168-19-137:/yijiu# ll nodes/
总用量 20
drwxr-xr-x 5 root root 4096 12月 7 12:54 ./
drwxr-xr-x 3 root root 4096 12月 7 12:54 ../
drwxr-xr-x 6 root root 4096 12月 7 12:54 192.168.19.133/ # 这个
drwxr-xr-x 6 root root 4096 12月 7 12:54 192.168.19.137/
drwxr-xr-x 3 root root 4096 12月 7 12:54 cert/
拷贝节点配置
首先现在192.168.19.133
机子里创建一个nodes文件夹 [可能会叫你输入一下 192.168.19.133 普通账户的密码,大家也可以对这两个机子进行免密操作的配置]
# 根据自己的实际情况填写普通账户和ip地址
root@192-168-19-137:/yijiu# ssh yijiu@192.168.19.133 "mkdir -p /yijiu/nodes"
The authenticity of host '192.168.19.133 (192.168.19.133)' can't be established.
ECDSA key fingerprint is SHA256:8JZFwBijayGtqRHhBxJ6Z257Lbl3+I4kQ28UJTJ12gI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.19.133' (ECDSA) to the list of known hosts.
yijiu@192.168.19.133's password:
再拷贝相关文件到 192.168.19.133
机子
# scp -r 需要拷贝的文件路径 普通账户@目标的ip地址:路径
root@192-168-19-137:/yijiu# scp -r nodes/192.168.19.133 yijiu@192.168.19.133:/yijiu/nodes
yijiu@192.168.19.133's password:
fisco-bcos 100% 28MB 152.0MB/s 00:00
download_bin.sh 100% 5476 4.5MB/s 00:00
download_console.sh 100% 2932 5.0MB/s 00:00
reload_whitelist.sh 100% 1745 2.1MB/s 00:00
load_new_groups.sh 100% 1006 391.9KB/s 00:00
monitor.sh 100% 4635 5.3MB/s 00:00
reload_sdk_allowlist.sh 100% 647 154.9KB/s 00:00
config.ini 100% 1762 2.2MB/s 00:00
stop.sh 100% 830 235.0KB/s 00:00
start.sh 100% 1005 264.1KB/s 00:00
node.key 100% 237 367.8KB/s 00:00
node.nodeid 100% 129 259.2KB/s 00:00
group.1.genesis 100% 1537 3.2MB/s 00:00
node.crt 100% 1838 4.4MB/s 00:00
group.1.ini 100% 2745 5.5MB/s 00:00
ca.crt 100% 664 1.3MB/s 00:00
stop_all.sh 100% 506 1.2MB/s 00:00
.transTest.sh 100% 2627 2.4MB/s 00:00
reload_whitelist.sh 100% 1745 4.1MB/s 00:00
load_new_groups.sh 100% 1006 2.8MB/s 00:00
monitor.sh 100% 4635 9.8MB/s 00:00
reload_sdk_allowlist.sh 100% 647 1.8MB/s 00:00
config.ini 100% 1762 4.4MB/s 00:00
stop.sh 100% 830 2.2MB/s 00:00
start.sh 100% 1005 3.0MB/s 00:00
node.key 100% 237 684.6KB/s 00:00
node.nodeid 100% 129 381.9KB/s 00:00
group.1.genesis 100% 1537 3.6MB/s 00:00
node.crt 100% 1838 4.3MB/s 00:00
group.1.ini 100% 2745 7.1MB/s 00:00
ca.crt 100% 664 1.6MB/s 00:00
sdk.key 100% 237 288.1KB/s 00:00
sdk.publickey 100% 129 231.9KB/s 00:00
ca.crt 100% 664 1.6MB/s 00:00
sdk.crt 100% 1830 2.6MB/s 00:00
reload_whitelist.sh 100% 1745 3.3MB/s 00:00
load_new_groups.sh 100% 1006 1.7MB/s 00:00
monitor.sh 100% 4635 5.2MB/s 00:00
reload_sdk_allowlist.sh 100% 647 1.3MB/s 00:00
config.ini 100% 1762 3.5MB/s 00:00
stop.sh 100% 830 2.2MB/s 00:00
start.sh 100% 1005 2.6MB/s 00:00
node.key 100% 237 437.6KB/s 00:00
node.nodeid 100% 129 169.6KB/s 00:00
group.1.genesis 100% 1537 2.8MB/s 00:00
node.crt 100% 1838 4.4MB/s 00:00
group.1.ini 100% 2745 5.9MB/s 00:00
ca.crt 100% 664 1.2MB/s 00:00
start_all.sh
然后查看一下133
机子的文件夹是否已经成功拷贝
root@192-168-19-133:/# ll yijiu/nodes/192.168.19.133/
总用量 28584
drwxr-xr-x 6 yijiu yijiu 4096 12月 7 13:13 ./
drwxrwxr-x 3 yijiu yijiu 4096 12月 7 13:13 ../
-rwxr-xr-x 1 yijiu yijiu 5476 12月 7 13:13 download_bin.sh*
-rwxr-xr-x 1 yijiu yijiu 2932 12月 7 13:13 download_console.sh*
-rwxr-xr-x 1 yijiu yijiu 29213128 12月 7 13:13 fisco-bcos*
drwxr-xr-x 4 yijiu yijiu 4096 12月 7 13:13 node0/
drwxr-xr-x 4 yijiu yijiu 4096 12月 7 13:13 node1/
drwxr-xr-x 4 yijiu yijiu 4096 12月 7 13:13 node2/
drwxr-xr-x 2 yijiu yijiu 4096 12月 7 13:13 sdk/
-rwxr-xr-x 1 yijiu yijiu 520 12月 7 13:13 start_all.sh*
-rwxr-xr-x 1 yijiu yijiu 506 12月 7 13:13 stop_all.sh*
-rwxr-xr-x 1 yijiu yijiu 2627 12月 7 13:13 .transTest.sh*
root@192-168-19-133:/#
启动双机节点
有两种方法启动,一种是远程启动,一种是去到目标机子进行启动
- 启动
137
机子节点
root@192-168-19-137:/yijiu# bash nodes/192.168.19.137/start_all.sh
try to start node0
try to start node1
try to start node2
node0 start successfully
node1 start successfully
node2 start successfully
- 启动
133
机子节点 | 我选择和官方一样进行远程启动
root@192-168-19-137:/yijiu# ssh yijiu@192.168.19.133 "bash /yijiu/nodes/192.168.19.133/start_all.sh"
yijiu@192.168.19.133's password:
try to start node0
try to start node1
try to start node2
node2 start successfully
node0 start successfully
node1 start successfully
可以检查一下两台机子的启动情况
root@192-168-19-137:/yijiu# ps -ef | grep -v grep | grep fisco
root 6731 1 1 13:17 pts/0 00:00:04 /yijiu/nodes/192.168.19.137/node0/../fisco-bcos -c config.ini
root 6733 1 1 13:17 pts/0 00:00:04 /yijiu/nodes/192.168.19.137/node1/../fisco-bcos -c config.ini
root 6735 1 1 13:17 pts/0 00:00:04 /yijiu/nodes/192.168.19.137/node2/../fisco-bcos -c config.ini
root@192-168-19-133:/# ps -ef | grep -v grep | grep fisco
yijiu 9457 1 1 13:20 ? 00:00:02 /yijiu/nodes/192.168.19.133/node1/../fisco-bcos -c config.ini
yijiu 9459 1 1 13:20 ? 00:00:02 /yijiu/nodes/192.168.19.133/node0/../fisco-bcos -c config.ini
yijiu 9461 1 1 13:20 ? 00:00:02 /yijiu/nodes/192.168.19.133/node2/../fisco-bcos -c config.ini
检查某个节点的连接数是否征程
root@192-168-19-133:/# tail -f yijiu/nodes/192.168.19.133/node1/log/log* | grep connected
info|2023-12-9 13:24:18.561051|[P2P][Service] heartBeat,connected count=5
info|2023-12-9 13:24:28.561754|[P2P][Service] heartBeat,connected count=5
检查某个节点的共识状态
root@192-168-19-137:/yijiu# tail -f nodes/192.168.19.137/node2/log/log* | grep +++
info|2023-12-09 13:25:16.156900|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=b5eafd2c...
info|2023-12-09 13:25:22.190674|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=ce20bd30...
配置一个简单的控制台
准备好一个初始化的控制台文件
这个和普通单机搭建一样,将sdk
文件夹的证书拷贝进 console的conf
目录
root@192-168-19-137:/yijiu/console# cp -r ../nodes/192.168.19.137/sdk/* conf/
拷贝一个config,toml 文件
root@192-168-19-137:/yijiu/console# cp -r conf/config-example.toml conf/config.toml
修改config.toml 文件
[network]
peers=["192.168.19.137:20200"] # 需要注意这个参数,需要按照实际情况填写,console控制台是基于此参数选择以什么节点进行区块链网络操作
启动控制台
root@192-168-19-137:/yijiu/console# bash start.sh
=============================================================================================
Welcome to FISCO BCOS console(2.8.0)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
________ ______ ______ ______ ______ _______ ______ ______ ______
| | \/ \ / \ / \ | \ / \ / \ / \
| $$$$$$$$\$$$$$| $$$$$$| $$$$$$| $$$$$$\ | $$$$$$$| $$$$$$| $$$$$$| $$$$$$\
| $$__ | $$ | $$___\$| $$ \$| $$ | $$ | $$__/ $| $$ \$| $$ | $| $$___\$$
| $$ \ | $$ \$$ \| $$ | $$ | $$ | $$ $| $$ | $$ | $$\$$ \
| $$$$$ | $$ _\$$$$$$| $$ __| $$ | $$ | $$$$$$$| $$ __| $$ | $$_\$$$$$$\
| $$ _| $$_| \__| $| $$__/ | $$__/ $$ | $$__/ $| $$__/ | $$__/ $| \__| $$
| $$ | $$ \\$$ $$\$$ $$\$$ $$ | $$ $$\$$ $$\$$ $$\$$ $$
\$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$$ \$$$$$$ \$$$$$$ \$$$$$$
=============================================================================================
[group:1]>
查看peers
[group:1]> getPeers
[
PeerInfo{
nodeID='9bb06a10288a809d20b5f52cb19754b330f8b8626e9346ec7bca2595469eb604debf536f5d25963b603f596a9581ba8cb513f431d685f1cd3e0deab7b7c59fa6',
iPAndPort='192.168.19.133:37122',
node='node0',
agency='agencyOne',
topic='[
]'
},
PeerInfo{
nodeID='581a96ff7f6c04957d19b0b4ba14e9fe019ca3bcadb9fdc7f7768fe4831b655345d80c115f5375a033994776a85f379ec73360f221123a9c0c3a43afcb5c680a',
iPAndPort='192.168.19.133:37138',
node='node2',
agency='agencyOne',
topic='[
]'
},
PeerInfo{
nodeID='08c694ec0f8fdce1323a61adf93f6c22670a5994a651e61018c1b4dcf46de09cdeb261f944e90b7a58c01f8dae850b81a0be619298c2ee2d8f4f94b5b3e39b17',
iPAndPort='192.168.19.133:37150',
node='node1',
agency='agencyOne',
topic='[
]'
},
PeerInfo{
nodeID='f61bc799ffa0c8ead5a976fc8d67706079d361d85720b77e6875f9ee5fb97f7e78e2484671e364712a87ec713b9695185533135546941198d5bdbbd3befa3fd6',
iPAndPort='192.168.19.137:30301',
node='node1',
agency='agencyOne',
topic='[
]'
},
PeerInfo{
nodeID='4513c784506e318e93af312f2042cd519ecc523a65cbce2f0274034712eecb16182da3cd38cc226874396ebb8bc7481aa9e3bce2749c4f9f050708c9328416a5',
iPAndPort='192.168.19.137:30302',
node='node2',
agency='agencyOne',
topic='[
]'
}
]
结语
这种搭建方式会比较繁琐,因为如果再有更多的机子和更多的节点,就会要一直做重复的复制和登录操作,推荐搭建使用 官方的企业级运维部署工具
文章来源:https://blog.csdn.net/weixin_52865146/article/details/134852547
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!