systemd를 사용하는 시스템에서는 Geth를 서비스로 설정하여 실행할 수 있습니다. 이 방법이 가장 안정적이고 관리하기 쉽습니다.
a. /etc/systemd/system/geth.service 파일을 생성합니다.(최소 용량을 위해 snap syncmode로 진행)
sudo vi /etc/systemd/system/geth.service
[Unit]
Description=Ethereum go client
After=network.target
Wants=network.target
[Service]
User=ethereum
Group=ethereum
WorkingDirectory=/home/ethereum
ExecStart=/usr/bin/geth --datadir /var/lib/ethereum \
--authrpc.addr localhost \
--authrpc.port 8551 \
--authrpc.vhosts localhost \
--authrpc.jwtsecret /var/lib/ethereum/geth/jwtsecret \
--http \
--http.api eth,net,engine,admin \
--http.corsdomain "*" \
--syncmode snap
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target
b. /etc/systemd/system/prysm.service 파일을 생성합니다.
sudo vi /etc/systemd/system/prysm.service
[Unit]
Description=Prysm Ethereum 2.0 beacon chain
After=network.target geth.service
Wants=network.target geth.service
[Service]
User=ethereum
Group=ethereum
WorkingDirectory=/home/ethereum
ExecStart=/var/lib/ethereum/prysm.sh beacon-chain \
--execution-endpoint=http://localhost:8551 \
--mainnet \
--jwt-secret=/var/lib/ethereum/geth/jwtsecret \
--checkpoint-sync-url=https://beaconstate.info \
--genesis-beacon-api-url=https://beaconstate.info
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target
c. 유저생성(없을시)
# 유저생성
# -r: 이 옵션은 시스템 계정(system account)을 생성한다는 의미입니다. 시스템 계정은 일반적으로 서비스를 실행하기 위해 사용되며, 일반 사용자 계정과는 몇 가지 차이가 있습니다:
# -s : 이 옵션은 사용자의 로그인 셸을 지정합니다.
sudo useradd -r -s /bin/bash ethereum
또는
sudo useradd -r -s /sbin/nologin ethereum
# /sbin/nologin 유저의 경우 쉘로 접근할 수 없기 때문에 /bin/bash로 실제 명령이 잘 수행되는지 테스트 한 뒤 생성을 권장.
sudo mkdir -p /home/ethereum
sudo chown ethereum:ethereum /home/ethereum
# 디렉토리 소유권한 변경
sudo chown -R ethereum:ethereum /var/lib/ethereum
# 권한 변경(권한755시 권한오류가 발생)
sudo chmod -R 777 /var/lib/ethereum
sudo chmod 755 /usr/bin/geth
d. 서비스를 시작합니다:
# 새로운 서비스 등록
sudo systemctl daemon-reload
# 서비스 시작
sudo systemctl start geth
sudo systemctl start prysm
# 부팅시 자동시작 활성화
sudo systemctl enable geth
sudo systemctl enable prysm
e. 실시간 로그확인
sudo journalctl -f -u geth.service
sudo journalctl -f -u prysm.service
이 방법을 사용하면 시스템 재부팅 시에도 자동으로 Geth,Prysm이 시작되며, 로그 관리와 모니터링이 더 쉬워집니다.