Bối cảnh hiện tại các điều kiện để nhận airdop của dự án ngày càng gắt gao, đòi hỏi anh em phải là người dùng thực của các nền tảng. Trong tương lai, mình nghĩ việc chạy node sẽ dễ được nhận airdop hơn vì anh em đang đóng góp trực tiếp vào quá trình kiểm tra và vận hành mạng lưới. Tuy nhiên cách này tốn kém chi phí ban đầu và mất nhiều thời gian để setup node, đòi hỏi anh em phải am hiểu cơ bản về code để xử lý các vấn đề phát sinh.
Hôm nay mình sẽ hướng dẫn anh em chạy node Aptos bằng Source Code. Anh em đọc bài viết bên dưới nhé!!!
Tìm hiểu thêm về tìm năng của Aptos tại đây.
Cài đặt Virtual Private Servers (VPS)
Mua VPS trên Contabo
– Anh em truy cập https://contabo.com/en/ để mua VPS. Sau đó >chọn gói Virtual Private Servers.
– Anh em chọn gói Cloud VPS M nhé. Gói này thường dùng nhất.
– Tiếp theo anh em chọn thời gian thuê VPS. Ở đây mình chạy testnet AT2 chỉ trong 1 tháng nên chọn 1 Month. Phần Region mình chọn Asia, anh em có thể chọn European cho tiết kiệm.
– Ở phần 5 anh em điền password rồi tiến hành thanh toán, các phần còn lại để mặc định.
– Sau khi hoàn thành các bước trên, anh em sẽ được chuyển đến giao diện thanh toán. Dưới đây là giao diện sau khi anh em thanh toán hoàn tất.
– Và một email xác nhận từ Contabo sẽ được gửi tới anh em.
Setup căn bản VPS
– Tiếp theo là phần setup VPS nhé, anh em làm theo trình tự bên dưới:
– Tiếp theo vào phần Manage => Chọn Control
– Sau đó anh em tiến hành reset lại password nhé. Đây là password anh em sử dụng trên máy ảo.
– Trường hợp anh em gặp lỗi thiếu port 22 thì anh em sử dụng VNC để thêm port vào nhé.
Hướng dẫn chạy node Aptos
Bước 1: Truy cập vào máy ảo bằng Terminal (MacOS) hoặc Putty (Window)
Bước 2: Cài đặt cần thiết
sudo apt update && sudo apt upgrade -y
- sudo apt-get install jq unzip -y sudo apt install screen
apt install git
apt install cargo
Bước 3: Kiểm tra firewall và mở port
– Anh em chạy các lệnh này:
ufw enable
ufw allow 22
ufw allow 80
ufw allow 80/tcp
ufw allow 9101
ufw allow 8080
ufw allow 22/tcp
ufw allow 181
ufw allow 182
– Sau đó chạy lệnh để hiện thông tin port:
ufw status
Bước 4: Using Aptos-core source code
1) Clone the Aptos repo.
git clone https://github.com/aptos-labs/aptos-core.git
2) cd into aptos-core
cd aptos-core
3) Run the scripts/dev_setup.sh Bash script as shown below. This will prepare your developer environment.
./scripts/dev_setup.sh
4) Update your current shell environment
source ~/.cargo/env
5) Checkout the testnet branch using git checkout –track origin/testnet git checkout –track origin/testnet
git checkout –track origin/testnet
6) Create a directory for your Aptos node composition. e.g.
export WORKSPACE=testnet
mkdir ~/$WORKSPACE
7) Generate key pairs (node owner key, consensus key and networking key) in your working directory.
cargo run –release -p aptos — genesis generate-keys –output-dir ~/$WORKSPACE
Lưu ý: trong file này bạn sẽ có 3 file chìa khóa cá nhân cần lưu giữ kín đáo: private-keys.yaml , validator-identity.yaml , validator-full-node-identity.yaml
8) Config validation
cargo run –release -p aptos — genesis set-validator-configuration \
–keys-dir ~/$WORKSPACE –local-repository-dir ~/$WORKSPACE \
–username tên bạn\
–validator-host IPVPS:6180
Ví dụ, tôi tên Đạt và IP VPS là 194.66.76.42 thì nó sẽ bằng
cargo run –release -p aptos — genesis set-validator-configuration \
–keys-dir ~/$WORKSPACE –local-repository-dir ~/$WORKSPACE \
–username dat\
–validator-host 194.66.76.42:6180
9) Create layout.yaml
nano ~/$WORKSPACE/layout.yaml
Anh em copy file dưới đây:
—
root_key: “F22409A93D1CD12D2FC92B5F8EB84CDCD24C348E32B3E7A720F3D2E288E63394”
users:
– “username tên bạn”
chain_id: 40
min_stake: 0
max_stake: 100000
min_lockup_duration_secs: 0
max_lockup_duration_secs: 2592000
epoch_duration_secs: 86400
initial_lockup_timestamp: 1656615600
min_price_per_gas_unit: 1
allow_new_validators: true
Lưu ý: “username tên bạn” phải trùng với username anh em đặt ở trên nhé, sau khi xong thì ctrl S rồi Ctrl X.
10) Build AptosFramework Move bytecode and copy into the framework folder.
cargo run –release –package framework — –package aptos-framework –output current
mkdir ~/$WORKSPACE/framework
mv aptos-framework/releases/artifacts/current/build/**/bytecode_modules/*.mv ~/$WORKSPACE/framework/
mv aptos-
framework/releases/artifacts/current/build//bytecode_modules/dependencies//*.mv
~/$WORKSPACE/framework/
11) Compile genesis blob and waypoint
cargo run –release -p aptos — genesis generate-genesis –local-repository-dir ~/$WORKSPACE –output-dir ~/$WORKSPACE
12) Copy the validator.yaml , fullnode.yaml files into this directory.
mkdir ~/$WORKSPACE/config
cp docker/compose/aptos-node/validator.yaml ~/$WORKSPACE/validator.yaml cp docker/compose/aptos-node/fullnode.yaml ~/$WORKSPACE/fullnode.yaml
13) Anh em lưu ý từ bước này nhé, kiểm tra kỹ từng đoạn tránh nhầm lẫn tên thư mục của admin.
cd
cd testnet
ls
pwd
Lưu ý: copy đoạn /root/testnet để config vào validator.yaml /root/testnet
nano validator.yaml
Lưu ý: các dòng mình khoanh đỏ, thay bằng nhánh thư mục copy ở trên /root/testnet sau khi thay thì sẽ như thế này:
Sau khi kiểm tra kỹ thì Ctr+S xong Ctrl+X.
Tiếp tục thực thi lệnh:
cd
cd aptos-core
14) Start your local Validator by running the below command:
cargo run -p aptos-node –release — -f ~/$WORKSPACE/validator.yaml
Bước 5: Lấy thông tin đăng kí
Lưu ý: Đừng vội điền form chạy nhé ae, bước này lấy key lưu lại, sẽ điền sau khi kết thúc bước cuối cùng.
Bước 6: Custom aptod-node
nano /etc/systemd/system/aptos-node.service
Điền các dòng lệnh bên dưới vào file trên:
Description=Aptos-node
After=network.target
[Service]
Type=simple
User=root
ExecStart=/aptos-core/target/release/aptos-node -f /root/testnet/validator.yaml
Restart=on-failure
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
Bước 7: Chạy lệnh Restart
sudo systemctl enable aptos-node
sudo systemctl restart aptos-node
journalctl -f -u aptos-node
Vậy là chúng ta đã hoàn thành chạy node testnet AT2 cho Aptos, anh em có thể điền form đăng kí chạy node tại đây. Sau khi hoàn tất đăng kí, anh em sẽ nhận được mail xác nhận từ Aptos.
Hướng dẫn chạy node Aptos (AIT3)
Hướng dẫn tạo Petra Aptos Wallet
Để kết nối ví, đầu tiên anh em cần tải wallet testnet. Anh em tải extension tại đây.
Sau đó, anh em vào extension của Google để tạo ví, bật chế độ dành cho nhà phát triển để upload file giải nén đã tải ở trên nhé!
Sau khi cài đặt extension thì anh em tiến hành tạo ví như bình thường nhé (tạo mật khẩu, lưu private key). Tiếp theo, anh em lấy token testnet bằng các nhấn Faucet.
Sau đó, anh em quay lại website Aptos connect ví để hoàn thành bước 2 của quá trình đăng kí nhé!
Hướng dẫn chạy AIT3
Bước 1: Cài đặt gói
sudo apt update && sudo apt upgrade -y
sudo apt-get install jq unzip -y
sudo apt install screen
Bước 2: Cài đặt cargo
apt install cargo
Bước 3: Clone git aptos repo
git clone https://github.com/aptos-labs/aptos-core.git
cd aptos-core
Bước 4: Chuẩn bị môi trường của bạn
./scripts/dev_setup.sh
Anh em nhấn Y để tiếp tục.
Cập nhật môi trường hiện tại của bạn
source ~/.cargo/env
Cài đặt aptos cli
cargo install –git https://github.com/aptos-labs/aptos-core.git aptos –branch testnet
Checkout the testnet
git checkout –track origin/testnet
export WORKSPACE=testnode
export USERNAME=thang
mkdir ~/$WORKSPACE
Bước 5: Tạo Key
aptos genesis set-validator-configuration \
–local-repository-dir ~/$WORKSPACE \
–username thang \
–owner-public-identity-file ~/$WORKSPACE/keys/public-keys.yaml \
–validator-host 194.233.93.249:6180 \
–stake-amount 100000000000000
Anh em lưu ý thay tên vị trí mình không bôi đen. Nó sẽ tạo ra file yaml với tên của anh em.
Bước 6: Tạo layout YAML file
aptos genesis generate-layout-template –output-file ~/$WORKSPACE/layout.yaml
vi ~/$WORKSPACE/layout.yaml
Sau khi file layout YAML xuất hiện, anh em xoá hết dữ liệu trong file và copy đoạn code bên dưới vào:
—
root_key: “D04470F43AB6AEAA4EB616B72128881EEF77346F2075FFE68E14BA7DEBD8095E”
users: [“thang”]
chain_id: 43
allow_new_validators: false
epoch_duration_secs: 7200
is_test: true
min_stake: 100000000000000
min_voting_threshold: 100000000000000
max_stake: 100000000000000000
recurring_lockup_duration_secs: 86400
required_proposer_stake: 100000000000000
rewards_apy_percentage: 10
voting_duration_secs: 43200
voting_power_increase_limit: 20
Để lưu file anh em ấn w. Sau đó ấn q để thoát.
Bước 7 : Framework
cargo run –package framework — release
cp head.mrb ~/$WORKSPACE/framework.mrb
Bước 8: Biên dịch genesis blod và điểm tham chiếu
aptos genesis generate-genesis –local-repository-dir ~/$WORKSPACE –output-dir ~/$WORKSPACE
Bước 9: Tạo thư mục config
mkdir ~/$WORKSPACE/config
cp docker/compose/aptos-node/validator.yaml ~/$WORKSPACE/validator.yaml
cp docker/compose/aptos-node/fullnode.yaml ~/$WORKSPACE/fullnode.yaml
Bước 10: Chỉnh sửa
sudo nano /root/testnode/validator.yaml
Những vùng mình khoang đỏ anh em cần thay đổi đường dẫn như hình bên dưới (thay genesis = testnode):
Bước 11: Mở port
apt install ufw -y
ufw allow ssh
ufw allow https
ufw allow http
ufw allow 6180
ufw allow 80
ufw allow 9101
ufw allow 181
ufw allow 182
ufw allow 8080
ufw allow 9103
ufw enable
Nhấn Y để tiếp tục.
Bước 12: Khởi tạo node
cd aptos-core
screen -S aptos-core
cargo run -p aptos-node –release — -f ~/testnode/validator.yaml
Sau khi hoàn thành, anh em kiểm tra tình trạng node tại đây.
Lời kết
Trên đây là các bước hướng dẫn anh em chạy node testnet AIT2 và AIT3 của Aptos, nếu có thắc mắc anh em có thể join nhóm telegram Aptos Việt Nam tại đây để được giải đáp thắc mắc. Xin chào và hẹn gặp lại anh em ở những bài viết sau!!!
Trả lời