普通节点(非验证者节点)安装

二进制可执行程序获取

YOU 二进制文件获取

链程序目前支持Linux/Windows/macOS等不同平台,通过项目GitHub官网获取到源码或者相应的二进制文件。

根据源码编译

  • 基本要求:
    golang 1.13+
    go mod(用于依赖管理)
    xgo2(github.com/youchainhq/xgo2 , fork from xgo. 用于跨平台编译并支持go mod)
    
  • 编译步骤
    • 开启gomod export GO111MODULE="on"
    • 获取xgo用于跨平台编译 go get -u github.com/youchainhq/xgo2
    • 主目录下Makefile支持不同平台的编译,譬如生成Linux二进制程序:make buildlinux
    • 编译成功后在output目录下获取到二进制文件

make devtools 可以安装或提示安装所依赖的工具。

不论是源码编译出来的还是直接下载的release二进制文件,通过 -h 选项可查看版本及帮助信息,如./you -h

Name:
   you - The YOUChain client application

   Copyright 2018-2020 YOUCHAIN FOUNDATION LTD.

Usage:
   you [options] [command [command options]] [arguments...]

Version:
   0.9.8

Description:
   Branch: master Revision: b24826b4 BuildTime: 2020-06-02 11:10:01

Commands:

   help, h  Shows a list of commands or help for one command

   CONSOLE COMMANDS:
     desc           show description
     console        Start an interactive JavaScript environment
     attach         Start an interactive JavaScript environment (connect to node)
     check_genesis  export block hash from genesis file

Global options:
  Basic options:

    --datadir value    datadir (default: "data")
    --nodetype value   node type (archive, full, light or ultralight) (default: "full")
    --networkid value  Network identifier (unsigned integer, 1=MainNet, 2=PubTestNet, others for specific purpose(develop, self-net etc.)) (default: 1)

  Miner options:
    Options for miner, be cautious about the validator key options, see corresponding document for detail.

    --mine           enable mining, default false -> disable
    --valaddr value  the address representing a validator key to use
    --pwd value      the password for the validator key
    --keep           whether to keep the validator key in plaintext

  Consensus options:
    These options are mainly for testing or running a new chain.

    --constype value       consensus type: 0 - YPOS, 1 - Solo (default: 0)
    --genesis value        Path to genesis
    --uconkey value
    --blssignkey value
    --soloblocktime value  1s,1000ms (default: 3s)

  RPC options:
    Options for providing rpc services.

    --rpc.gascap value      Sets a cap on gas that can be used in eth_call/estimateGas (default: 0)
    --rpc.host value        HTTP-RPC server listening interface (default: "localhost")
    --rpc.port value        HTTP-RPC server listening port (default: 8283)
    --rpc.corsdomain value  Comma separated list of domains from which to accept cross origin requests (browser enforced) (default: "*")
    --rpc.vhosts value      Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "*")
    --rpc.api value         API's offered over the HTTP-RPC interface (default: "net,you")
    --rpc.wshost value      WS-RPC server listening interface (default: "localhost")
    --rpc.wsport value      WS-RPC server listening port (default: 8284)
    --rpc.wsapi value       API's offered over the WS-RPC interface (default: "net,you")
    --rpc.wsorigins value   Origins from which to accept websockets requests (default: "*")
    --rpc.ipcenabled        Enable the IPC-RPC server, default is false
    --rpc.ipcpath value     ipc path, default: youchain.ipc

  P2P options:
    These options are mainly for P2P.

    --p2p.bootnode value      P2P discovery bootstrap
    --p2p.port value          Network listening port (default: 9283) (default: 9283)
    --p2p.discover value      P2P discover port (default: 9284) (default: 9284)
    --p2p.nodekey value       P2P node key file
    --p2p.nodekeyhex value    P2P node key as hex (for testing)
    --p2p.maxpeers value      Maximum number of nodes that can be connected (default: 50) (default: 50)
    --p2p.maxpendpeers value  Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) (default: 0)
    --p2p.msgevent            Open the node msg report(true is open, false is close)
    --p2p.nodiscovery         Disables the peer discovery mechanism (manual peer addition)
    --p2p.localnet            The node runs on the local area network
    --nat.type value          NAT type, vales:Unknown|None|Full|Restricted|PortRestricted|Symmetric (default: "Unknown")
    --nat.master value        NAT master server IP address and port (default: "42.62.25.77:45521")
    --nat.slave value         NAT slave server IP address and port (default: "42.62.25.79:45523")
    --nat.pubservice value    NAT public detection service address (default: "stun.ideasip.com:3478")

  Metrics options:
    These options are mainly for debugging.

    --pprof
    --pprof.host value                 (default: "0.0.0.0")
    --pprof.port value                 (default: 7283)
    --log.level value                  (default: 3)
    --log.vmodule value
    --log.path value
    --metrics
    --metrics.influxdb
    --metrics.influxdb.hostname value
    --metrics.influxdb.database value
    --metrics.influxdb.username value
    --metrics.influxdb.password value

  TxPool options:
    These options are mainly for TxPool.

    --txpool.journal value       Disk journal for local transaction to survive node restarts (default: "transactions.rlp")
    --txpool.rejournal value     Time interval to regenerate the local transaction journal (default: 1h0m0s)
    --txpool.pricelimit value    Minimum gas price limit to enforce for acceptance into the pool (default: 1000000000)
    --txpool.pricebump value     Price bump percentage to replace an already existing transaction (default: 10)
    --txpool.accountslots value  Minimum number of executable transaction slots guaranteed per account (default: 64)
    --txpool.globalslots value   Maximum number of executable transaction slots for all accounts (default: 4096)
    --txpool.accountqueue value  Maximum number of non-executable transaction slots permitted per account (default: 256)
    --txpool.globalqueue value   Maximum number of non-executable transaction slots for all accounts (default: 1024)
    --txpool.lifetime value      Maximum amount of time non-executable transaction are queued (default: 3h0m0s)

  DevOp options:
    These options are mainly for DevOp.

    --bootnodeid value       bootNodeId (default: -1)
    --bootuconfile value     bootuconfile
    --bootnodesvcname value  boot node service name in k8s
    --help, -h               show help
    --version, -v            print the version


Use "you help [COMMAND]" or "you [COMMAND] --help" for more information on a command.

启动参数说明

对于非验证者节点,不用提供 Miner optionsConsensus options,只需通过 --networkid 指定要连接的网络。

其他参数,基本都是与节点本地管理有关,比如 数据存储目录、日志目录、日志级别、rpc绑定的地址及端口等等,大部分采用默认值即可。详见帮助信息。

比较常见要设置的参数:

  • -rpc.ipcenabled 开启ipc,可以通过console形式与You链程序交互;
  • -nodetype 节点类型,有archive/full/light/ultralight等4种类型,默认为full
  • -log.path 日志存放路径,一般建议与程序同级目录下,例如logs
  • -log.level 输出日志的级别,从 0~5 分别为 Crit、Error、Warn、Info、Debug、Trace,默认值3 即 Info。

Note:关于nodetype节点类型的介绍可以参考如下表格:

节点类型 历史区块 最新区块 历史状态 最新状态 全量区块头 最新区块头 CHT BLT 依赖类型 备注
1:存档节点(archive node) 1/2 官方和核心社区维护;可以查询历史高度下的状态
2:全节点(full node) 1/2 适用于普通设备;只能查询最新状态
3:轻节点(light node) 1/2 适用于存储受限,且需要参与共识的设备
4:超轻节点(ultra light node) 1/2 作为客户端,请求服务器,查询状态

运行示例

根据需要选择程序运行方式。下面提供一种在 Linux(Centos) 下将节点程序部署为系统服务从而持续运行的参考。

部署目录

一般选择独立的磁盘进行部署,譬如/data/目录,可以创建子目录/data/youchain 目录内容一般如下:

├─── start.sh   You程序启动脚本,包含有启动相关参数
├─── you-linux-amd64/you-windows-amd64/you-linux-arm64 You链程序,支持不同平台,更新时请注意版本
├─── data  You程序启动后,链数据存储目录
├─── logs  You程序启动后,日志存储目录

Note: data和logs为You程序启动后生成的目录

程序启动脚本 start.sh

程序启动脚本包含了节点启动所必需的参数:

#!/bin/sh
cd /data/youchain
./you-linux-amd64 -rpc.ipcenabled -nodetype archive -log.path logs

部署步骤

推荐通过Linux自带systemd部署程序,可以参考如下youchain.service配置:

[Unit]
Description=youchain_client

[Service]
TimeoutStartSec=0
ExecStart=/data/youchain/start.sh
Restart=always
RestartSec=5s
User=youchain
Group=youchain

[Install]
WantedBy=multi-user.target

note:出于系统安全考虑,建议以youchain:youchain的权限执行程序部署

如下步骤需要在目录/data/youchain下完成:

  1. 编辑和拷贝youchain.service
sudo mv youchain.service /etc/systemd/system/
  1. 设置程序开机启动:
sudo systemctl enable youchain.service
  1. 启动youchain服务:
sudo chown youchain:youchain -R /data
sudo systemctl start youchain
  1. 观察节点启动状态,查看最新日志文件中有投票信息:tail -f logs/app.log | grep height,参考主网区块链浏览器出现最新的高度后,说明节点已经正常启动

  2. 完成部署启动流程