Nodes/bsc/localhost

bsc

BSC 노드 Localhost 설치 가이드

10분 읽기 · localhost

list목차(30)

BSC 노드 Localhost 설치 가이드

Ubuntu 시스템에 BSC (Binance Smart Chain) 노드를 직접 설치하고 실행하는 방법입니다.

시스템 요구사항

최소 사양

  • OS: Ubuntu 22.04 LTS 이상
  • CPU: 4코어 이상
  • RAM: 8GB 이상
  • 디스크: 2TB 이상 SSD
  • 네트워크: 안정적인 인터넷 연결 (100Mbps 이상)

권장 사양

  • OS: Ubuntu 24.04 LTS
  • CPU: 8코어 이상
  • RAM: 16GB 이상
  • 디스크: 3TB 이상 NVMe SSD
  • 네트워크: 광대역 인터넷 (500Mbps 이상)

설치 단계

1. 시스템 업데이트

sudo apt update && sudo apt upgrade -y
sudo apt install -y wget curl build-essential

2. BSC Geth 다운로드

# BSC 디렉토리 생성
sudo mkdir -p /opt/bsc
cd /opt/bsc

# 최신 BSC Geth 다운로드
BSC_VERSION="1.4.15"
sudo wget https://github.com/bnb-chain/bsc/releases/download/v${BSC_VERSION}/geth_linux
sudo mv geth_linux geth
sudo chmod +x geth

# 버전 확인
./geth version

3. 데이터 디렉토리 생성

# 데이터 저장 디렉토리 생성
sudo mkdir -p /mnt/cryptocur-data/bsc

# 사용자 생성 (보안)
sudo useradd -r -m -s /bin/bash bsc

# 권한 설정
sudo chown -R bsc:bsc /opt/bsc
sudo chown -R bsc:bsc /mnt/cryptocur-data/bsc

4. 설정 파일 생성 (선택사항)

# config.toml 생성
sudo tee /opt/bsc/config.toml > /dev/null <<EOF
[Eth]
SyncMode = "snap"
TrieTimeout = 100000000000
TrieDirtyCache = 4096
TrieCleanCache = 4096

[Node]
DataDir = "/mnt/cryptocur-data/bsc"
HTTPHost = "0.0.0.0"
HTTPPort = 8545
HTTPVirtualHosts = ["*"]
HTTPCors = ["*"]
HTTPModules = ["eth", "net", "web3", "txpool", "parlia"]

WSHost = "0.0.0.0"
WSPort = 8546
WSOrigins = ["*"]
WSModules = ["eth", "net", "web3", "txpool", "parlia"]

[Node.P2P]
MaxPeers = 50
NoDiscovery = false
ListenAddr = ":30311"
EOF

sudo chown bsc:bsc /opt/bsc/config.toml

5. Systemd 서비스 생성

# 서비스 파일 생성
sudo tee /etc/systemd/system/bsc.service > /dev/null <<EOF
[Unit]
Description=BSC (Binance Smart Chain) Node
After=network.target
Wants=network.target

[Service]
Type=simple
User=bsc
Group=bsc
ExecStart=/opt/bsc/geth \\
    --config /opt/bsc/config.toml \\
    --datadir /mnt/cryptocur-data/bsc \\
    --port 30311 \\
    --cache 4096 \\
    --maxpeers 50 \\
    --syncmode snap \\
    --rpc.allow-unprotected-txs \\
    --txlookuplimit 0 \\
    --http \\
    --http.addr "0.0.0.0" \\
    --http.port 8545 \\
    --http.vhosts "*" \\
    --http.corsdomain "*" \\
    --http.api "eth,net,web3,txpool,parlia" \\
    --ws \\
    --ws.addr "0.0.0.0" \\
    --ws.port 8546 \\
    --ws.origins "*" \\
    --ws.api "eth,net,web3,txpool,parlia" \\
    --metrics \\
    --metrics.addr "0.0.0.0" \\
    --metrics.port 6060

Restart=on-failure
RestartSec=10
LimitNOFILE=65536
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

6. 서비스 시작

# Systemd 데몬 리로드
sudo systemctl daemon-reload

# 서비스 활성화 (부팅 시 자동 시작)
sudo systemctl enable bsc

# 서비스 시작
sudo systemctl start bsc

# 서비스 상태 확인
sudo systemctl status bsc

노드 관리

로그 확인

# 실시간 로그 보기
sudo journalctl -u bsc -f

# 최근 100줄 로그
sudo journalctl -u bsc -n 100

# 오늘의 로그
sudo journalctl -u bsc --since today

노드 상태 확인

# 동기화 상태 확인
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'eth.syncing'

# 최신 블록 번호
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'eth.blockNumber'

# 피어 연결 수
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'net.peerCount'

# 체인 ID (56: mainnet, 97: testnet)
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'eth.chainId()'

서비스 제어

# 노드 중지
sudo systemctl stop bsc

# 노드 재시작
sudo systemctl restart bsc

# 서비스 비활성화
sudo systemctl disable bsc

스냅샷 사용 (빠른 동기화)

스냅샷을 사용하면 동기화 시간을 크게 단축할 수 있습니다.

스냅샷 다운로드

# 노드 중지
sudo systemctl stop bsc

# 스냅샷 다운로드 디렉토리로 이동
cd /mnt/cryptocur-data/bsc

# 최신 스냅샷 다운로드 (약 1.5TB, 시간 소요)
# URL은 https://github.com/bnb-chain/bsc-snapshots 에서 확인
sudo wget -c https://pub-60d5.bscscan.com/mainnet/geth-20240101.tar.gz

# 압축 해제
sudo tar -xzvf geth-20240101.tar.gz

# 권한 설정
sudo chown -R bsc:bsc /mnt/cryptocur-data/bsc

# 압축 파일 삭제
sudo rm geth-20240101.tar.gz

# 노드 재시작
sudo systemctl start bsc

방화벽 설정

# UFW 방화벽 설정 (Ubuntu)
sudo ufw allow 30311/tcp  # P2P
sudo ufw allow 30311/udp  # P2P
sudo ufw allow from 127.0.0.1 to any port 8545  # RPC (로컬만)
sudo ufw allow from 127.0.0.1 to any port 8546  # WS (로컬만)

RPC 사용 예제

HTTP-RPC

# 최신 블록 번호 조회
curl -H "Content-Type: application/json" \
  -X POST \
  --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
  http://localhost:8545

# 잔액 조회
curl -H "Content-Type: application/json" \
  -X POST \
  --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xYOUR_ADDRESS","latest"],"id":1}' \
  http://localhost:8545

JavaScript Console

# Geth 콘솔 접속
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc

# 또는 HTTP로 접속
/opt/bsc/geth attach http://localhost:8545

업데이트

BSC Geth 업데이트

# 노드 중지
sudo systemctl stop bsc

# 새 버전 다운로드
cd /opt/bsc
BSC_VERSION="1.4.16"  # 새 버전으로 변경
sudo wget https://github.com/bnb-chain/bsc/releases/download/v${BSC_VERSION}/geth_linux
sudo mv geth_linux geth.new

# 백업 및 교체
sudo mv geth geth.old
sudo mv geth.new geth
sudo chmod +x geth
sudo chown bsc:bsc geth

# 버전 확인
./geth version

# 노드 재시작
sudo systemctl start bsc

# 정상 작동 확인 후 구버전 삭제
sudo rm geth.old

모니터링

리소스 사용량

# CPU, 메모리 사용량
top -p $(pgrep geth)

# 디스크 사용량
df -h /mnt/cryptocur-data/bsc
du -sh /mnt/cryptocur-data/bsc/*

# 네트워크 트래픽
iftop -i eth0

동기화 진행률

# 동기화 진행 스크립트
cat > /tmp/check_sync.sh << 'EOF'
#!/bin/bash
CURRENT=$(/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'eth.blockNumber')
HIGHEST=$(/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'eth.syncing.highestBlock')
echo "Current Block: $CURRENT"
echo "Highest Block: $HIGHEST"
if [ "$HIGHEST" != "null" ]; then
  PERCENT=$(awk "BEGIN {printf \"%.2f\", ($CURRENT/$HIGHEST)*100}")
  echo "Progress: $PERCENT%"
else
  echo "Fully synced!"
fi
EOF

chmod +x /tmp/check_sync.sh
/tmp/check_sync.sh

문제 해결

동기화가 멈춘 경우

# 피어 연결 확인
/opt/bsc/geth attach /mnt/cryptocur-data/bsc/geth.ipc --exec 'net.peerCount'

# 피어가 없으면 노드 재시작
sudo systemctl restart bsc

디스크 공간 부족

# 오래된 로그 정리
sudo journalctl --vacuum-time=7d

# 트랜잭션 룩업 제한 (재시작 필요)
# config.toml에 txlookuplimit = 0 추가

메모리 부족

# cache 크기 줄이기
# systemd 서비스 파일에서 --cache 4096 을 --cache 2048 로 변경
sudo systemctl daemon-reload
sudo systemctl restart bsc

추가 리소스

bsc 다른 챕터