ROCKPro64 System, Part 3
In this post I detail the steps needed to enable fan control, install electrs Electrum personal server, and install and configure nginx to provide an SSL proxy for the electrs server, to make it easy to use with the Electrum client software.
-
enable the case fan using Active Thermal Service, follow github instruction
-
install c language and git (if not already installed)
sudo apt install clang git
-
install rust tools per rust-lang.org/tools/install instructions
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env
-
clone and build the electrs project
git clone https://github.com/romanz/electrs.git cd electrs cargo build --release
-
add a new
electrs
system user and make it part of bitcoin groupsudo adduser --system --home /var/lib/electrs --ingroup bitcoin electrs
-
create a new LVM logical volume for electrs data, I allocate 40% of bitcoin volume size which is needed during indexing, but can lowered later after the indexes are compacted if I need the space back.
sudo lvcreate -n electrs -L 200g rockpro64
-
format my new electrs logical volume, identify it's UUID and mount it via fstab
sudo mkfs.ext4 /dev/rockpro64/electrs sudo blkid sudo vi /etc/fstab
add line to /etc/fstab:
UUID=<THE UUID OF MY NEW LOGICAL PARTITION> /var/lib/electrs ext4 errors=remount-ro 0 1
sudo mount -a sudo chown electrs:bitcoin /var/lib/electrs sudo chmod -R o-rwx /var/lib/electrs sudo chmod u+rxw /var/lib/electrs sudo chmod g+x /var/lib/electrs
-
copy electrs binary to /var/lib/electrs
sudo mkdir /var/lib/electrs/bin sudo chown electrs:bitcoin /var/lib/electrs/bin sudo cp target/release/electrs /var/lib/electrs/bin sudo chown electrs:bitcoin /var/lib/electrs/bin/electrs
-
create systemd startup file for electrs
sudo vi /usr/lib/systemd/system/electrs.service
and add below content to file
[Unit] Description=Electrs After=bitcoind.service [Service] WorkingDirectory=/var/lib/electrs ExecStart=/var/lib/electrs/bin/electrs -vvv --db-dir ./db --index-batch-size=10 --jsonrpc-import --cookie-file /var/lib/bitcoind/.cookie --daemon-dir /var/lib/bitcoind --electrum-rpc-addr="127.0.0.1:50001" User=electrs Group=bitcoin Type=simple KillMode=process TimeoutSec=60 Restart=always RestartSec=60 [Install] WantedBy=multi-user.target
-
edit the bitcoind service to enable the rpc server, restart bitcoind
sudo vi /usr/lib/systemd/system/bitcoind.service
add
-server=1
to the ExecStart linesudo systemctl daemon-reload sudo systemctl restart bitcoind
-
update the permission for bitcoind .cookie file so electrs can use it to connect to the bitcoind rpc api
sudo chmod -R g+r /var/lib/bitcoind/ sudo chmod g+x /var/lib/bitcoind sudo chmod g+x /var/lib/bitcoind/blocks /var/lib/bitcoind/chainstate /var/lib/bitcoind/database
-
create /run/electrs directory, reload systemd services and start the electrs daemon
sudo mkdir /run/electrs sudo chown electrs:bitcoin /run/electrs sudo systemctl daemon-reload sudo syste:qqmctl start electrs
At this point electrs will start indexing, this took almost 24 hours on my system.
-
install nginx
sudo apt install nginx
-
create a new nginx cert
sudo mkdir /etc/nginx/ssl sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
-
add the below block to the nginx config file
sudo vi /etc/nginx/nginx.conf
stream { upstream electrs { server 127.0.0.1:50001; } server { listen 50002 ssl; proxy_pass electrs; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 4h; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; } }
-
unlink the nginx default site in the sites-active directory and restart nginx
sudo rm /etc/nginx/sites-enabled/default sudo systemctl restart nginx
Done! I now have an electrum server at https://localhost:50001 that I can use as a back end to an electrum client, or any other service that uses the electrum server apis to browse the bitcoin block chain.