Install lightning on Raspberry Pi
This time I went and tried c-lightning instead of lnd. Let’s see how it goes.
After successfully running Bitcoin using the below tutorial
It is time to download Core Lightning binaries from the official repo, at the time of this writing the below was the latest.
cd onto the directory you want to download and run the following commands
$ https://github.com/ElementsProject/lightning/releases/download/v23.08/clightning-v23.08.zip
$ wget -O SHA256SUMS.cln https://github.com/ElementsProject/lightning/releases/download/v23.08/SHA256SUMS
Verify with the following command
$ sha256sum --ignore-missing --check SHA256SUMS.cln
# clightning-v23.08.zip: OK
uncompress with
$ unzip clightning-v23.08.zip
You got the source, but before you start building, let’s start installing some dependencies:
sudo apt install autoconf automake build-essential git libtool libsqlite3-dev python3 python3-pip net-tools zlib1g-dev libsodium-dev gettext --yes
Now install some Python dependencies
pip3 install --upgrade pip
pip3 install --user poetry
pip3 install --user grpcio-tools
Install rust dependencies to build the rust
plugins
$ sudo apt install protobuf-compiler --yes
# download and install rust
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# load onto $PATH
$ source "$HOME/.cargo/env"
Now let CD into the clightning source code
$ cd clightning-v23.08
Let’s get building!
$ pip3 install mako
$ pip3 install -r plugins/clnrest/requirements.txt
$ ./configure
$ make
$ sudo make install
And you now have built c-lightning on your Raspberry Pi 🎉
Create a non-root user for running lightning
Create a new user called lightning
following these steps and add it to the debian-tor
group
$ sudo usermod -a -G debian-tor lightning
Create a directory outside the SDCard to lower the activity on the SDCard for the lightning data dir
$ sudo mkdir /mnt/sda/lightning
$ sudo chown lightning:lightning /mnt/sda/lightning
$ sudo ln -s /mnt/sda/lightning /home/lightning/.lightning
$ sudo chown -R lightning:lightning /home/lightning/.lightning
Switch to the lightning user
$ sudo -su lightning
$ cd ~
Download the sample lightning config file, and open it
$ wget -O ~/.lightning/config https://raw.githubusercontent.com/ElementsProject/lightning/master/contrib/config-example
$ vi .lightning/config
Edit the following lines
## Give your node a name
alias=YOUR_ALIAS
## Pick your favorite color as a hex code
rgb=FFA500
## Set the network for Core Lightning to sync to, Bitcoin Mainnet for most users
## Not required if the config file is in a network directory
network=bitcoin
## Log output to specified file instead of the terminal
## Required for `daemon`
log-file=/home/lightning/.lightning/log
## Set to debug for more verbose log output
#log-level=info
## Run `lightningd` as a background daemon instead of in the terminal
## Requires `log-file` path
daemon
# Set JSON-RPC socket (or /dev/tty), such as for lightning-cli(1).
rpc-file=/home/lightning/.lightning/lightning-rpc
# Set JSON-RPC socket file mode, as a 4-digit octal number.
# Default is 0600, meaning only the user that launched lightningd
# can command it.
# Set to 0660 to allow users with the same group to access the RPC
# as well.
rpc-file-mode=0666
## Bind Core Lightning RPC server to localhost PORT 9734
bind-addr=127.0.0.1:9734
## Configure proxy/tor for OUTBOUND connections.
proxy=127.0.0.1:9050
## INBOUND connections - default PORT 9735
## 0.0.0.0 for clearnet | localhost+torhiddenservice for tor
addr=statictor:127.0.0.1:9051
## Force all outbound connections through the proxy/tor
always-use-proxy=true
## Load your plugins from a directory
plugin-dir=/home/lightning/.lightning/plugins
Because my drive isn’t encrypted, I enabled encryption by adding encrypted-hsm
to the config file
## Password encrypt your `hsm_secret`
## You must supply the password on startup if you choose to do this
encrypted-hsm
run lightning
$ lightningd
If you added encrypted-hsm
, it will ask for a password and then it will be sent to the background.
Read the logs to make sure everything looks good with the following command:
$ tail -f ~/.lightning/log
You can also get the public onion address and the public key from the log, or by running lightning-cli getinfo
.
Backup the hsm_secret
file to recover on-chain funds, and the lightningd.sqlite3
file to recover channel funds by reading the official site recommendations, if you have any questions feel free to ask.
Things that I did:
- Use two USB drives to store the sqlite database in realtime using
wallet=sqlite3:///path/to/lightningd.sqlite3:/path/to/backup/lightningd.sqlite3
in ~/.lightning/config - Create a new
hsm_secret
from a backed-up Bip39 mnemonic code
Install RTL as a front-end to manage your lightning node, on-chain operations, and the lightning channels
And that’s it, happy bitcoining!