1.安装依赖(Ubuntu)
sudo apt install -y openssl curl
2.创建操作目录,下载安装脚本
## 创建操作目录 cd ~ && mkdir -p fisco && cd fisco 下载脚本 curl -#LO https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/releases/v2.9.0/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 使用本地文件:bash build_chain.sh -e ./fisco-bcos -l 127.0.0.1:4 -p 30300,20200,8545 注意: 国密版本请执行 bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545 -g -G 其中-g表示生成国密配置,-G表示使用国密SSL连接
成功结果:
Checking fisco-bcos binary... Binary check passed. ============================================================== Generating CA key... ============================================================== Generating keys ... Processing IP:127.0.0.1 Total:4 Agency:agency Groups:1 ============================================================== Generating configurations... Processing IP:127.0.0.1 Total:4 Agency:agency Groups:1 ============================================================== [INFO] Execute the download_console.sh script in directory named by IP to get FISCO-BCOS console. e.g. bash /home/ubuntu/fisco/nodes/127.0.0.1/download_console.sh ============================================================== [INFO] FISCO-BCOS Path : bin/fisco-bcos [INFO] Start Port : 30300 20200 8545 [INFO] Server IP : 127.0.0.1:4 [INFO] Output Dir : /home/ubuntu/fisco/nodes [INFO] CA Key Path : /home/ubuntu/fisco/nodes/cert/ca.key ============================================================== [INFO] All completed. Files in /home/ubuntu/fisco/nodes
4.启动FISCO BCOS链
- 启动所有节点
bash nodes/127.0.0.1/start_all.sh
成功结果:
5.检查进程
ps -ef | grep -v grep | grep fisco-bcos
成功结果:
work 91631 1276 1 23:50 pts/1 00:00:01 /home/work/fisco/nodes/127.0.0.1/node1/../fisco-bcos -c config.ini work 91633 1276 1 23:50 pts/1 00:00:01 /home/work/fisco/nodes/127.0.0.1/node0/../fisco-bcos -c config.ini work 91635 1276 1 23:50 pts/1 00:00:01 /home/work/fisco/nodes/127.0.0.1/node3/../fisco-bcos -c config.ini work 91639 1276 1 23:50 pts/1 00:00:01 /home/work/fisco/nodes/127.0.0.1/node2/../fisco-bcos -c config.ini
6.检查日志输出
- 查看节点node0 链接的节点数
tail -f nodes/127.0.0.1/node0/log/log* | grep connected
配置及使用控制台
1.准备依赖
- 安装java
# ubuntu系统安装java sudo apt install -y default-jdk jdk1.8: sudo apt install -y openjdk-8-jdk 配置环境: export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
!!!注意:
Jave路径设置 若系统报错JAVA_HOME has not been configured(初始java安装也可参考以下步骤)
sudo apt install openjdk-8-jdk sudo vim /etc/profile #没有vim按系统提示安装 #进入后按i编辑文件,在最后写入下面两句,写完按esc退出编辑模式,然后按shift+:,键入wq回车保存退出(vim使用规则自行学习) export JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64 export PATH=$PATH:$JAVA_HOME/bin #更新文件 source /etc/profile
- 获取控制台并回到fisco目录
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
- 配置控制台证书
cp -r nodes/127.0.0.1/sdk/* console/conf/
2.启动并使用控制台
- 启动
cd ~/fisco/console && bash start.sh
成功结果:
- 部署及调用HelloWorld合约
-
- 编写HelloWorld合约
pragma solidity ^0.4.24; contract HelloWorld { string name; function HelloWorld() { name = "Hello, World!"; } function get()constant returns(string) { return name; } function set(string n) { name = n; } }
-
- 部署HelloWord合约
# 在控制台输入以下指令 部署成功则返回合约地址 [group:1]> deploy HelloWorld transaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23fa contract address:0xb3c223fc0bf6646959f254ac4e4a7e355b50a344
WBASE-Front
快速入门搭建
1.下载安装包
先进入到fisco目录下
cd fisco
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证书到webase-front/conf目录下
先进入到fisco目录下 cd ~ cd fisco 拷贝sdk证书 cp nodes/127.0.0.1/sdk/* webase-front/conf/
4.服务启停
启动: bash start.sh 停止: bash stop.sh 检查: bash status.sh
5.访问
http://localhost:5002/WeBASE-Front
动态增加新节点
- 所有的操作都在 nodes/127.0.0.1 目录下
- 利用外网获取私钥证书(本地无 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
- 准备节点配置文件
-
- 拷贝
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 //20204 ;jsonrpc listen port jsonrpc_listen_port=8549 //8549 [p2p] ;p2p listen ip listen_ip=0.0.0.0 ;p2p listen port listen_port=30304 //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 //node.4 30304
-
- 节点3拷贝节点1的
node0/conf/group.1.genesis
(内含群组节点初始列表)和node0/conf/group.1.ini
到node4/conf
目录下,不需改动;
- 节点3拷贝节点1的
cp node0/conf/group.1.genesis node0/conf/group.1.ini node4/conf/
- 启动节点
bash node4/start.sh
- 确认node4与其他节点连接已经建立,加入网络操作完成。
tail -f node4/log/log* | grep "connected count"
成功结果:
- 节点加入群组、
-
- 获取node4的nodeid
cat node4/conf/node.nodeid
成功结果:
-
- 使用控制台将node4加入群组1
-
-
- 使用addObserver将node4作为观察节点加入群组1
-
[group:1]> getObserverList [] [group:1]> addObserver 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e { "code":1, "msg":"Success" } [group:1]> getObserverList [ 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e ]
-
-
- 使用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 ]