มารันบิตคอยน์โหนดกัน
Bitcoin Node คือเครื่องคอมพิวเตอร์ที่ลง Bitcoin Client ในปัจจุบันมีหลายวิธีมากแต่ในบความนี้จะมาติดตั้งลงบน Linux แบบพื้นฐานเอาไว้ใช้งานส่วนตัว
อย่าลืมลง OS Linux ก่อนครับ
บทความนี้ผมใช้ Ubuntu server
มาเริ่มกันเลย อัปเดตและอัปเกรดระบบให้เรียบร้อยก่อน
sudo apt update && sudo apt upgrade -y
ติดตั้งเครื่องมือที่จำเป็นต้องใช้งาน
sudo apt install wget curl gnupg tar ufw -y
ตั้งค่า Firewall กันก่อนเพิ่มความปลอดภัย
เปิด Port เท่าที่จำเป็นต้องใช้
sudo ufw allow 22/tcp comment 'ssh'
sudo ufw allow 9051/tcp comment 'tor'
sudo ufw allow 9050/tcp comment 'tor'
sudo ufw allow 8333/tcp comment 'Bitcoin core peer'
sudo ufw allow 8332/tcp comment 'Bitcoin core RPC'
เปิด Firewall
sudo ufw enable
ตรวจสอบ Port Firewall
sudo ufw status
เครื่องของเราตอนนี้ก็พร้อมแล้วไปติดตั้ง Bitcoin node กันเลย
ผมใช้ Bitcoin core V29.0 คุณอยากใช้เวอร์ชันไหนเลือกชุดกฎที่คุณต้องการได้เลย
วิธีติดตั้ง Bitcoin core+Tor
ดาวน์โหลด Bitcoin core ลงเครื่อง
wget https://bitcoincore.org/bin/bitcoin-core-29.0/bitcoin-29.0-x86_64-linux-gnu.tar.gz
ดาวน์โหลด signatures ล่าสุด
wget https://bitcoincore.org/bin/bitcoin-core-29.0/SHA256SUMS
wget https://bitcoincore.org/bin/bitcoin-core-29.0/SHA256SUMS.asc
ตรวจสอบ Signature ของผู้พัฒนา ดาวน์โหลด Public key ของผู้พัฒนา
curl -s "https://api.github.com/repositories/355107265/contents/builder-keys" | grep download_url | grep -oE "https://[a-zA-Z0-9./-]+" | while read url; do curl -s "$url" | gpg --import; done
output
gpg: key 17565732E08E5E41: 29 signatures not checked due to missing keys
gpg: /home/admin/.gnupg/trustdb.gpg: trustdb created
gpg: key 17565732E08E5E41: public key "Andrew Chow <andrew@achow101.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: no ultimately trusted keys found
[...]
ตรวจสอบ Signature
gpg --verify SHA256SUMS.asc SHA256SUMS
output
gpg: Good signature from...
Primary key fingerprint:...
ตรวจสอบซอฟต์แวร์ว่าถูกต้องไหม
sha256sum --ignore-missing --check SHA256SUMS
output
bitcoin-29.0-x86_64-linux-gnu.tar.gz: OK
แตกไฟล์ Bitcoin core
tar -xzvf bitcoin-29.0-x86_64-linux-gnu.tar.gz
ติดตั้ง Bitcoin core
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-29.0/bin/bitcoin-cli bitcoin-29.0/bin/bitcoind
ตรวจสอบเวอร์ชั่น
bitcoind --version
ทดสอบ Bitcoin core
bitcoind -daemon
สั่ง Bitcoin core หยุดทำงาน
bitcoin-cli stop
ลบไฟล์ที่ไม่ได้ใช้งาน
sudo rm -r bitcoin-$VERSION bitcoin-29.0-x86_64-linux-gnu.tar.gz SHA256SUMS SHA256SUMS.asc
สร้างไฟล์ bitcoin.conf
sudo nano .bitcoin/bitcoin.conf
ตัวอย่าง bitcoin.conf
# [core]
# Run in the background as a daemon and accept commands.
daemon=1
# Maintain a full transaction index, used by the getrawtransaction rpc call.
txindex=1
# [network]
# Use separate SOCKS5 proxy <ip:port|path> to reach peers via Tor hidden services. May be a local file path prefixed with 'unix:'
onion=127.0.0.1:9050
bind=127.0.0.1
onlynet=onion
listen=1
# [rpc]
# Accept command line and JSON-RPC commands.
server=1
rpcuser=username #เปลี่ยน username ของคุณเอง
rpcpassword=password #เปลี่ยน password ของคุณเอง
rpcbind=0.0.0.0:8332
rpcallowip=0.0.0.0/0
deprecatedrpc=accounts
คุณสามรถตั้งค่า bitcoin.conf ด้วยตัวเองได้ไปที่ https://jlopp.github.io/bitcoin-core-config-generator
ติดตั้ง tor
sudo apt install tor -y
แก้ไข Tor Configuration
sudo nano /etc/tor/torrc
เพิ่ม Tor Configuration
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
HiddenServiceDir /var/lib/tor/bitcoin/bitcoinrpc
HiddenServiceVersion 3
HiddenServicePort 8332 127.0.0.1:8332
สร้าง Directory สำหรับ Hidden Service
sudo mkdir -p /var/lib/tor/bitcoin/bitcoinrpc
เปลี่ยน Ownership และ Permissions ของ Directory
sudo chown -R debian-tor:debian-tor /var/lib/tor/bitcoin/bitcoinrpc
sudo chmod 700 /var/lib/tor/bitcoin/bitcoinrpc
เพิ่ม User ให้กับ Group debian-tor
sudo usermod -a -G debian-tor username
อย่าลืมเปลี่ยน USERNAME ให้ตรงกับ user ของคุณ
sudo systemctl restart tor
สร้าง Systemd Service File สำหรับ Bitcoin Core การสร้าง Systemd Service เพื่อให้ระบบสมารถเรียกใช้ bitcoin daemon โดยอัตโนมัติในพื้นหลังได้
sudo nano /etc/systemd/system/bitcoind.service
configuration
[Unit] Description=Bitcoin daemon After=network.target
[Service] ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/username/.bitcoin/bitcoin.conf -datadir=/home/username/.bitcoin ExecStop=/usr/local/bin/bitcoin-cli stop User=username Group=username Type=forking Restart=on-failure
[Install] WantedBy=multi-user.target
> อย่าลืมเปลี่ยน USERNAME ให้ตรงกับ user ของคุณ
เปิดใช้งาน Bitcoind
sudo systemctl enable bitcoind
sudo systemctl start bitcoind
ตรวจสอบว่า Bitcoind ทำงานไหม
sudo systemctl status bitcoind
output
● bitcoind.service - Bitcoin daemon
Loaded: loaded (/etc/systemd/system/bitcoind.service; enabled; preset: enabled)
Active: active (running) since Sat 2025-04-19 14:10:16 UTC; 23min ago
Process: 812 ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/node/.bitcoin/bitcoin.conf -datadir=/home/node/.bitcoin (code=exited, >
Main PID: 876 (bitcoind)
Tasks: 26 (limit: 4552)
Memory: 3.2G (peak: 3.2G swap: 252.0K swap peak: 252.0K)
CPU: 12min 55.480s
CGroup: /system.slice/bitcoind.service
└─876 /usr/local/bin/bitcoind -daemon -conf=/home/node/.bitcoin/bitcoin.conf -datadir=/home/node/.bitcoin
Apr 19 14:10:14 node systemdbitcoind.service - Bitcoin daemon... Apr 19 14:10:16 node bitcoindCore starting Apr 19 14:10:16 node systemdbitcoind.service - Bitcoin daemon.
ติดตั้งทุกอย่างเสร็จแล้วมาตรวจสอบกันว่าทุกอย่างทำงานไหม
ตรวจสอบ Bitcoin core เขื่อมต่อกับ Tor network ไหม
bitcoin-cli -netinfo
Output
onion total block
in 0 0 out 10 10 2 total 10 10
Local addresses address.onion port 8333 score 4
ตรวจสอบ Bitcoind เปิด Port อะไรบ้าง
sudo ss -tulpn | grep bitcoind
Output
tcp LISTEN 0 4096 127.0.0.1:8333 0.0.0.0: users:(("bitcoind",pid=876,fd=30)) tcp LISTEN 0 128 0.0.0.0:8332 0.0.0.0: users:(("bitcoind",pid=876,fd=12))
ตรวจสอบ Bitcoin core ซิงก์ข้อมูลไปถึงไหนแล้ว
echo "$(bitcoin-cli getblockchaininfo | jq -r '.verificationprogress * 100') %"
> ต้องติดตั้ง jq ก่อน (sudo apt install jq)
ตรวจสอบ Bitcoin node เชื่อมต่อกับโหนดอื่นอยู่กี่โหหนด
bitcoin-cli getconnectioncount
เพียงแค่นี้ก็มี Bitcoin node ใช้งานแล้ว
# วิธีเชื่อมต่อ Wallet
ในไฟล์ bitcoin.conf เราได้ตั้ง userame:password ของ RPC ไว้แล้วส่วนนี้แหละที่เราจะเอาไปเชื่อมต่อเข้า Wallet ต่าง ๆ ที่เราใช้งาน
## เชื่อมต่อ wallet แบบใช้ ip
192.168.x.xxx:8332
user:password
ip address เครื่องที่ติตตั้ง bitcoin core port: 8332 rpcuser=username ของคุณเอง rpcpassword=password ของคุณเอง
> วิธีตรวจสอบ ip เครื่อง พิมพ์ ip a และสั่งเกต eth0 จะมีคำว่า inet 192.168.x.xxx/24
## เชื่อมต่อ wallet แบบใช้ Tor
ต้องหา tor address ที่เราตั้งค่าไว้ก่อนโดยใช้คำสั่งนี้
sudo cat /var/lib/tor/bitcoin/bitcoinrpc/hostname
output
address.onion
address.onion:8332
user:password
address.onion port: 8332 rpcuser=username ของคุณเอง rpcpassword=password ของคุณเอง
เป็นไงกันบ้างครับไม่น่ายากจนเกินไปใช่ไหมหวังว่าจะทำตามกันได้
วิธีติดตั้งเองทั้งหมดนั้นทำให้เราเลือกเวอร์ชันที่จะลงเองได้ปรับแต่งได้เยอะกว่าตามความต้องการในบทความนี้ตั้งค่าแค่พื้นฐานให้ Tor และเชื่อมต่อ wallet ได้
จุดไหนผิดพลาดช่วยเสริมได้ครับ
> ไว้เจอกันใหม่ในบทความหน้า ขอบคุณทุกคนที่อ่านมาถึงตรงนี้
บ๊ะบาย
#Siamstr #RightTech