diff --git a/docs.json b/docs.json index 8edd5fa93..74f7067b3 100644 --- a/docs.json +++ b/docs.json @@ -316,6 +316,7 @@ "pages": [ "ecosystem/nodes/cpp/setup-mytonctrl", "ecosystem/nodes/cpp/run-validator", + "ecosystem/nodes/cpp/run-liteserver", "ecosystem/nodes/cpp/run-archive-liteserver", "ecosystem/nodes/cpp/integrating-with-prometheus", "ecosystem/nodes/cpp/setup-mylocalton", @@ -2139,7 +2140,7 @@ }, { "source": "/v3/guidelines/nodes/running-nodes/liteserver-node", - "destination": "/ecosystem/nodes/cpp/run-archive-liteserver", + "destination": "/ecosystem/nodes/cpp/run-liteserver", "permanent": true }, { @@ -4148,4 +4149,4 @@ "permanent": true } ] -} +} \ No newline at end of file diff --git a/ecosystem/nodes/cpp/run-liteserver.mdx b/ecosystem/nodes/cpp/run-liteserver.mdx new file mode 100644 index 000000000..2b9cb4cb2 --- /dev/null +++ b/ecosystem/nodes/cpp/run-liteserver.mdx @@ -0,0 +1,434 @@ +--- +title: "Run a liteserver" +description: "Run a liteserver node with MyTonCtrl" +--- + +import { Aside } from '/snippets/aside.jsx'; + +## Objective + +This guide describes how to set up a liteserver using MyTonCtrl. + +## Prerequisites + +- A server meeting the [minimal hardware requirements](#1-1-minimal-hardware-requirements) +- An OS meeting the [requirements](#1-2-os-and-system-requirements) + +## Step 1: Prepare environment + +### 1.1 Minimal hardware requirements + +- 16-core CPU +- 64 GB RAM +- At least 1 TB of NVMe Gen4+ SSD storage (Enterprise grade preferred) or Provisioned 64k+ IOPS storage. +- 1 Gbit/s symmetric connectivity (both inbound and outbound), \~16 TB/month at peak load +- Fixed (static) public IP address + + + +### 1.2 OS and system requirements + +- [Ubuntu](https://ubuntu.com/download/server) 22.04/24.04 LTS or [Debian](https://www.debian.org/distrib/) 11/12 +- Python 3.10 or higher + +### 1.3 Subscribe to official channels + +Subscribe and follow the announcements provided for liteservers in the following Telegram channels: + +| Channel | Network | +| -------------------------------------------- | ----------- | +| [@tonstatus](https://t.me/tonstatus) | TON Mainnet | +| [@testnetstatus](https://t.me/testnetstatus) | TON Testnet | + +### 1.4 Free space requirements + +Ensure sufficient free disk space for the initial download and extraction of the database dump. + +- The `/tmp` directory requires over 235 GB of free space. +- The `/var` directory requires over 740 GB of free space. + +### 1.5 Prepare the operator account + +To create a dedicated operator user and switch to it before installing MyTonCtrl: + +- Create a non-root user: + +```bash +# Create a non-root operator user +sudo adduser +sudo usermod -aG sudo +``` + +Define placeholders: + +- `` - name of the non-root operator user. + +- `` - public IP address of the server. + +- `` - custom SSH port number configured in Step 1.7. + +- Switch to the new operator account by reconnecting via SSH: + +```bash +# Option 1: Reconnect using the standard port +exit +ssh @ +``` + +```bash +# Option 2: Reconnect using the custom SSH port +exit +ssh @ -p +``` + +### 1.6 Benchmark server performance + +Before installing, verify that the server meets performance requirements. Inadequate disk or network performance is the most common cause of validator instability. + +#### 1.6.1 Network latency + +Check latency to TON beacon nodes. Expect approximately 50 milliseconds to the nearest beacon and up to 300 milliseconds to the farthest: + +```bash +ping beacon-eu-01.toncenter.com -c 6 +ping beacon-apac-01.toncenter.com -c 6 +``` + +#### 1.6.2 Disk IOPS + +Install `fio` and run a random read/write benchmark: + +```bash +sudo apt install -y fio +fio --randrepeat=1 --ioengine=psync --direct=1 --gtod_reduce=1 --name=tlstest --bs=4k --iodepth=1 --size=40G --readwrite=randrw --numjobs=1 --group_reporting --filename=/var/ton-work/testfile --time_based=1 --runtime=60 +rm /var/ton-work/testfile +``` + +Minimum acceptable results: + +| Metric | Minimum | +| ------ | -------- | +| Read | 10k IOPS | +| Write | 10k IOPS | + + + +#### 1.6.3 Network bandwidth + +Verify network throughput with `speedtest-cli`: + +```bash +sudo apt install -y speedtest-cli +speedtest-cli +``` + +Ensure download and upload speeds meet the [1 Gbit/s requirement](#1-1-minimal-hardware-requirements). + +### 1.7 Harden server security + + + +#### SSH hardening + +Apply the following SSH configuration changes in `/etc/ssh/sshd_config`: + +- Enable key-based authentication and disable password login: + +```text +PasswordAuthentication no +PubkeyAuthentication yes +``` + +- Disable root login: + +```text +PermitRootLogin no +``` + +- Change the default SSH port: + +```text +Port +``` + +- Restrict SSH access to specific IP addresses using the `Match Address` directive: + +```text +Match Address + AllowUsers +``` + +Define placeholders: + +- `` - a custom non-default port number (for example, `2222`). +- `` - IP address or subnet permitted to connect via SSH. +- `` - name of the operator user. + +Restart the SSH service after changes: + +```bash +sudo systemctl restart sshd +``` + +#### Firewall configuration + +Enable the firewall and allow only the SSH port. The node UDP port and liteserver port are added after installation in [open the node UDP port and the liteserver port](#2-2-1-open-the-node-udp-port-and-the-liteserver-port). + +```bash +sudo apt install -y ufw +sudo ufw allow +sudo ufw enable +sudo ufw status +``` + +#### Additional security measures + +- Use a unique, strong password for the root user. + +- Set a GRUB bootloader password to prevent unauthorized boot modifications. + +- Enable Fail2ban for SSH brute-force protection: + + ```bash + sudo apt install -y fail2ban + sudo systemctl enable fail2ban + sudo systemctl start fail2ban + ``` + +- Configure two-factor authentication for SSH using `libpam-google-authenticator` or a similar PAM module. + +## Step 2: Liteserver installation + +The installation process consists of two stages (in total, this can take up to three hours): + +- Download DB dump and install the liteserver +- Final synchronization of the liteserver + +### 2.1 Download DB dump and install the liteserver + +### 2.1.1 Install prerequisites and download installer (MyTonCtrl) + +```bash + sudo apt update + sudo apt install -y curl wget git ca-certificates python3-pip + wget https://raw.githubusercontent.com/ton-blockchain/mytonctrl/master/scripts/install.sh +``` + +### 2.1.2 Run liteserver installation + +Run the installer from the operator account with `sudo` so it can create system users and services: + + + ```bash Mainnet + ARCHIVE_TTL=2592000 && STATE_TTL=86400 && sudo -v && nohup sudo bash install.sh -m liteserver -n mainnet -d > mytonctrl_installation.log 2>&1 & + ``` + + ```bash Testnet + ARCHIVE_TTL=2592000 && STATE_TTL=86400 && sudo -v && nohup sudo bash install.sh -m liteserver -n testnet -d > mytonctrl_installation.log 2>&1 & + ``` + + +Installation runs in the background. + +Monitor the progress using the following command: + +```bash +tail -f mytonctrl_installation.log +``` + +During the download process, the log contains entries like the following: + +```text +[#cf6515 8.5GiB/218GiB(3%) CN:8 DL:242MiB ETA:14m44s] +[#cf6515 8.7GiB/218GiB(4%) CN:8 DL:247MiB ETA:14m27s] +[#cf6515 9.0GiB/218GiB(4%) CN:8 DL:252MiB ETA:14m7s] +``` + + + +Upon successful completion of the installation, the following line appears in the log: + +```text +[5/5] Mytonctrl installation completed +``` + +### 2.2 Final synchronization of liteserver + +This process starts automatically after installation and can take from one to several hours depending on server performance. + +Monitor the progress using MyTonCtrl: + +```bash +mytonctrl --cmd status +``` + +Check the `Local validator initial sync status` field. The value indicates how old the last imported block was. On a fully synchronized node, this value should be less than 20 seconds. + +### 2.2.1 Open the node UDP port and the liteserver port + +At this stage, the node UDP port and liteserver port should be opened to make the archive liteserver available for syncing blocks from other nodes. + +Identify the node UDP port and liteserver port from the `config.json` file: + +```bash +sudo grep -A5 '"addrs"' -n /var/ton-work/db/config.json | grep '"port"' | head -1 +sudo grep -A5 '"liteservers"' -n /var/ton-work/db/config.json | grep '"port"' | head -1 +``` + +Update security groups or configure `ufw` on bare-metal hosts: + +```bash +sudo ufw allow +sudo ufw allow +sudo ufw status +``` + +Define placeholders: + +- `` - UDP port of the validator engine. +- `` - TCP port of the liteserver. + +## Step 3: Maintenance + +### 3.1 Set up alerting + +Set up alerting in MyTonCtrl to get a notification of critical issues with the liteserver. For more information, see [MyTonCtrl private alerting bot](/ecosystem/nodes/cpp/mytonctrl/alerting). + +### 3.2 Set up monitoring + +Set up monitoring dashboards for RAM, disk, network, CPU usage, and other metrics. + +For system-level metrics, [integrate Prometheus with node\_exporter with MyTonCtrl](/ecosystem/nodes/cpp/integrating-with-prometheus). + +It is critical to use the monitoring system to: + +- monitor server stability +- monitor synchronization parameters +- check for memory leaks + +For technical assistance, contact [@mytonctrl\_help\_bot](https://t.me/mytonctrl_help_bot). + +### 3.3 Perform software updates + +Follow the @tonstatus channel, turn on notifications, and be prepared for urgent updates if needed. + +Update the node software and MyTonCtrl: + +```bash +mytonctrl --cmd "update master" +mytonctrl --cmd "upgrade master" +``` + +These commands will check for new versions of the TON node binaries and MyTonCtrl, download them, and apply the updates. + + + +## Troubleshooting + +### Monitor logs + +To see detailed logs of synchronization process, increase the log verbosity from the MyTonCtrl console: + +```bash +mytonctrl --cmd "installer set_node_argument --verbosity 3" +``` + +Then follow the log file from a separate terminal: + +```bash +tail -f /var/ton-work/log* +``` + +Set verbosity back to `1` after checking logs to avoid excessive disk I/O overhead: + +```bash +mytonctrl --cmd "installer set_node_argument --verbosity 1" +``` + +### Performance issues + +Logs containing "Importing archive for masterchain seqno #... from net" accompanied by timeout errors indicate insufficient storage performance. Ensure the disk meets the IOPS requirements listed in [Minimal hardware requirements](#1-1-minimal-hardware-requirements). + +To verify disk and system performance, run the built-in `mytonctrl` benchmark: + +1. Stop the validator service: + + ```bash + sudo systemctl stop validator.service + ``` + +1. Run the benchmark: + + ```bash + mytonctrl --cmd benchmark + ``` + +For stable liteserver operation, the benchmark score should be **greater than 70%**. + +### Manual DB dump download + +A manual download of the database dump is required if it does not download automatically. Download a pre-built database dump instead of syncing from peers. Check the [dump index](https://dump.ton.org/) for available snapshots. + +1. Install `aria2` and `plzip` if not already present: + + ```bash + sudo apt install -y aria2 plzip + ``` + +1. Stop the validator and MyTonCore services: + + ```bash + sudo systemctl stop mytoncore.service + sudo systemctl stop validator.service + ``` + +1. Download and extract the dump: + + ```bash + cd /var/ton-work/ + aria2c -x 16 https://dump.ton.org/dumps/latest.tar.lz + mv /var/ton-work/db /var/ton-work/db_old + mkdir /var/ton-work/db + plzip -d -c /var/ton-work/latest.tar.lz | tar -xvf - -C /var/ton-work/db + ``` + +1. Restore configuration and keys from the original database: + + ```bash + cp /var/ton-work/db_old/config.json /var/ton-work/db/config.json + cp -r /var/ton-work/db_old/keyring /var/ton-work/db/keyring + sudo chown -R validator:validator /var/ton-work/db + ``` + +1. Start the services again: + + ```bash + sudo systemctl start validator.service + sudo systemctl start mytoncore.service + ``` + +## Support + +For technical assistance, join the official support channel: [@ton\_node\_help](https://t.me/ton_node_help). + +## See also + +- [TON node types](/ecosystem/nodes/overview) +- [Run a node with MyTonCtrl](/ecosystem/nodes/cpp/setup-mytonctrl)