<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by michael on Medium]]></title>
        <description><![CDATA[Stories by michael on Medium]]></description>
        <link>https://medium.com/@michael-purba?source=rss-7984d3113a19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LICeSLte4EwK39lo</url>
            <title>Stories by michael on Medium</title>
            <link>https://medium.com/@michael-purba?source=rss-7984d3113a19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:33:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michael-purba/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cheapest  PostgreSQL Server (even all in one server for your full stack needs) + SSH hardened…]]></title>
            <link>https://medium.com/@michael-purba/cheapest-postgresql-server-even-all-in-one-server-for-your-full-stack-needs-ssh-hardened-4a2133d2c40f?source=rss-7984d3113a19------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a2133d2c40f</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[cheap-cloud-hosting]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[full-stack]]></category>
            <dc:creator><![CDATA[michael]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 08:28:08 GMT</pubDate>
            <atom:updated>2023-11-05T08:28:08.227Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cheapest PostgreSQL Server (even all in one server for your full stack needs) + SSH hardened servers. All in one full stack server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2nUfnuMQAhqE6JPT.png" /><figcaption>building your own cheap postgresql</figcaption></figure><blockquote>TLDR : we can get a postgreSQL 4 vcpu and 8GB RAM and 200GB SSD for only $5.5 per month that can also has much room left for deploying for REDIS server, rabbitmq server, mySQL server and MongoDB server or even your full stack dockerized apps</blockquote><p>As a new freelancer entering the world of web development or data management, you often find yourself juggling multiple responsibilities. Among these tasks, setting up a reliable database server is crucial, especially if you’re working with data-driven applications. PostgreSQL, an open-source relational database management system, is a popular choice for many freelancers due to its robust features and flexibility. However, when you’re just starting out, budget constraints can be a real concern. In this article, we’ll guide you on how to build the cheapest PostgreSQL server for new freelancers, ensuring a solid foundation for your projects without breaking the bank.</p><blockquote>this guide is demonstrated using a workstation in fedora, ubuntu will also work</blockquote><p><strong>1. Choose the Right Hosting Service and start having an instance:</strong></p><p>The first step in creating an affordable PostgreSQL server is selecting the right hosting service. Several cloud providers offer free tiers with limited resources, which are perfect for freelancers just starting. For me i prefer using the cheapest VPS i could find (haha). for this writing i chose to use <a href="https://contabo.com/en/">contabo</a> (i’m not sponsored but i find it my cheapest option right now)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*aNe0mnjBEF2dWxnP7Sd-ww.png" /><figcaption>nov 2023 pricing</figcaption></figure><p>you can easily sign up and the VPS will gave you the credential to ssh to the ubuntu server to create your own all in one server.</p><p><strong>2. think through what youre gonna deploy there</strong></p><p>for this tutorial i will install and implement all of these stack :</p><ol><li>Ubuntu</li><li>Ansible (for preconfiguring my server for all this stack)</li><li>Docker Swarm (for orchestration)</li><li><a href="https://docs.portainer.io/start/install/server/swarm/linux">Portainer</a> (dashboard for docker swarm)</li><li>PostgreSQL</li></ol><p>you can even install anything you need if its docker swarm capable by compose</p><ol><li>Redis</li><li>MongoDB</li><li>RabbitMQ</li><li>Adminer</li><li>PGadmin</li><li>etc..</li></ol><p><strong>2. Test to SSH to the instance you’ve just subscribed / bought</strong></p><p>after having the ssh credential from your VPS provider. you can test it out to SSH using root to your newly subscribed server. i usually use this command from my workstation pc</p><pre>ssh root@xxx.xxx.xxx.xxx -p 22</pre><p>if you already able to SSH it , lets continue to do the preconfiguration of your server using ansible</p><p><strong>3. Preparing the configuration script for the server using ansible</strong></p><p>to make life easier for you lemme guide you to create ansible script to preconfigure your server to add SSH hardening, install docker, install portainer and add cron jobs to housekeep the docker swarm</p><ol><li>make a directory for your ansible and all its playbooks dependencies</li></ol><pre>mkdir ~/new-instance &amp;&amp; cd ~/new-instance<br>mkdir cronjob<br>touch playbook_initiate.yml playbook_portainer.yml host_initial host_after cronjob/dockerprune.sh. start to fill those fi</pre><p>2. start to edit all those file into this configuration</p><p>first we setup the housekeeping bash script</p><pre>vi cronjob/dockerprune.sh</pre><p>note :</p><ol><li>this housekeeping script will run at every 2 in the morning</li><li>you can try to run it if you have docker installed on the server later</li></ol><pre>#!/bin/bash<br>#<br>mkdir -p $HOME/cronjob/cron_logs<br>docker image prune -a --force --filter &quot;until=24h&quot; &gt;&gt; &quot;$HOME/cronjob/cron_logs/dockerimageprune-$(date +\%Y-\%m-\%d_\%H\%M\%S).log&quot; 2&gt;&amp;1<br>docker container prune -f --filter &quot;until=24h&quot; &gt;&gt; &quot;$HOME/cronjob/cron_logs/dockercontainerprune-$(date +\%Y-\%m-\%d_\%H\%M\%S).log&quot; 2&gt;&amp;1<br>find $HOME/cronjob/cron_logs -type f -mtime +30 -delete</pre><p>next we setup the ansible playbook for installing docker and SSH hardening</p><pre>vi playbook_initiate.yml</pre><p>note :</p><ol><li>you need to have your RSA public key for SSH hardening (this command can help you create one if you dont have any it will be placed on ~/.ssh/)</li></ol><blockquote>ssh-keygen -t rsa -b 4096 -C &quot;your_email@example.com&quot;</blockquote><p>2. you need to have your designated username on the bold content</p><p>3. you need to adjust to your timezone on the bold content</p><p>4. your SSH port will be changed from <strong>22</strong> to <strong>44125</strong> after this playbook was run</p><pre>---<br>- name: update server and install docker<br>  hosts: managed_instance<br>  become: true<br>  tasks:<br><br>    - name: Set configured port fact<br>      set_fact:<br>        configured_port: &quot;44125&quot;<br>    <br>    - name: Setup alternate SSH port<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^Port&quot;<br>        line: &quot;Port {{ configured_port }}&quot;<br><br>    - name: enable PAM<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^UsePAM&quot;<br>        line: &quot;UsePAM yes&quot;<br><br>    - name: Ensure SSH is reloaded if need be<br>      meta: flush_handlers<br><br>    - name: Add Docker GPG apt Key<br>      apt_key:<br>        url: https://download.docker.com/linux/ubuntu/gpg<br>        state: present<br><br>    - name: Add Docker Repository<br>      apt_repository:<br>        repo: deb https://download.docker.com/linux/ubuntu focal stable<br>        state: present<br><br>    - name: Update apt and install docker-ce<br>      apt:<br>        name: docker-ce<br>        state: latest<br>        update_cache: true<br><br>    - name: Update apt and install htop<br>      apt:<br>        name: htop<br>        state: latest<br>        update_cache: true<br><br>    - name: Update apt and install net-tools<br>      apt:<br>        name: net-tools<br>        state: latest<br>        update_cache: true<br><br> <br>    - name: add user your-username to docker group  <br>      ansible.builtin.user:<br>        name: <strong>your-username</strong><br>        shell: /bin/bash<br>        groups: docker, sudo<br>        append: yes<br><br><br>    - name: setup user your-username for no password sudo<br>      lineinfile:<br>        dest: &quot;/etc/sudoers&quot;<br>        regexp: &quot;^<strong>your-username</strong>&quot;<br>        line: &quot;<strong>your-username</strong> ALL=(ALL) NOPASSWD:ALL&quot;<br><br>    - name: reset ssh connection to allow user changes to affect ansible user<br>      ansible.builtin.meta:<br>        reset_connection<br><br>    - name: disable password authentication<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^PasswordAuthentication&quot;<br>        line: &quot;PasswordAuthentication no&quot;<br><br>    - name: disable root login<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^PermitRootLogin&quot;<br>        line: &quot;PermitRootLogin no&quot;<br><br>    - name: disable empty password <br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^PermitEmptyPasswords&quot;<br>        line: &quot;PermitEmptyPasswords no&quot;<br><br>    - name: disable X11Forwarding<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^X11Forwarding&quot;<br>        line: &quot;X11Forwarding no&quot;<br><br>    - name: set SSH ClientAliveInterval<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^ClientAliveInterval&quot;<br>        line: &quot;ClientAliveInterval 300&quot;<br><br>    - name: set SSH ClientAliveInterval<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^ClientAliveCountMax&quot;<br>        line: &quot;ClientAliveCountMax 2&quot;<br><br>    - name: set SSH MaxAuthTries<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^MaxAuthTries&quot;<br>        line: &quot;MaxAuthTries 3&quot;<br><br>    - name: set SSH MaxSessions<br>      lineinfile:<br>        dest: &quot;/etc/ssh/sshd_config&quot;<br>        regexp: &quot;^ClientAliveCountMax&quot;<br>        line: &quot;MaxSessions 5&quot;<br><br>        <br>    - name: Set authorized key for multiple user to access user ops ssh by copying it from current user<br>      authorized_key:<br>        user: <strong>your-username<br></strong>        state: present<br>        key: &#39;{{ item }}&#39;<br>      with_file:<br>        - &quot;~/.ssh/id_rsa.pub&quot;<br><br>    - name: set timezone as Asia/Jakarta<br>      ansible.builtin.shell:<br>        cmd: sudo timedatectl set-timezone <strong>Asia/Jakarta<br></strong><br>    - name: restart sshd<br>      service:<br>        name: sshd<br>        state: restarted<br><br>    - name: reset ssh connection to allow user changes to affect ansible user<br>      ansible.builtin.meta:<br>        reset_connection<br><br>    - name: Ensure we use the configured SSH port for the remainder of the role<br>      set_fact:<br>        ansible_port: &quot;{{ configured_port }}&quot;</pre><p>next we setup the ansible playbook for installing portainer</p><pre>vi playbook_portainer.yml</pre><p>note :</p><ol><li>this should work only if you havent configure docker swarm</li><li>this should work only if you dont have a docker network named “public”</li></ol><pre>---<br>  - name: post setup for new instance installation <br>    hosts: managed_instance_ops_admin<br>    tasks:<br><br>      - name: start docker swarm<br>        ansible.builtin.shell:<br>          cmd: docker swarm init<br><br>      - name: create docker network public for portainer if it doesnt exist<br>        ansible.builtin.shell:<br>          cmd: docker network create --driver overlay --attachable --subnet 10.200.0.0/16 public<br><br>      - name: download portainer compose file to home directory<br>        ansible.builtin.shell:<br>          cmd: curl -L https://downloads.portainer.io/ce2-19/portainer-agent-stack.yml -o ~/portainer-agent-stack.yml<br><br>      - name: run compose<br>        ansible.builtin.shell:<br>          cmd: docker stack deploy -c ~/portainer-agent-stack.yml portainer<br>    <br>      - name: copy cronjob shell script for docker prune to the remote server<br>        copy:<br>          src: cronjob/dockerprune.sh<br>          dest: ~/cronjob/<br>          mode: u+x,o+x<br>      <br>      - name: add the cronjob for docker prune<br>        ansible.builtin.cron:<br>          name: &quot;docker daily prune&quot;<br>          minute: &quot;0&quot;<br>          hour: &quot;2&quot;<br>          job: &quot;~/cronjob/dockerprune.sh&quot;</pre><p>next we setup the ansible inventory for the target host on ansible playbook run</p><pre>vi host</pre><p>note:</p><ol><li>change the xxx.xxx.xxx to your VPS IP</li><li>change the username of your previously designated username on the playbook</li></ol><pre>[managed_instance]<br>vps_target ansible_host=<strong>xxx.xxx.xxx.xxx</strong> ansible_user=root ansible_port=22<br><br>[managed_instance_ops_admin]<br>vps_target_hardened ansible_host=<strong>xxx.xxx.xxx.xxx</strong> ansible_user=<strong>your-username</strong> ansible_port=33426</pre><p><strong>4. running the configuration script for the server using ansible</strong></p><p>to run your ansible script you can use this command sequentially</p><pre>&lt;!-- run to install docker and harden SSH and enter your VPS root password when prompted--&gt;<br>ansible-playbook -i host playbook_initiate.yml -K --ask-pass<br><br>&lt;!-- run after playbook_initiate successfully one  --&gt;<br>ansible-playbook -i host playbook_portainer.yml </pre><p>after all those script runned, you can check you server now whether it has already installed docker and portainer</p><pre>ssh your-username@xxx.xxx.xxx -p 44125<br><br>docker service ls<br>docker stack ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/153/1*oeqbuO64y-SAjy_h3DSV7Q.png" /><figcaption>you can see the portainer stack has been installed</figcaption></figure><p><strong>4. setting up the portainer admin credential</strong></p><p>access your portainer using http://xxx.xxx.xxx:9000/ on your web browser, and create a new admin account for portainer (do it as fast as you can cause it can be timed out and error occured if you do it more than 30 sec)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/0*ceeSGntrVvGUJvgc.png" /></figure><p>note :</p><ol><li>xxx.xxx.xxx.xxx is the public IP of your instance</li><li>you need to create in the username and password for the admin on portainer dashboard</li><li>if there is error with timeout, it happened as a security measure from portainer cause it took you too long for entering the new admin credential</li></ol><blockquote>if no 3 happened, you can ssh to the server and run this blocked command , then access the portainer dashboard again from your browser and create the admin account for the dashboard</blockquote><pre>ssh your-username@xxx.xxx.xxx -p 44125 <br>docker stack rm portainer<br>docker stack deploy -c </pre><p><strong>5. installing postgresql using docker stack (compose file)</strong></p><p>click on the primary server (portainer manager)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CACGq_6nCHaZy1bIdOWhQ.png" /></figure><p>click stacks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*miHYyBze0OJeRrXGdccahg.png" /></figure><p>click add stack</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qg13zNU52FNd9KRwnFqGmw.png" /></figure><p>type the name with <strong>postgres</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2G7MzqDZbFeBVIl5c8uAg.png" /></figure><p>and fill the compose configuration with this sample compose file</p><p>note:</p><ol><li>change the environment to your preferred credential to be the superuser of your postgres and the default DB name</li></ol><blockquote>— “POSTGRES_USER=admin_postgres”<br> — “POSTGRES_DB=operational”<br> — “POSTGRES_PASSWORD=mdkwaisjwoe123jedk213j”</blockquote><p>2. for security hardening the db port is changed from the default <strong>5432</strong> to <strong>23455</strong></p><pre>version: &#39;3.9&#39;<br><br>services:<br><br>  postgres:<br>    image: postgres:14.9-alpine<br>    ports:<br>      - target: 23455<br>        published: 5432<br>        protocol: tcp<br>        mode: ingress<br>    environment: <br>      - &quot;POSTGRES_USER=admin_postgres&quot;<br>      - &quot;POSTGRES_DB=operational&quot;<br>      - &quot;POSTGRES_PASSWORD=mdkwaisjwoe123jedk213j&quot;<br>      - &quot;PGDATA=/data/postgres&quot;<br>    volumes:<br>      - &quot;/etc/localtime:/etc/localtime:ro&quot;<br>      - postgres-database:/data/postgres<br>    networks:<br>      - public<br>    deploy:<br>      replicas: 1<br>      rollback_config:<br>        parallelism: 1<br>        delay: 10s<br>        order: start-first<br>      update_config:<br>        parallelism: 1<br>        delay: 10s<br>        order: start-first<br>        failure_action: rollback<br>      restart_policy:<br>        condition: any<br>        delay: 5s<br>        max_attempts: 5<br>      resources:<br>        limits:<br>          cpus: &#39;1&#39;<br>          memory: 4G<br><br>networks:<br>  public:<br>    external: true<br>    name: public<br><br>volumes:<br>  postgres-database:<br>    name: postgres-database</pre><p><strong>5. try out your new DB server</strong></p><p>try using pgadmin, adminer, or dbeaver to access your newly created DB with your docker stack environment value, for this guide those are</p><blockquote>DB HOST = xxx.xxx.xxx</blockquote><blockquote>DB USER = admin_postgres</blockquote><blockquote>DB PASS = mdkwaisjwoe123jedk213j</blockquote><blockquote>DB PORT = 23455</blockquote><blockquote>DB NAME = operational</blockquote><p><strong>6. Have fun with your new PostgreSQL server that capable of installing another stack if you need to</strong></p><p><strong>Conclusion :</strong></p><p>we can set up our own postgresql server on docker with the cost of 5.5 dollar per month rather than spend it on a managed service RDS on cloud provider</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a2133d2c40f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>