9. Shared PostgreSQL server with students¶
In this exercise, a database server shared with the students is prepared for a PostgreSQL exercise in IsardVDI, without the need for advanced network configurations.
Scenario¶
┌────────────────────────┐
│ │
│ DEFAULT GATEWAY ROUTER │
│ │
└────────────┬───────────┘
│.1
┌───────────────────────┼────────────────────────┐
│ │ │
│ 192.168.1.0/24 │ │
─────┬───┴───────── ─────┬──┴───────── ──────┬───┴───────
│ default │ │
│ │ │
┌────┴─────────┐ ┌───┴──────────┐ ┌─────┴────────┐
│ │ │ │ │ │
│ server │ │ client1 │ │ client2 │
│ │ │ Ubuntu │ │ Ubuntu │
│ Postgres │ │ Postgres │ │ Postgres │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│.20 │DHCP │DHCP
│ │ │
│ │ │
│ 192.168.222.0/24 │ │
────────┴──────┬──────────────────┴─────────────────────┴──────────
│ Group network: grupo_bbdd
│
│.10
┌───────┴───────┐
│ │
│ │
│ server │
│ DHCP │
│ Alpine │
│ │
│ │
└───────────────┘
Create resources and users in IsardVDI¶
To create all the following resources you need the administrator role, from the administration panel (see the administration manual).
First, create a new category with the following name:
If there is no student group, create one:
Create a sample user for this group:
Add a group network, which the students must also see. Networks are created in Domains → Resources, Interfaces section (see Resources):
Then, share it with the students: find the network you created, click the button and select the correct category and group:
Create PostgreSQL server¶
Next, the PostgreSQL server is created: a desktop with the following characteristics:
Inside the desktop, open a terminal and run the following commands:
sudo bash -c 'cat > /etc/udev/rules.d/70-persistent-net.rules << EOF
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="enp1s0", NAME="inet"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{type}=="1", KERNEL=="enp2s0", NAME="grupo"
EOF'
DHCP Server with Alpine Linux¶
The DHCP server is hosted on a desktop based on Alpine Linux, with the following configuration:
Inside the server, update the packages and shut it down:
Next, edit the desktop with the following characteristics:
- Remove the ISO.
- Boot: Hard Disk.
- Keep only the Default network.
Then, convert the desktop into a template to have a base Alpine template, and check that the template is enabled and has the necessary permissions. This can be changed in the templates section with the buttons and :
Connecting to the router via SSH from a graphical desktop to use the clipboard¶
Next, edit the desktop to add the group network created earlier and start it again; it now depends on the template you have just created. To be able to copy and paste commands, a graphical desktop with the SPICE viewer is used, and from it you connect via SSH to the DHCP server, which will have a fixed IP.
On the DHCP server you can run setup-alpine again and configure the IP of the new interface, or assign the new IP address with the following commands:
Next, create a Fedora-based client as follows:
Inside the client, assign another IP from the same group network:
sudo systemctl stop NetworkManager.service
sudo ip a a 192.168.222.20/24 dev enp2s0
ping -c 1 192.168.222.10
Create the Alpine xarxes template¶
The goal is to have an Alpine template ready to work with networks, with an initial script where the students can enter basic Linux commands to configure interfaces and iptables.
The script commands run when the machine boots.
- Create the script and give it permissions on the Alpine server:
- Install the Bash shell:
- Enable the forwarding bit for the next boot:
# Enable forwarding bit so it can function as a router
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
- Script content:
- Create the service file:
- Service file content:
#!/sbin/openrc-run
depend() {
after sshd
}
start() {
ebegin "router starting"
/usr/local/bin/startup_script.sh
eend $?
}
- Enable the service:
- Reboot and check that it is active by looking at:
- Add the network packages:
- Shut down the desktop and create the Alpine xarxes v1 template.
Configure the DHCP server¶
On the DHCP server desktop, remove the Default network so that only the group interface remains.
Run the Alpine interface configuration:
Then, restart the network to apply the new configuration:
Next, configure the DHCP server by creating the configuration file:
cat <<'EOF' > /etc/dnsmasq.conf
interface=eth0
dhcp-range=192.168.222.20,192.168.222.199,255.255.255.0,24h
log-dhcp
dhcp-leasefile=/var/lib/dnsmasq.leases
EOF
Start the service and enable it to run at boot:
Reboot, check with a client that it gets an IP and that the assignment is recorded in the logs:
Finally, shut down the desktop and create the dhcp-server-alpine template:
PostgreSQL Server on Debian¶
Create a Debian desktop from an ISO (from Media → Create new desktop) with the following configuration:
Install it as a server, without any graphical environment and selecting SSH server:
With the desktop shut down, set Boot: Hard Disk, remove the ISO and create the debian13-server template:
Install PostgreSQL service¶
- Add the group network interface.
- Configure the interface. By default, Debian configures the network with the
networkingservice and the/etc/network/interfacesfile. - Become root and add these lines to configure the second network card (enp2s0):
- Restart the service:
- Install sudo:
apt install sudo
usermod -aG sudo isard
echo 'isard ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/isard
- Log in as isard and check that sudo works without asking for the password.
- Install the postgres packages:
- Configure the server so that it is accessible from other machines:
# Change listen_addresses to '*' in postgresql.conf
sudo sed -i "s/^#listen_addresses = 'localhost'/listen_addresses = '*'/" /etc/postgresql/17/main/postgresql.conf
# Add the line to pg_hba.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/17/main/pg_hba.conf
- Check that it has been configured correctly:
grep listen_addresses /etc/postgresql/17/main/postgresql.conf
sudo tail -n 1 /etc/postgresql/17/main/pg_hba.conf
- Restart the service and enable it:
- Enter the PostgreSQL shell:
- Create the database and a user, and grant it all privileges:
CREATE DATABASE testdb;
CREATE USER testuser WITH ENCRYPTED PASSWORD '<password>';
GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
- Create a superuser user with all privileges in PostgreSQL:
PostgreSQL Clients in Fedora¶
- Create a desktop based on Fedora 40.
- Update the packages and restart the system.
Check that the service works:
Install pgadmin4:
To install the DBeaver client, download the .rpm file from the official website and install it.
Check that the clients work and can connect.
From the client command line, connect to the PostgreSQL server:
Create a table:
If no errors have occurred, the table should be created.
In pgAdmin4, configure the connection and create a row in the test table:
In DBeaver, also configure the connection:
Deploy users¶
Finally, create the templates of the PostgreSQL server and of the desktop with the clients.






















