教程 ·

CESS容器部署一机多节点教程-测试网(20240202)

安装docker和docker compose
以ubuntu(官方推荐存储节点操作系统)为例安装docker:

1.更新系统软件包列表
sudo apt update

2.安装必要的依赖项:
sudo apt install apt-transport-https ca-certificates curl software-properties-common

3.添加Docker GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4.设置Docker仓库:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5.更新软件包索引并安装Docker引擎:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

6.将当前用户添加到docker组中,这样不需要使用sudo命令来运行docker,重启后生效:
sudo usermod -aG docker $USER

配置存储节点信息

1.为每个存储节点创建工作目录(以运行两个存储节点为例,两个存储程序的数据目录分别位于/mnt/disk0和/mnt/disk1,您可以修改为自己的目录。):
cd /mnt/disk0/
mkdir bucket storage
cd /mnt/disk1/
mkdir bucket storage
其中bucket目录用于存放存储节点配置文件,storage目录作为存储节点运行的工作目录;

 

2.复制以下内容,分别在每个存储节点bucket目录下创建config.yaml文件并粘贴:
# The rpc endpoint of the chain node
Rpc:
- "ws://127.0.0.1:9944/" (rpc节点ip+端口)
- "wss://testnet-rpc0.cess.cloud/ws/"
- "wss://testnet-rpc1.cess.cloud/ws/"
- "wss://testnet-rpc2.cess.cloud/ws/"
# Bootstrap Nodes
Boot:
- "_dnsaddr.boot-bucket-testnet.cess.cloud"
# Signature account mnemonic
Mnemonic: "xxx xxx ... xxx"
# Staking account
# If you fill in the staking account, the staking will be paid by the staking account,
# otherwise the staking will be paid by the signature account.
StakingAcc: "cXxxx...xxx"
# earnings account
EarningsAcc: cXxxx...xxx
# Service workspace
Workspace: "/opt/bucket-disk"
# P2P communication port
Port: 4001
# Maximum space used, the unit is GiB
UseSpace: 2000
# Number of cpu's used, 0 means use all
UseCpu: 4
# Priority tee list address
TeeList:
- "127.0.0.1:8080"
- "127.0.0.1:8081"
需要注意,每个存储节点应设置不同的工作账户,工作路径和端口等
请注意,配置RPC时,第一个是本地的RPC节点地址,若采用第三种类型则只需要配置外部RPC地址;配置文件中展示的第2-第4个RPC地址为CESS官方推荐地址,Boot中展示的地址为CESS官方提供的存储节点boot node节点地址。

3.配置好配置文件的存储节点目录应当如下图所示:

第四步、配置并启动存储节点容器
请根据以下内容创建docker-compose.yaml文件,用于批量启动存储节点容器:
version: '3'
name: cess-storage
services:
bucket_0: #services name
image: 'cesslab/cess-bucket:testnet'
network_mode: host
restart: always
volumes: #Mapping of host disk to container
- '/mnt/disk0/bucket:/opt/bucket' #Node configuration directory
- '/mnt/disk0/storage/:/opt/bucket-disk' #Node working directory
command:
- run
- '-c'
- /opt/bucket/config.yaml
logging:
driver: json-file
options:
max-size: 500m
container_name: bucket0 #container name
bucket_1:
image: 'cesslab/cess-bucket:testnet'
network_mode: host
restart: always
volumes:
- '/mnt/disk1/bucket:/opt/bucket' #Node configuration directory
- '/mnt/disk1/storage/:/opt/bucket-disk' #Node working directory,
command:
- run
- '-c'
- /opt/bucket/config.yaml
logging:
driver: json-file
options:
max-size: 500m
container_name: bucket1
watchtower: #only needs to be run once
image: containrrr/watchtower
container_name: watchtower
network_mode: host
restart: always
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
command:
- '--cleanup'
- '--interval'
- '300'
- '--enable-lifecycle-hooks'
- chain
- bucket
logging:
driver: json-file
options:
max-size: 100m
max-file: '7'
上述文件中,运行多少个存储节点容器就需要配置多少个存储节点服务,yaml文件通过缩进两格来表示层级关系,如上述文件中,配置了bucket_0和bucket_1两个服务;每个服务中需要重点配置服务名,容器名以及宿主机到容器的目录映射;如在bucket_0中,目录映射配置如下:
volumes: #Mapping of host disk to container
- '/mnt/disk0/bucket:/opt/bucket' #Node configuration directory
- '/mnt/disk0/storage/:/opt/bucket-disk' #Node working directory
其中"/mnt/disk0/bucket/"是之前创建好的存放节点0配置文件的目录,里面有config.yaml, "/mnt/disk0/storage/"是之前创建好的存储节点0用于工作的工作目录;
watchtower服务用于监控各存储节点容器状态,并自动为容器动态更新最新的镜像,每台服务器配置一个该服务即可;

可以将docker-compose.yaml文件放在任何可访问的地方,配置好文件后,运行 docker compose up -d 命令来启动存储节点容器。

您可以通过docker ps -a命令查看存储节点的运行状态。

参与评论