1. 程式人生 > 其它 >ubuntu20.04 搭建門羅幣節點

ubuntu20.04 搭建門羅幣節點

第一步更新:
sudo apt update && sudo apt-get upgrade
第二步安裝git:
sudo apt install git 如果已安裝git請跳過
第三步安裝依賴:
sudo apt install build-essential cmake doxygen graphviz miniupnpc pkg-config libboost-all-dev libcurl4-openssl-dev libgtest-dev libminiupnpc-dev libreadline-dev libssl-dev libunbound-dev libunwind8-dev libzmq3-dev libzmq3-dev libpgm-dev libsodium-dev
如果在安裝依賴時發生錯誤,參考:
https://blog.csdn.net/otter1010/article/details/105431417
https://blog.csdn.net/u010426270/article/details/52028620

第四步: libgtest-dev 在 Ubuntu 上不是二進位制的,所以你必須編譯

cd /usr/src/gtest 
sudo cmake . 
sudo make -j2
sudo mv libg* /usr/lib/
第五步,克隆github上的門羅幣原始碼,這個看網路情況,網不好會git clone 以及make可能會失敗: 
cd ~
git clone --recursive https://github.com/monero-project/monero
cd monero
make -j2 release # -j4 for 4 threads etc
第六步: 把編譯後的檔案拷貝:
sudo cp build/Linux/master/release/bin/* /usr/local/bin/
設定防火牆:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh

sudo ufw allow 22
sudo ufw allow 18080 
sudo ufw allow 18081 
sudo ufw allow 18082 
 
sudo ufw enable
第七步: set up service: 
cd /lib/systemd/system
sudo wget https://gist.githubusercontent.com/mariodian/b8bb62de8f5aa5466cccb17f280f439e/raw/db0a98573e0a8cc871781d8d43f03437ca159e22/monerod.service
sudo chmod 644 monerod.service
修改一下monerod.service檔案內容, 如果報"monerod.service: Changing to the requested working directory failed: Permiss"錯誤,修改一下root/monero資料夾的許可權: 
[Unit]
Description=Monero Full Node
After=network.target

[Service]
User=xsk
Group=xsk
WorkingDirectory=~
RuntimeDirectory=monero

# Clearnet config
#
Type=forking
PIDFile=/run/monero/monerod.pid
ExecStart=/usr/local/bin/monerod --restricted-rpc --block-sync-size 3 --confirm-external-bind --config-file /root/.bitmonero/monerod.conf \
    --detach --pidfile /run/monero/monerod.pid

# Tor config
#
## We have to use simple, not forking, because we cannot pass --detach
## because stderr/stdout is not available when detached, but torsocks
## attempts to write to it, and fails with 'invalid argument', causing
## monerod to fail.
#Type=simple
#Environment=DNS_PUBLIC=tcp
## The following is needed only when accessing wallet from a different
## host in the LAN, VPN, etc, the RPC must bind to 0.0.0.0, but
## by default torsocks only allows binding to localhost.
#Environment=TORSOCKS_ALLOW_INBOUND=1
#ExecStart=/usr/bin/torsocks /usr/bin/monerod --config-file /etc/monerod.conf \
#    --non-interactive

Restart=always

[Install]
WantedBy=multi-user.target
第八步Next, create a config file:
mkdir ~/.bitmonero
cd ~/.bitmonero
touch monerod.conf
第九步命令列輸入:
echo "data-dir=/home/satoshi/.bitmonero" >> monerod.conf
echo "log-file=/home/satoshi/.bitmonero/monero.log" >> monerod.conf
echo "log-level=0" >> monerod.conf
如果要連線rpc遠端節點,做一下設定,使用者名稱和密碼自己修改
echo "rpc-bind-ip=0.0.0.0" >> monerod.conf
echo "rpc-bind-port=18081" >> monerod.conf
echo "rpc-login=testUser:testPassword" >> monerod.conf
第十步Run the service, Enable the systemd config and start the daemon:
sudo systemctl enable monerod
sudo service monerod start
檢視門羅幣日誌:
tail -f monero.log
或者 using a simpler output:
monerod --config-file /home/satoshi/.bitmonero/monerod.conf status
第十一步, 設定Allow incoming connections :
For the P2P connection run this command:
sudo iptables -I INPUT -p tcp --dport 18080 -j ACCEPT

For the RPC:
sudo iptables -I INPUT -p tcp --dport 18081 -j ACCEPT
儲存設定Save the rules permanently:
sudo iptables-save

連線自己的錢包,下載monero-wallet-gui錢包的視覺化介面: 
https://www.getmonero.org/downloads/