{"id":64,"date":"2021-11-29T02:46:48","date_gmt":"2021-11-29T02:46:48","guid":{"rendered":"http:\/\/blog.scottlaboe.com\/?p=64"},"modified":"2021-11-29T03:09:13","modified_gmt":"2021-11-29T03:09:13","slug":"setting-up-rasberry-pi-server","status":"publish","type":"post","link":"https:\/\/blog.scottlaboe.com\/?p=64","title":{"rendered":"Setting Up Rasberry Pi Server"},"content":{"rendered":"\n<p>I&#8217;ve just finished migrating all of my websites from AWS Lightsail to a Raspberry Pi I have running on my home network. This includes this WordPress blog, an OpenProjects instance, and my static portfolio website. The process was fairly straightforward, but I want to write a post to consolidate the process and highlight some problems I ran into. I know very little about networking so this was a good introductory project that allowed me to learn some of the tools available for web hosting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hardware<\/h2>\n\n\n\n<p>I am using a Raspberry Pi 4 compute module Lite with 8GB of RAM loaded on the official IO Board. I decided to use the Raspberry Pi to host my site due to the low volume of traffic between my sites and the low cost of the hardware. It doesn&#8217;t have any onboard flash but it does have a port for a single lane PCIe which I used to connect a 250GB Samsung 970 EVO Plus through <a rel=\"noreferrer noopener\" href=\"https:\/\/www.amazon.com\/Profile-PCI-M-Key-Express-Adapter\/dp\/B07R9VB35J\" target=\"_blank\">this<\/a> Xiwai Low Profile PCI-E 3.0 x1 Lane to M.2 adapter. I am using a 12V 1.5A Globtec power supply to power the entire setup through the IO board which contains all the necessary regulators for the PCIe port and compute module. I used 12V over 5V to ensure I would have enough headroom for the PCIe port regulator. The device is networked through a gigabit switch that I have connected to my AX3000 router. On the compute module I am running Raspbian GNU\/Linux 11 (Bullseye) with kernel: Linux 5.10.63-v7l+. I do not have a static IP and rely on my ISP to dynamically provide me with an address via their DHCP server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methodology<\/h2>\n\n\n\n<p>I need to set the address of the compute module to a static value in the LAN. Once I have a static LAN address I can set rules on my router to forward the necessary web port (port 80 in this case) to only allow WAN traffic through that port. I can then forward my public IP to the DNS server that was configured when I purchased my domain. I will need to update the records on the DNS server whenever my ISP provides me with a new public IP such as when the power on my modem is cycled.<\/p>\n\n\n\n<p>Once I have the networking configured I will need to set up the OpenProject web app, the WordPress CMS, and my static website. Since I only have one public IP address I will need to associate different site requests with their respective directories on the Pi server. Because I am porting my existing WordPress blog, I will need to export the old blog and database and import it into the new server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PCIe SSD Configuration<\/h2>\n\n\n\n<p>I needed to load the Raspian OS onto the M.2 SSD and configure the Pi bootloader to use the PCIe port as a boot source. With the SSD inserted into the PCIe slot, I installed the Raspian OS to an SD card with the Raspberry Pi Imager and inserted it into the IO Board. After booting from the SD Card I copied the installation from the SD Card to the SSD with the <a href=\"https:\/\/github.com\/billw2\/rpi-clone\" target=\"_blank\" rel=\"noreferrer noopener\">rpi-clone<\/a> tool. I had a Raspberry Pi 400 on hand so I booted that up and installed the <a href=\"https:\/\/github.com\/raspberrypi\/usbboot\" target=\"_blank\" rel=\"noreferrer noopener\">usbboot<\/a> tool onto it. I connected the IO Board with the compute module to the Raspberry Pi 400 with a micro USB cable and updated the EEPROM on the compute module to add the PCIe as a boot source.<\/p>\n\n\n\n<p>The instructions to install usbboot and update the bootloader configuration for the CM4 can be found <a rel=\"noreferrer noopener\" href=\"https:\/\/www.raspberrypi.com\/documentation\/computers\/compute-module.html#cm4bootloader\" target=\"_blank\">here<\/a>. To understand which value to set for the BOOT_ORDER variable you can look <a rel=\"noreferrer noopener\" href=\"https:\/\/www.raspberrypi.com\/documentation\/computers\/raspberry-pi.html#BOOT_ORDER\" target=\"_blank\">h<\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/www.raspberrypi.com\/documentation\/computers\/raspberry-pi.html#raspberry-pi-4-bootloader-configuration\" target=\"_blank\">ere<\/a>. After completing these steps I removed the SD card and the compute module booted properly from the SSD.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Network Configuration<\/h2>\n\n\n\n<p>I first configured my router to reserve an arbitrary unassigned address (192.168.0.100) that I chose within the subnet range that my router was configured to provide through its DHCP server. The router reserves the address (192.168.0.100) for a specific device by associating it with the device&#8217;s MAC address, which was the MAC address of the Pi in this circumstance. I don&#8217;t believe it&#8217;s necessary, but I also configured the Pi to use the same static address by adding the address to the &#8220;\/etc\/dhcpcd.conf&#8221; file with the following lines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Static IP Configuration\ninterface eth0\nstatic ip_address=192.168.0.100\/24\nstatic ip6_address=fd51:42f8:caae:d92e:ff\/64\nstatic routers=192.168.0.1\nstatic domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e\n<\/code><\/pre>\n\n\n\n<p>The DNS server for my domain is hosted on AWS&#8217; Route 53 which I dynamically update with the correct public IP address through a script I run periodically with crontab using the AWS CLI. The script I used for this is available <a href=\"https:\/\/gist.github.com\/anthonyheddings\/f22967967bbf524ed510c356678b2651\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. I couldn&#8217;t get the precompiled binary for the AWS CLI to work so I just downloaded the source from <a href=\"https:\/\/github.com\/aws\/aws-cli\/tree\/v2\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> and built it on the Pi. Make sure the python version you are using is the recommended version to build the AWS CLI. I initially built it with Python 3.10.0 but was getting strange errors that didn&#8217;t obviously indicate the problem was my Python version. I would recommend you use something like pyenv to install the correct version of Python recommended on the AWS CLI GitHub page.<\/p>\n\n\n\n<p>I use <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/pyenv\/pyenv\" target=\"_blank\">pyenv<\/a> to manage different versions of python so my default installation location for the AWS CLI executable was &#8220;\/home\/pi\/.pyenv\/shims\/aws&#8221;. To find the installation on your system you can run &#8220;which aws&#8221;. I updated the calls in the script to reference the location directly and replaced the first two variables with parameters so I could update the records for multiple sites and hosted zones more easily. The two variables I take as parameters defined in the script look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Variable Declaration\nHOSTED_ZONE_ID=$1\nNAME=$2\n<\/code><\/pre>\n\n\n\n<p>All of my Route 53 CLI calls were changed from:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws route53<\/code><\/pre>\n\n\n\n<p>to the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/pi\/.pyenv\/shims\/aws route53<\/code><\/pre>\n\n\n\n<p>The reason for adding absolute paths to the script is because when crontab executes the script, it doesn&#8217;t have the environment variable containing the AWS executable. More detailed instructions on how to configure and use the script are <a href=\"https:\/\/www.cloudsavvyit.com\/3103\/how-to-roll-your-own-dynamic-dns-with-aws-route-53\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>To add calls to the script in crontab so the public IP is checked and updated if needed every minute I added the following call using &#8220;crontab -e&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * * * \/home\/pi\/scripts\/update_dns.sh \"REPLACE_WITH_HOST_ID\" \"openproject.scottlaboe.com.\" &gt;\/var\/log\/update_dns.log 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<p>I added three of these calls for each of my sites only changing the name parameter for each site. You can check if crontab has executed the script by calling &#8220;systemctl status cron&#8221;. It will show a timestamp to indicate when the script was called. You can call the script with sudo if you need to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next Post<\/h2>\n\n\n\n<p>After setting up the basic structure for the network I began working on installing the OpenProject app, WordPress CMS, and static website. In my next post, I will go into the details for installing these on the Pi.<\/p>\n\n\n<div class=\"taxonomy-post_tag wp-block-post-terms\"><a href=\"https:\/\/blog.scottlaboe.com\/?tag=boot-from-pcie\" rel=\"tag\">boot from pcie<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=cm4\" rel=\"tag\">CM4<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=compute-module-4\" rel=\"tag\">compute module 4<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=configure\" rel=\"tag\">configure<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=openprojects\" rel=\"tag\">openprojects<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=raspberry-pi\" rel=\"tag\">Raspberry Pi<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=server\" rel=\"tag\">server<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=static-site\" rel=\"tag\">static site<\/a><span class=\"wp-block-post-terms__separator\">, <\/span><a href=\"https:\/\/blog.scottlaboe.com\/?tag=wordpress\" rel=\"tag\">wordpress<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just finished migrating all of my websites from AWS Lightsail to a Raspberry Pi I have running on my home network. This includes this WordPress blog, an OpenProjects instance, and my static portfolio website. The process was fairly straightforward, but I want to write a post to consolidate the process and highlight some problems&hellip; <a class=\"more-link\" href=\"https:\/\/blog.scottlaboe.com\/?p=64\">Continue reading <span class=\"screen-reader-text\">Setting Up Rasberry Pi Server<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20,13,14,15,17,12,16,18,19],"_links":{"self":[{"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/posts\/64"}],"collection":[{"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64"}],"version-history":[{"count":3,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.scottlaboe.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}