<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>postgresql on Daan Geijs</title>
    <link>https://www.daangeijs.nl/tags/postgresql/</link>
    <description>Recent content in postgresql on Daan Geijs</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 22 Aug 2023 12:48:00 +0100</lastBuildDate><atom:link href="https://www.daangeijs.nl/tags/postgresql/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Website Analytics with Umami, Netlify and a self-hosted database. </title>
      <link>https://www.daangeijs.nl/posts/umami-netlify/</link>
      <pubDate>Tue, 22 Aug 2023 12:48:00 +0100</pubDate>
      
      <guid>https://www.daangeijs.nl/posts/umami-netlify/</guid>
      <description>Umami is a sleek, open-source analytics tool that provides an alternative to mainstream solutions like Google Analytics. Its simplicity and transparency make it a preferred choice for those wary of the intricacies and potential privacy concerns associated with bigger platforms.</description>
      <content:encoded><![CDATA[<p><figure>
    <img loading="lazy" src="cover.jpg"/> 
</figure>

Umami is a sleek, open-source analytics tool that provides an alternative to mainstream solutions like Google Analytics. Its simplicity and transparency make it a preferred choice for those wary of the intricacies and potential privacy concerns associated with bigger platforms.</p>
<p>In this case I like having autonomy and control of hosting my own data, but I also appreciate the efficiency and scalability of cloud services. That&rsquo;s why, I&rsquo;ve opted to host the database needed for Umami at home on my homeserver using Proxmox.  However, when it comes to the dashboard – the visual heart of Umami – I use Netlify. Hosting the Umami dashboard on Netlify not only offloads my trusty NUC from running yet another service but also made installation a breeze with Netlify&rsquo;s effortless deployment process. In this article I will show you how I set it up.</p>
<h2 id="setting-up-database-on-proxmox">Setting Up Database on Proxmox</h2>
<ol>
<li>
<p><strong>Download CT Template</strong>: Begin by obtaining the <code>turnkey-postgresql</code> CT template. The easiest way to do this is to download the template from the Proxmox web interface. Navigate to &ldquo;Templates&rdquo; -&gt; &ldquo;Download&rdquo; and search for &ldquo;turnkey-postgresql&rdquo;. Select the template and click &ldquo;Download&rdquo;.</p>
</li>
<li>
<p><strong>Create a LXC container</strong>:
<figure>
    <img loading="lazy" src="1.png"/> 
</figure>
</p>
<ul>
<li>Assign a fixed IP address (fixed to enable port forwarding).</li>
<li>Allocate 1024MB memory and 1024MB swap.</li>
<li>Dedicate 1 CPU core.</li>
<li>Designate 16GB for disk storage.</li>
<li>Ensure &ldquo;start after created&rdquo; is selected.</li>
</ul>
</li>
</ol>
<p>For me these where the resources that I had available, but you can adjust these to your own needs.</p>
<ol start="3">
<li><strong>Complete Initialization</strong>: Access the console of your started container, log in with <code>root</code> and the password you set up at the previous step. Complete the installation, skipping any unnecessary add-ons but making sure to apply the updates.
<figure>
    <img loading="lazy" src="3.png"/> 
</figure>
</li>
<li><strong>Database Setup</strong>: Navigate to the browser using assigned-static-IP-address:12322 or simply input the IP address. This will take you to a dashboard where you can select Adminer. Use Adminer to log in with PostgreSQL credentials. Create a table named <code>umami</code>.
<figure>
    <img loading="lazy" src="5.png"/> 
</figure>
</li>
<li><strong>Port forwarding</strong> Make sure you don&rsquo;t forget to enable port forwarding (5432) to the IP address of your running Postgres container. Ofcourse, this completely depends on your network setup. Keep in mind that exposing a port does come with security vulnerabilities. If you have an Ubiquiti router <a href="/posts/ubiquiti-vlan/">you can read this article</a> for more information on how to set this up in a more safe way.</li>
</ol>
<h2 id="deploying-umami-on-netlify">Deploying Umami on Netlify</h2>
<ol>
<li>
<p><strong>Fork Repository</strong>: Fork the Umami repository to your GitHub account:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl">https://github.com/umami-software/umami
</span></span></code></pre></div></li>
<li>
<p><strong>Netlify Setup</strong>:</p>
<ul>
<li>Log into Netlify.</li>
<li>Choose &ldquo;Add New Site&rdquo; -&gt; &ldquo;Import Existing Site&rdquo;.</li>
<li>Opt for &ldquo;Deploy with GitHub&rdquo;.</li>
<li>Select your forked Umami repository.</li>
</ul>
</li>
<li>
<p><strong>Environment Variable</strong>:
<figure>
    <img loading="lazy" src="6.png"/> 
</figure>
</p>
<ul>
<li>In the site settings of your new project, navigate to &ldquo;Site configuration&rdquo; -&gt; &ldquo;Environment variables&rdquo;.</li>
<li>Add the <code>DATABASE_URL</code> variable with the value:
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl">postgresql://<span class="p">&lt;</span><span class="nt">postgres_account</span><span class="p">&gt;</span>:<span class="p">&lt;</span><span class="nt">postgress_password</span><span class="p">&gt;</span>@<span class="p">&lt;</span><span class="nt">your_db_ip</span><span class="p">&gt;</span>/umami
</span></span></code></pre></div></li>
</ul>
</li>
<li>
<p><strong>Trigger Deployment</strong>:
<figure>
    <img loading="lazy" src="7.png"/> 
</figure>
</p>
<ul>
<li>In the Netlify dashboard, go to &ldquo;Deploys&rdquo;.</li>
<li>Select &ldquo;Trigger Deploy&rdquo; and choose &ldquo;Clear cache and deploy site&rdquo;.</li>
</ul>
</li>
</ol>
<p>The example here is just with Proxmox, but you can choose any popular solutions like AWS, Azure, DigitalOcean, or Heroku— provided they support PostgreSQL.  At the end you just need to update the URL in the Netlify dashboard.  Choose what&rsquo;s best for your needs.</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Setting Up an Isolated Virtual Server in a VLAN on Ubiquiti and Proxmox</title>
      <link>https://www.daangeijs.nl/posts/ubiquiti-vlan/</link>
      <pubDate>Wed, 14 Jun 2023 12:48:00 +0100</pubDate>
      
      <guid>https://www.daangeijs.nl/posts/ubiquiti-vlan/</guid>
      <description>Hosting your own services to be accessed by the public internet comes with its share of challenges, especially when exposing ports security concerns are involved. Cloud hosting providers are a good way to solve some of these problems, but can the costs can rise pretty quickly.</description>
      <content:encoded><![CDATA[<p>Hosting your own services to be accessed by the public internet comes with its share of challenges, especially when exposing ports security concerns are involved. Cloud hosting providers are a good way to solve some of these problems, but can the costs can rise pretty quickly.</p>
<p>In this article I wrote down a  step-by-step walkthrough on creating an isolated environment for hosting services, using a VLAN setup.  By using a VLAN and setting up a firewall we can isolate the virtual server from your primary private network, layering an additional shield of security to your setup. As an example we&rsquo;ll use a virtual machine (VM) hosting a database service as our primary example.</p>
<h3 id="ubiquiti-vlan-configuration">Ubiquiti VLAN Configuration</h3>
<h4 id="1-create-a-vlan">1. Create a VLAN</h4>
<ul>
<li>Log into your <strong>UniFi Controller</strong>.</li>
<li>Navigate to the &ldquo;Settings&rdquo; (gear icon) at the bottom left.</li>
<li>Under &ldquo;Networks&rdquo;, click on &ldquo;Create New Network&rdquo;.</li>
<li>Provide a name for the network, for instance, &ldquo;Public VLAN&rdquo;.</li>
<li>Set &ldquo;Purpose&rdquo; to &ldquo;Corporate&rdquo;.</li>
<li>Assign a VLAN ID of &ldquo;10&rdquo;.</li>
<li>Define the subnet as <code>10.0.0.1/24</code>.</li>
<li>Configure the DHCP range if required and save these settings.</li>
</ul>
<h4 id="2-firewall-rules-for-vlan-traffic">2. Firewall Rules for VLAN Traffic</h4>
<ul>
<li>
<p>Proceed to &ldquo;Routing &amp; Firewall&rdquo; within the settings.</p>
</li>
<li>
<p>Select &ldquo;Firewall&rdquo; and then &ldquo;LAN IN&rdquo;.</p>
</li>
<li>
<p>Set up a rule that permits only PostgreSQL traffic:</p>
<ul>
<li>Name: <strong>Allow PostgreSQL to WAN</strong></li>
<li>Action: <strong>Accept</strong></li>
<li>Source: <strong>Public VLAN</strong></li>
<li>Destination: <strong>Any</strong></li>
<li>Ports: <strong>5432</strong> (PostgreSQL&rsquo;s default port)</li>
</ul>
</li>
<li>
<p>Create rules that block all traffic from the VLAN to other local networks:</p>
<ul>
<li>Name: <strong>Block VLAN to all LANs</strong></li>
<li>Action: <strong>Drop</strong></li>
<li>Source: <strong>Public VLAN</strong></li>
<li>Destination: <strong>All other local networks/VLANs</strong></li>
</ul>
</li>
</ul>
<h4 id="3-port-forwarding">3. Port Forwarding</h4>
<ul>
<li>
<p>Navigate to &ldquo;Routing &amp; Firewall&rdquo; and select &ldquo;Port Forwarding&rdquo;.</p>
</li>
<li>
<p>Click on the &ldquo;+ Create New Rule&rdquo; or &ldquo;Add New Port Forward Rule&rdquo; button, which should open a new window or pane for rule creation.</p>
</li>
<li>
<p><strong>Name</strong>: Give the rule a descriptive name, e.g., &ldquo;PostgreSQL Remote Access&rdquo;.</p>
</li>
<li>
<p><strong>Enabled</strong>: Make sure this is toggled on.</p>
</li>
<li>
<p><strong>Rule Applied</strong>: Set to &ldquo;After Predefined Rules&rdquo;</p>
</li>
<li>
<p><strong>WAN Interface</strong>: Usually set to &ldquo;All&rdquo; unless you have multiple WANs and prefer a specific one.</p>
</li>
<li>
<p><strong>Original IP</strong>: Leave as &ldquo;Any&rdquo; to allow access from any external IP or specify a range/IP if you have a static IP where you&rsquo;ll be connecting from.</p>
</li>
<li>
<p><strong>Original Port</strong>: Set to the PostgreSQL default port, &ldquo;5432&rdquo;.</p>
</li>
<li>
<p><strong>Forward IP</strong>: Enter the IP address of the machine where PostgreSQL is running, in this case, the VM&rsquo;s IP, <code>10.0.0.2</code>.</p>
</li>
<li>
<p><strong>Forward Port</strong>: Again, set this to &ldquo;5432&rdquo;.</p>
</li>
<li>
<p><strong>Protocol</strong>: PostgreSQL typically uses TCP, so set this to &ldquo;TCP&rdquo;. If there are any reasons to believe you need both TCP and UDP, you can set it to &ldquo;Both&rdquo;, but this is usually not necessary for PostgreSQL.</p>
</li>
</ul>
<h3 id="proxmox-vm-configuration">Proxmox VM Configuration</h3>
<h4 id="1-vm-creation-or-modification">1. VM Creation or Modification</h4>
<p>Now lest assign our newly created VLAN to a VM. Either initiate a new VM or select an existing one.</p>
<ul>
<li>Access the Proxmox web interface.</li>
<li>During the setup or via the &ldquo;Network&rdquo; menu for an existing VM:
<ul>
<li>Set the <strong>Bridge</strong>, you can use your default, typically <code>vmbr0</code>.</li>
<li>Assign the <strong>VLAN Tag</strong> to &ldquo;10&rdquo;.</li>
<li>Ensure the firewall is activated.</li>
<li><strong>IPv4/CIDR</strong>: <code>10.0.0.2/32</code></li>
<li><strong>Gateway</strong>: <code>10.0.0.1</code></li>
</ul>
</li>
<li>Once the VM is started or rebooted, it should automatically acquire the assigned static IP.</li>
</ul>
<h3 id="testing-the-configuration">Testing the Configuration</h3>
<h4 id="1-verify-the-ip-address">1. Verify the IP Address</h4>
<ul>
<li>In Proxmox, access the VM&rsquo;s console.</li>
<li>Execute the <code>ifconfig</code> command to ensure that the IP address <code>10.0.0.2</code> has been correctly assigned.</li>
</ul>
<h4 id="2-test-connectivity">2. Test Connectivity</h4>
<ul>
<li>In the same console, check internet access by pinging an external website: <code>ping www.daangeijs.nl</code>.</li>
<li>Subsequently, attempt to ping a device from your private network. This ping should fail, verifying that the VM is isolated from the private network.</li>
</ul>
<p>There you go! You&rsquo;ve successfully set up a VLAN and isolated a VM within it. You can now host services on this VM and access them from the internet, while keeping your private network secure.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
