Databases
Installation of each database can be done with instructions below.
Redis
Installation
Run with elevated privledges
sudo su
Install Redis
apt update && apt install redis
Enable Redis Service
systemctl enable redis-server
Configuration
Configure Redis by editing /etc/redis/redis.conf
Allow remote connections by commenting out binding
# bind 127.0.0.1 -::1
Set database password by uncommenting the following line and replaceing foobared
requirepass moreSecurePass
Start Server
Start Redis server
systemctl start redis-server
QuestDb
Preinstallation
Make sure you have Java installed
sudo apt update && sudo apt install default-jre
Edit the system configuration to set maximum open file limits:
sudo nano /etc/sysctl.conf
fs.file-max=1048576
Installation
Get the latest version of QuestDb
wget https://github.com/questdb/questdb/releases/download/8.1.4/questdb-9.3.3-rt-linux-x86-64.tar.gz
Untar the file
tar -xvzf https://github.com/questdb/questdb/releases/download/9.3.3/questdb-9.3.3-rt-linux-x86-64.tar.gz
Move folder
mv questdb-9.3.3-rt-linux-x86-64 /opt/questdb
Capacity Planning
You should read QuestDb's documentation on capacity planning as you can have fairly large database improvements by adjusting specific parameters Capacity Planning
Start QuestDb
You can start QuestDb via the following command
bash /opt/questdb/bin/questdb.sh start
PostGresDb
Installation
Run with elevated privledges
sudo su
Install PostGreSql
apt install postgresql postgresql-contrib
Enable PostGreSql Service
systemctl start postgresql.service
Switch to postgres user
sudo -i -u postgres
Open psql
psql
Set user with password
CREATE ROLE app SUPERUSER
LOGIN
PASSWORD 'moreSecurePass';
Let user login
ALTER ROLE 'app' WITH LOGIN;
Exit psql
\q
Edit server to allow remote connections
sudo nano /etc/postgresql/16/main/postgresql.conf
Modify the #listen_addresses = 'localhost' to '*' and modify max_connections to 1000, we will have many microservices and it's a good idea to increase the max connections now
listen_addresses = '*'
max_connections = 10000
Edit connections
sudo nano /etc/postgresql/16/main/pg_hba.conf
Modify the section:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
To:
# IPv4 local connections:
host all all 0.0.0.0/0 md5
Restart Service
systemctl restart postgresql.service
NATS
Installation
Download the latest NATS server binary from the official NATS GitHub releases:
curl -L https://github.com/nats-io/nats-server/releases/download/v2.10.14/nats-server-v2.10.14-linux-amd64.zip -o nats-server.zip
Unzip the downloaded file:
unzip nats-server.zip
Move the binary to a system path:
sudo mv nats-server /usr/local/bin/
Verify the installation:
nats-server --version
Configuration
Create a NATS configuration directory:
sudo mkdir -p /etc/nats
Create a configuration file:
sudo nano /etc/nats/nats.conf
Add configuration with username and password authentication:
port: 4222
monitor_port: 8222
# Store logs
log_file: "/var/log/nats/nats.log"
# Enable debug mode (optional)
debug: false
# Authentication
authorization {
users: [
{ user: "nats_user", password: "secure_password_here" }
]
}
# Configure persistence (optional)
jetstream {
store_dir: "/var/lib/nats"
}
Replace nats_user and secure_password_here with your desired username and a strong password.
Create the log and data directories:
sudo mkdir -p /var/log/nats
sudo mkdir -p /var/lib/nats
Create Systemd Service
Create a systemd service file:
sudo nano /etc/systemd/system/nats.service
Add the following configuration:
[Unit]
Description=NATS Server
After=network.target
[Service]
Type=simple
User=nobody
Group=nogroup
ExecStart=/usr/local/bin/nats-server -c /etc/nats/nats.conf
Restart=on-failure
RestartSec=5s
StandardOutput=append:/var/log/nats/nats.log
StandardError=append:/var/log/nats/nats.log
[Install]
WantedBy=multi-user.target
Start NATS
Enable the NATS service to start on boot:
sudo systemctl enable nats
Start the NATS server:
sudo systemctl start nats
Verify the service is running:
sudo systemctl status nats
Verify NATS is Running
Connect to NATS using the command-line client:
nats-server -h
Or monitor the status via the monitoring port:
curl http://localhost:8222/varz