home..

Vps

academy vps

Prepare a virtual private server (VPS)

This guide is written for setting up a VPS with Lunanode, a solid hosting provider based in Toronto, Ontario. I recommend them partly because I’ve been running a Lightning node there for several years, and partly because they accept Lightning payments directly into their own node. For the purpose of running a Lightning Node, you may choose any other provider, given they can give you full ssh access to a Linux instance.

Other popular providers that accept Lightning are Namecheap, Cherryservers, Hostinger or Bitlaunch (reselling Digital Ocean).

Create an account

First, you will need to create an account. You’ll be asked for an email address, password and a country. They will later require a phone number for verification, so if you are using a service like SMS4SATS, plan ahead!

Your security is important: If you signed up with a phone number that isn’t yours, make sure this phone number isn’t automatically added to your account for recovery purposes. Under Account in the top panel, you can opt into two-factor authentication. I recommend “time-based one-time password”.

Deposit funds into your account

We will have to deposit some funds into our account. Under Billing in the top panel we can make a lump-sum payment into our account. Try adding US$5 via BTCPay (Lightning) if you already have a mobile Lightning wallet.

SSH access

In this step, we are going to get ready to access our server from our personal computer via SSH. To do that, we are going to first create an SSH key. We recommend you creating a new SSH key, in case you will later need to revoke it or exchange it.

Create an SSH key on your personal machine

In Mac OS X, Windows or Linux we are going to open a terminal for the first time and execute the following.

ssh-keygen

Windows:

Linux, Mac OS X:

We are typically asked for a name for this key, for example nodekey_rsa. You may optionally choose a passphrase for this key, meaning you will have to enter this passphrase everytime you log into your machine. Your public key will be called newkey_rsa.pub and it will be saved in the following location:

Linux: ~/.ssh/newkey_rsa.pub Mac OS: /Users/MYUSERNAME/.ssh/newkey_rsa.pub

In our Lunanode account, under Account, we can find the option SSH Keys. We can add our SSH key there. Give it a name (ideally the name of the computer that belongs to this key), paste your public key into the appropriate field and add it.

You can add multiple SSH keys here, for example if you want to access your server both from your desktop and laptop computer. Just repeat the steps above and add the two keys seperately into your Lunanode account. Be careful to only add the public keys: they end with .pub.

Provision your first VPS

Under Virtual Machines on the left panel, we are going to Create a new virtual machine. At the moment, there is only one region to choose from, so we’ll place our node in Ontario.

In the next step we’ll first give it a hostname. If you plan to point a domain name at your server, then that would make for a good hostname. Otherwise, anything descriptive will do, such as node or lnd.

The most difficult decision is what server we want to provision. The “memory optimized” servers tend to be a good choice, as a bitcoin and Lightning node consume disproportionately more RAM than CPU power. And for the CPU-intensive syncronization process we can choose to pay for acceleration later.

The m.2 instance is probably a good minimum for a Lightning node. I personally run a BTCPay Server (including a Lightning node), a Lightning node (including LNbits) and a testnet Lightning node (including LNBits) each on an m.2 instance without performance issues, but a performing routing node with dozens of channels would well benefit from something beefier, such as the m.4 or m.8, but that performance comes at a price.

Next, we are going to choose the operating system. Ubuntu 22.04 64-bit is what we are going to choose, but Debian 11 64-bit is very similar and will work just as well. Another popular option for professionally run nodes is CentOS 8 64-bit. It’s important we are choosing an 64-bit operating system, or else we might crash our node once it’s channel.db reaches 2GB or more.

Finally we will select our SSH key or keys and provision our VPS by clicking on Create virtual machine.

Connect to your node over SSH

Under Virtual machines we should now see our VPS. After a minute or two, the yellow box should turn green, meaning our VPS is ready. We can see its External IP, as well as its IPv6. We can use either of them to connect to our node from our personal computer.

On our personal computer, we are going to open a terminal and type

ssh ubuntu@<our node's ip address>

For example

ssh ubuntu@172.81.181.220

If you are running into errors, you may have to specify the location and name of the SSH key you want to use:

ssh -i ~/.ssh/id_rsa <username>@<ip address>

As this is our first time connecting to our node, we are prompted with the message The authenticity of the host can’t be established. We will continue to connect by typing yes, but the next time we see that message we should be suspicious. This principle is called “Trust on First Use” or Tofu.

The terminal should read:

Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-25-generic x86_64)

We have successfully provisioned our server!

Attach a volume

Our server comes with some space on an SSD, but we might want to have more, especially for the Bitcoin blockchain. Luckily, we can buy additional space and attach it to our server.

Create the volume

First, we will power off our node. We are going to do that through the Lunanode dashboard. Under Virtual Machines we will select Manage, then Shut Down. We can verify that it is shut down by its status changing to Offline.

On the left of the screen, we find the option Volumes. We select our region (Toronto), give it a name (for example bitcoin) and decide on a size. For a Bitcoin node that is used as a backend to our node, 50GB is a good size for a small node. That’s about 24 weeks worth of blocks. For a more performant node, 80GB or even 120GB might be a decent choice too. The entire blockchain takes up about 600GB today, and growing by about 2GB per week, so running a full archival node on a VPS might not be economical, as Lunanode will charge us US$36 per month for a 600GB large SSD.

We will leave the volume empty (Source) and create it.

The volume should appear instantly in our volume list. We will click on Manage and then Attach to VM where we select our node under Virtual Machine and virtio as a driver. This won’t work if our server isn’t shut down. Only once our volume reads Attached to our node we can go back into Virtual Machines, then Manage, then Start Up our node. Once we can see Status changed to Online we can log back into our node with SSH.

Format the volume

We will log back into our node via SSH from our personal computer.

We can execute the following command to check if our volume is successfully attached:

lsblk

Typically, we will find it at the very bottom labelled vdc. The main storage partition of our server is likely called vda. You should be able to see their sizes too.

Next, we are going to format this SSD. We type and execute:

sudo mkfs.ext4 /dev/vdc

Depending on the size of your volume, this can be very fast or take a minute.

Now, we are going to permanently mount this volume. First we are going to create a directory called bitcoin.

sudo mkdir /mnt/bitcoin

Next, we are going to mount the drive at this directory.

sudo mount /dev/vdc /mnt/bitcoin

We can see a list of all mounted volumes with the df utility.

df -h

Finally, we are going to give permission over this new volume back to the user ubuntu, as it is initially owned by the root user.

sudo chown ubuntu:ubuntu /mnt/bitcoin

To make sure our server automatically mounts this volume when we start it, we are going to have to edit some configuration files.

First, we will find out the UUID of our SSD by running the following. If we can’t see our drive, we have to reboot the machine with sudo reboot now, then reconnect via SSH:

blkid

Typically, the first line corresponds to your main disk, while the second and subsequent lines correspond to your external disks. We will also check that the beginning of the line starts with the correct file system, in the above case /dev/vdc. A typical UUID looks like this: 50fb9f4-60e7-4024-adde-2a9959214dd6.

Next, we are going to open the nano editor and edit the fstab file:

sudo nano /etc/fstab

We are going to paste (right-click and paste or if your computer/mouse has one, the middle button) the following line:

UUID=<your SSD's UUID> <your mount path> ext4 defaults 0 0

For example:

UUID=050fb9f4-60e7-4024-adde-2a9959214dd6 /mnt/bitcoin ext4 defaults 0 0

Now are going to save the file with Ctrl + O and exit the editor with Ctrl + X.

We are going to test our configuration by mounting all the volumes.

sudo mount -a

If this succeeds without error, we can optionally reboot our server.

sudo reboot now

We will have to wait a minute for our server to reboot before we can log back in with SSH.

df -h

We should see something like the following.

Filesystem      Size  Used Avail Use% Mounted on
tmpfs            98M  996K   97M   2% /run
/dev/vda1        16G  2.0G   14G  13% /
tmpfs           486M     0  486M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/vdc        4.9G   24K   50G   0% /mnt/bitcoin
/dev/vda15      105M  5.3M  100M   5% /boot/efi
tmpfs            98M  4.0K   98M   1% /run/user/1000

You have successfully set up your VPS and attached a volume. Congratulations!

© 2024 Vancouver Bitcoiners   •  Powered by Bitdevs Vancouver   •   Theme  Moonwalk