Intermediate
How to Install and Configure a Consensus Node
Welcome to our tutorial on setting up a consensus node on the Klaytn blockchain network. In Klaytn, consensus nodes are responsible for participating in the consensus process and validating transactions on the network. Setting up a consensus node is a crucial step in becoming a validator on the Klaytn network and earning rewards for participating in the consensus process. In this tutorial, we will explore the process of setting up a consensus node on the Klaytn network, including the necessary hardware and software requirements, the configuration steps, and the best practices for maintaining and securing the node. Whether you are a developer, researcher, or simply a blockchain enthusiast, this tutorial will provide valuable insights and hands-on experience in setting up a consensus node on the Klaytn network.
Linux Archive Distribution
The archive file consists of the executable binary and the configuration file structured as follows.
Note: Do NOT alter the file structure or file name. If you change it, the node may not function correctly.
bin |- kcn |- kcnd conf |- kcnd.conf
File Name |
File Description |
---|---|
bin/kcn |
CN executable file |
bin/kcnd |
CN start/termination script file |
conf/kcnd.conf |
CN configuration file |
Installation
The installation is the uncompression of the downloaded package where you want to install the package
$ tar zxf kcn-vX.X.X-linux-amd64.tar.gz
Or,
$ tar zxf kcn-baobab-vX.X.X-linux-amd64.tar.gz
Note: it is recommended that the uncompressed directory kcn-linux-amd64/bin
path should be added to the environment variable $PATH
to run the kcn
and kcnd
globally. As an example,
$ export PATH=$PATH:~/downloaded/path/kcn-linux-amd64/bin
The other sections assume that the path is added to the variable.
RPM Distribution (RHEL/CentOS/Fedora)
Install downloaded RPM
You can install the downloaded RPM file with the following yum
command.
$ yum install kcnd-vX.X.X.el7.x86_64.rpm
Or,
$ yum install kcnd-baobab-vX.X.X.el7.x86_64.rpm
Install from Klaytn Yum Repo
Alternatively, you can install kcnd
from the Klaytn Yum repo, run:
$ sudo curl -o /etc/yum.repos.d/klaytn.repo https://packages.klaytn.net/config/rhel/7/prod.repo && sudo yum install kcnd
Installed Location
The installed files are located as follows.
File Name |
Location |
---|---|
kcn |
/usr/bin/kcn |
kcnd.conf |
/etc/kcnd/conf/kcnd.conf |
Configuration
The CN configuration is to create a data directory and set up several values in the configuration file kcnd.conf
.
-
Create the CN data directory.
-
Install node key
-
Configure the CN with
kcnd.conf
.
CN Data Directory Creation
Considering the fact that the size of Klaytn blockchain data is always increasing, it is recommended to use a big enough storage. You may need to create the directory on your desired path.
$ mkdir -p /var/kcnd/data
Install Node Key
In order to operate a CN, a nodekey
is required. The KCN binary will create a new one for you if you do not have one. If you have one, you need to put your nodekey
into the CN data directory.
$ cp nodekey /var/kcnd/data
$ cp nodekey /var/kcnd/data
Update the Configuration File
Configuration File Location:
-
For the archive distribution, the config directory location defaults to
$INSTALL_PATH/kcn-linux-amd64/conf/
. -
For the package distribution, the config directory defaults to
/etc/kcnd/conf/
.
Add Data Directory
You should update the data directory environment variable $DATA_DIR
on the configuration file kcnd.conf
.
Setup Rewardbase
... DATA_DIR=/var/kcnd/data ...
As a reward for participating in the consensus of the Klaytn network, the CN operator will receive KLAY. For this reason, it is required to set an address on the configuration file kcnd.conf
.
The ways to create a new account are various, but the kcn
also provides the functionality. You can check the help message with the following command.
$ kcn account new --help
One example of doing this procedure is as follows. First of all, you need to create a new account which the reward KLAY will be sent.
$ kcn account new --datadir ~/kcnd_home INFO[03/15,09:04:43 +09] [17] Setting connection type nodetype=cn conntype=-0 INFO[03/15,09:04:43 +09] [17] Maximum peer count KLAY=25 LES=0 total=25 INFO[03/15,09:04:43 +09] [17] SBN is disabled. Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {d13f7da0032b1204f77029dc1ecbf4dae2f04241}
As a result of this, it will create the associated keystore on the path that you define. Next, you need to put the created address in the file kcnd.conf
file as follows.
... REWARDBASE="d13f7da0032b1204f77029dc1ecbf4dae2f04241" ...
Startup the CN
CN Start/Stop
You can start/stop the Klaytn service with the following systemctl
command.
Note: This requires root privileges.
start
$ systemctl start kcnd.service
stop
$ systemctl stop kcnd.service
status
$ systemctl status kcnd.service
Troubleshooting
If you meet the following error,
Failed to start kcnd.service: Unit not found.
reload the systemd manager configuration with the following command.
$ systemctl daemon-reload