门外汉自学系列:[ 二、 快速部署 cita 服务]

快速部署 CITA 服务

检查主机软件包并更新

sudo apt update
#检查软件包
sudo apt upgrade -y
#更新软件包

安装 Docker 环境

sudo apt install -y docker.io

Tips:
更多 Docker 安装教程参考: Install Docker Engine on CentOS | Docker Docs

启动 Docker

service docker start
#启动docker
service docker status
#查看docker状态 按q退出查看
##下载并解压缩 CITA 安装包文件
#(当前最新版本为v0.20.2)
cd /opt
wget https://github.com/cryptape/cita/releases/download/v0.20.2/cita_secp256k1_sha3.tar.gz
tar zxvf cita_secp256k1_sha3.tar.gz
cd cita_secp256k1_sha3

Tips:
CITA 还提供了 blake2b签名算法+ed25519的加密算法,以及sm2、sm3国密算法的版本,本文内容都是以 secp256k1_sha3 版本为例子说明;

创建用户

./env.sh bin/create_key_addr new_account_key new_account_address
cat new_account_key new_account_address

0x4466f6fc6a70914775734187ff380ec7cf8fb1b115a73e180f95cedac7fedcd9
#账户私钥
0x6859a022d47f22a153fecb4dd91714a6f8607a2b
#账户地址

Tips:
从 CITA v0.20版本开始,部署前需拥有一个用户,在部署时指定该用为此链的超级管理员;
官方提供测试账户:

  • 账户地址:0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523
  • 账户私钥:0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6

创建共识节点配置文件

按照下列指令,填写账户地址0x6859a022d47f22a153fecb4dd91714a6f8607a2b,将赋予此用户超级管理员权限,并且引导您创建4个默认配置的节点文件, CITA最少需要运行4个节点(共识节点)才能正常出块;

./env.sh ./scripts/create_cita_config.py create --nodes “127.0.0.1:4000,127.0.0.2:4001,127.0.0.3:4002,127.0.0.4:4003” --chain_name ‘test-chain’ --super_admin 0x6859a022d47f22a153fecb4dd91714a6f8607a2b --contract_arguments VersionManager.version=1 SysConfig.economicalModel=1

Tips:
SysConfig.economicalModel用于修改经济模型;0表示没有经济激励,1表示给予经济激励;

初始化节点配置文件

./env.sh ./bin/cita setup test-chain/0
./env.sh ./bin/cita setup test-chain/1
./env.sh ./bin/cita setup test-chain/2
./env.sh ./bin/cita setup test-chain/3

启动CitA节点

按照下列指令,将引导您启动4个默认配置的节点(共识节点),运行 CITA 服务,区块开始产出;

./daemon.sh ./bin/cita start test-chain/0
./daemon.sh ./bin/cita start test-chain/1
./daemon.sh ./bin/cita start test-chain/2
./daemon.sh ./bin/cita start test-chain/3

查看当前4个节点的进程,每个节点会启动7个微服务进程

ps aux | grep ‘cita-’ | grep -v ‘grep’
root 24463 0.0 0.6 53148 24820 ? Sl 07:34 0:00 cita-forever
root 24474 0.0 1.3 207780 54464 ? Sl 07:34 0:03 cita-network -c network.toml
root 24475 0.1 1.3 227872 56288 ? Sl 07:34 0:06 cita-chain -c chain.toml
root 24476 0.3 1.3 217272 55992 ? Sl 07:34 0:14 cita-auth -c auth.toml
root 24477 0.1 1.7 252084 70112 ? Sl 07:34 0:05 cita-executor -g genesis.json -c executor.toml
root 24478 0.1 1.3 224140 52544 ? Sl 07:34 0:07 cita-bft -c consensus.toml -p privkey
root 24479 0.0 1.9 213452 78068 ? Sl 07:34 0:02 cita-jsonrpc -c jsonrpc.toml
root 24719 0.0 0.7 53148 28932 ? Sl 07:34 0:00 cita-forever
root 24726 0.1 1.7 252084 69160 ? Sl 07:34 0:05 cita-executor -g genesis.json -c executor.toml
root 24728 0.1 1.3 224132 52592 ? Sl 07:34 0:07 cita-bft -c consensus.toml -p privkey
root 24732 0.0 1.3 207780 52800 ? Sl 07:34 0:03 cita-network -c network.toml
root 24733 0.0 1.7 207308 69852 ? Sl 07:34 0:02 cita-jsonrpc -c jsonrpc.toml
root 24734 0.1 1.3 227872 54808 ? Sl 07:34 0:06 cita-chain -c chain.toml
root 24735 0.3 1.3 217272 53496 ? Sl 07:34 0:14 cita-auth -c auth.toml
root 24961 0.0 0.7 53148 30984 ? Sl 07:34 0:00 cita-forever
root 24970 0.0 1.3 207780 55024 ? Sl 07:34 0:03 cita-network -c network.toml
root 24971 0.3 1.3 217272 53836 ? Sl 07:34 0:14 cita-auth -c auth.toml
root 24972 0.1 1.7 254132 70844 ? Sl 07:34 0:05 cita-executor -g genesis.json -c executor.toml
root 24974 0.0 1.6 207308 65612 ? Sl 07:34 0:02 cita-jsonrpc -c jsonrpc.toml
root 24976 0.1 1.3 224136 53136 ? Sl 07:34 0:08 cita-bft -c consensus.toml -p privkey
root 24977 0.1 1.3 227872 54528 ? Sl 07:34 0:05 cita-chain -c chain.toml
root 25178 0.0 0.5 53148 22756 ? Sl 07:34 0:00 cita-forever
root 25194 0.3 1.3 217272 56044 ? Sl 07:34 0:14 cita-auth -c auth.toml
root 25195 0.0 1.3 207780 54680 ? Sl 07:34 0:03 cita-network -c network.toml
root 25196 0.0 1.7 207308 70224 ? Sl 07:34 0:02 cita-jsonrpc -c jsonrpc.toml
root 25197 0.1 1.4 227872 57308 ? Sl 07:34 0:05 cita-chain -c chain.toml
root 25198 0.1 1.7 254132 71052 ? Sl 07:34 0:05 cita-executor -g genesis.json -c executor.toml
root 25199 0.1 1.4 232328 59528 ? Sl 07:34 0:07 cita-bft -c consensus.to

Tips:
关于微服务的详细说明,请参考: https://docs.nervos.org/cita/#/configuration/service_config


:grinning: 很感谢您能够看到这里,如果文中的内容有描述不当,请您在本章节下方指出,我会尽快修改;