前言
学习了比特币后,了解了区块链是什么,也可以跳过以太坊的学习,来到区块链3.0等平台的学习使用,但若能掌握以太坊各种技术的使用,是可以很好地理解此类平台的。
1. 安装依赖
安装依赖,用开发部署工具 build_chain.sh
脚本建链,该脚本依赖 openssl 和 curl,所以先安装依赖:
sudo apt install -y openssl curl
如果遇到锁定问题:
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
解决方法:
sudo rm /var/lib/apt/lists/lock && sudo rm /var/cache/apt/archives/lock && sudo rm /var/lib/dpkg/lock* && sudo dpkg --configure -a && sudo apt update
2. 创建操作目录
创建操作目录fisco并进入该目录
cd ~ && mkdir -p fisco && cd fisco
3. 下载脚本
curl -#LO https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/releases/v2.8.0/build_chain.sh && chmod u+x build_chain.sh
4. 搭建单群组4节点联盟链
在 fisco 目录下执行下面的指令,生成一条单群组4节点的 FISCO 链。请确保机器的 30300~30303,20200~20203,8545~8548
端口没有被占用。
bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545
命令执行成功会输出 All completed
。如果执行出错,请检查 nodes/build.log
文件中的错误信息。
Checking fisco-bcos binary...
Binary check passed.
... # (略去中间输出)
[INFO] All completed. Files in /home/ubuntu/fisco/nodes
以上操作完成后目录结构如下:
-fisco
- nodes
- 127.0.0.1
- download_bin.sh
- download_console.sh
- fisco-bcos
- node0
- conf
- config.ini
- scripts
- start.sh
- stop.sh
- node1
- conf
- config.ini
- scripts
- start.sh
- stop.sh
- node2
- conf
- config.ini
- scripts
- start.sh
- stop.sh
- node3
- conf
- config.ini
- scripts
- start.sh
- stop.sh
- sdk
- ca.crt
- sdk.crt
- sdk.key
- sdk.publickey
- start_all.sh
- stop_all.sh
- cert
- agency
- ca.crt
- ca.key
- ca.srl
- cert.cnf
5. 启动 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
到这里,4节点联盟链就已经部署并启动完成了
6. 检查
检查进程
检查进程是否启动:
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
检查日志输出
1.查看节点 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=3
info|2019
2.检查是否在共识
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...