How to install Streamlit on Ubuntu 22.04

In this tutorial, we are going to learn how to install Streamlit on Ubuntu 22.04

Streamlit is an open-source Python library that makes it easy to create and share beautiful, custom web apps for machine learning and data science. This is a faster way to build and share data apps. Streamlit turns data scripts into shareable web apps in minutes.

You don’t need to write the backend or frontend to define Streamlit, you only need to add widgets which is the same as declaring variables. This makes it easy to use and also deploy. Deploying your app is just a click of a button and your application is in the cloud.

Prerequisites

  • Have PIP installed
  • Python 3.7 and above
  • IDE

Something to note here is, have a virtual environment installed so that Streamlit doesn’t impact any other projects you might be working on.

Install Streamlit on Ubuntu 22.04

1. Create a virtual environment

First, we need to create a virtual environment so that we can separate our Streamlit work from others. To create a virtual environment using the following command. First create a project directory.

$ sudo mkdir streamlit 
$ cd streamlit
$ python3 -m venv env # env is the name of the virtual environment.

After creating a virtual environment, you can then open this project from your favorite IDE or you can continue from the terminal.

To activate the virtual environment, use the following command.

$ source env/bin/activate

If it happens you don’t have pip installed, you can do install using the following command.

sudo apt-get install python3-pip

After this we need to install pipenv on our virtual environment.

$ pip3 install pipenv

This will create pipfile in your workspace.

2. Install streamlit

To install Streamlit, use the following command on your terminal.

pip install streamlit

You will be in a position to see an output such as this one.

Collecting streamlit
  Downloading streamlit-1.12.2-py2.py3-none-any.whl (9.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.1/9.1 MB 118.6 kB/s eta 0:00:00
Collecting protobuf<4,>=3.12
  Downloading protobuf-3.20.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 88.4 kB/s eta 0:00:00
Collecting blinker>=1.0.0
  Downloading blinker-1.5-py2.py3-none-any.whl (12 kB)
Collecting python-dateutil
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting importlib-metadata>=1.4
  Downloading importlib_metadata-4.12.0-py3-none-any.whl (21 kB)
Collecting packaging>=14.1
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting watchdog
  Downloading watchdog-2.1.9-py3-none-manylinux2014_x86_64.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.4/78.4 KB 202.5 kB/s eta 0:00:00

We can test whether the installation worked, let’s create an hello file from the terminal

streamlit hello

This will automatically open a web browser on localhost:8501.

Nextgentips: Streamlit hello interface

Create Streamlit App

Let’s create a simple example. Paste the following code on your browser and name it app.py

import streamlit as st

st.write('Hello world')

To run this code go to your terminal and type streamlit run app.py

streamlit run app.py

The output will be an hello world.

Let’s find the square of different numbers.

x = st.slider('x')
st.write(x, 'squared is', x * x)

You will get a slider as an output.

Nextgentips: slider squared

Conclusion

We have successfully installed Streamlit on ubuntu 22.04 and we have learned how to create sliders. This is a very important tool when it comes to data science. Feel free to consult Streamlit documentation.

How to install Monit on Arch Linux

In this tutorial, we will be learning how to install Monit on Arch Linux.

Monit is a small open-source utility for managing and monitoring Unix systems. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

With Monit, systems status can be viewed directly from the command line, or via the native HTTP(s) webserver. It is able to do automatic maintenance, repair, and run meaningful causal actions in error situations.

Uses of Monit.

Monit can have many use cases because of its versatility. Let’s look at the following:

  • Monit can be used to monitor files and directories, Monit monitor this system for any changes such as file timestamp, security changes or file size changes, etc.
  • Monit acts proactively, whereby in case of an error in the system functionality, Monit can send an alert to inform that such a process wasn’t complete.
  • Monit can be used to test programs and scripts such as cron jobs do. You can monitor and check the scripts you want to use in any scenario.
  • We use Monit to monitor any daemon processes or any other process running on the localhost such as sshd, Nginx, or MySQL processes.
  • Monit can be used to monitor general system functionality such as CPU and RAM usage.
  • It can be used to monitor network connections on various servers because Monit has built-in tests for Internet protocols such as SMTP, and HTTP.

Install Monit on Arch Linux

1. Update system repositories.

The first thing, to begin with, is to update repositories in order to make them up to date.

sudo pacman -Syy

2. Install Monit in Arch Linux

To install Monit on Arch Linux we can use the following command pacman -S monit.

sudo pacman -S monit

You should be in a position to see the following from the terminal.

resolving dependencies...
looking for conflicting packages...

Packages (1) monit-5.32.0-1

Total Download Size:   0.35 MiB
Total Installed Size:  0.92 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 monit-5.32.0-1-x...   362.0 KiB  1466 KiB/s 00:00 [###################] 100%
(1/1) checking keys in keyring                     [###################] 100%
(1/1) checking package integrity                   [###################] 100%
(1/1) loading package files                        [###################] 100%
(1/1) checking for file conflicts                  [###################] 100%
(1/1) checking available disk space                [###################] 100%
:: Processing package changes...
(1/1) installing monit                             [###################] 100%
:: Running post-transaction hooks...
(1/2) Reloading system manager configuration...
(2/2) Arming ConditionNeedsUpdate...

3. Configuring Monit service

After the installation, we need to enable and start the services.

To enable Monit service use the following command.

sudo systemctl enable monit 

To start Monit service you the following command.

sudo systemctl start monit

To check the status of Monit, use the following command.

sudo systemctl status monit 

If you see the following status, then it is working perfectly.

● monit.service - Pro-active monitoring utility for unix systems
     Loaded: loaded (/usr/lib/systemd/system/monit.service; enabled; preset: di>
     Active: active (running) since Sat 2022-09-03 05:14:21 UTC; 11s ago
       Docs: man:monit(1)
             https://mmonit.com/wiki/Monit/HowTo
   Main PID: 408 (monit)
      Tasks: 2 (limit: 4690)
     Memory: 1.4M
        CPU: 16ms
     CGroup: /system.slice/monit.service
             └─408 /usr/bin/monit -I

Sep 03 05:14:21 localhost systemd[1]: Started Pro-active monitoring utility for>
Sep 03 05:14:21 localhost monit[408]:  New Monit id: 8f8a6e8053c2a85c3639baea87>
                                       Stored in '/root/.monit.id'
Sep 03 05:14:21 localhost monit[408]: Starting Monit 5.32.0 daemon with http in>
Sep 03 05:14:21 localhost monit[408]: 'localhost' Monit 5.32.0 started

How to install Webmin 2 control panel on Ubuntu 22.04

In this tutorial, we will learn how to install the Webmin control panel on Ubuntu 22.04

Webmin is a powerful and flexible web-based server management control panel for UNIX-like users. It allows Webmin to configure operating system internals e.g users, configuration files, disk quotas, etc. Webmin removes the need to edit Unix configuration files manually and lets you manage the system remotely or via console.

Install Webmin on Ubuntu 22.04

Let’s install Webmin via Ubuntu apt repository. First, update your system in order to make them up to date.

sudo apt update && apt upgrade

To install Webmin via apt repository, we need to edit the /etc/apt/sources.list file and add the following line deb https://download.webmin.com/download/repository sarge contrib

sudo vi /etc/apt/sources.list

Secondly, let’s add GPG key with which the repository is signed.

wget https://download.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc

Third, we need to update our system repositories again for the changes to be effected.

sudo apt update 

Finally, install the Webmin with the following command.

sudo apt install webmin -y

You should be in a position to see an output like this

The following additional packages will be installed:
  libauthen-pam-perl libio-pty-perl libnet-ssleay-perl perl-openssl-defaults
  unzip
Suggested packages:
  zip
The following NEW packages will be installed:
  libauthen-pam-perl libio-pty-perl libnet-ssleay-perl perl-openssl-defaults
  unzip webmin
0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.
Need to get 29.0 MB of archives.
After this operation, 305 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

To know that the Webmin was installed correctly, check the version with the following command.

webmin -v
2.000

Having successfully installed Webmin, let’s now go to the browser and see the Webmin in action.

http://:10000

The username is the root and the password is the root user password.

You should be in a position to see a dashboard like this.

Nextgentips: Webmin dashboard

How to install PostgreSQL 14 and configure it to use md5 connection on Fedora 36

In this guide, we will walk through installing PostgreSQL 14 and then configure I to use an md5 connection whenever you are login into Postgres.

PostgreSQL is a powerful, open-source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. It was designed to handle a range of workloads from single machines to data warehousing.

Every database must conform to ACID properties i.e Atomicity, Consistency, Isolation, and Durability. This is true for PostgreSQL as well, it must conform to those features for transactions to pass the tests.

1. Update system repositories

Before you do any installation, begin by updating your repositories in order to make them up to date.

sudo dnf update -y

We can check the Apstream for available PostgreSQL first.

sudo dnf module list postgresql

This will list all available PostgreSQL in your Fedora Apstream. The output should look like this.

Fedora Modular 36 - x86_64
Name              Stream        Profiles                 Summary                
postgresql        10            client, server [d]       PostgreSQL module      
postgresql        11            client, server [d]       PostgreSQL module      
postgresql        12            client, server           PostgreSQL module      
postgresql        13            client, server           PostgreSQL module      
postgresql        14            client, server           PostgreSQL module      

Fedora Modular 36 - x86_64 - Updates
Name              Stream        Profiles                 Summary                
postgresql        10            client, server [d]       PostgreSQL module      
postgresql        11            client, server [d]       PostgreSQL module      
postgresql        12            client, server           PostgreSQL module      
postgresql        13            client, server           PostgreSQL module      
postgresql        14            client, server           PostgreSQL module      

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

2. Install PostgreSQL 14

To install PostgreSQL use the following command.

sudo dnf install postgresql-server postgresql-contrib

After installation is complete, we need to enable Postgressql, it is disabled by default in our system.

sudo systemctl enable postgresql

Now we need to populate the PostgreSQL database with initial data. This will create postgresql.conf and pg_hba.conf files.

$ sudo postgresql-setup --initdb --unit postgresql
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

Then we can start Postgresql using the following code.

sudo systemctl start postgresql

Check if your PostgreSQL server is running.

● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendo>
     Active: active (running) since Thu 2022-09-01 05:30:34 UTC; 32s ago
    Process: 13028 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql>
   Main PID: 13030 (postmaster)
      Tasks: 8 (limit: 4659)
     Memory: 16.4M
        CPU: 60ms
     CGroup: /system.slice/postgresql.service
             ├─ 13030 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─ 13031 "postgres: logger "
             ├─ 13033 "postgres: checkpointer "
             ├─ 13034 "postgres: background writer "
             ├─ 13035 "postgres: walwriter "
             ├─ 13036 "postgres: autovacuum launcher "
             ├─ 13037 "postgres: stats collector "
             └─ 13038 "postgres: logical replication launcher "

So to check the version of the installed server use the following command.

postgres -V
postgres (PostgreSQL) 14.3

3. Setting up password for Postgres role

Local connections on Postgresql use peer-to-peer connections to check the authenticated users. That is Postgresql instead of asking for the user password, it only checks on the logged-in user to ascertain if the user has credentials to get access to the resources.

Let’s change the way we log in and use a more strong password instead. Let’s set the password for the Postgres user first.

Open psql as the Postgres user with this command sudo -u postgres psql

$ sudo -u postgres psql

could not change directory to "/root": Permission denied
psql (14.3)
Type "help" for help.

The reason we are getting could not change directory to "/root": Permission denied is because of the Postgres authentication, we need to set the password first.

To change the Postgres password use the following command inside of the Postgres interface.

ALTER USER POSTGRES WITH ENCRYPTED PASSWORD 'mypasswrd';
ALTER ROLE

After we have set the password, we now need to tell Postgres to use this password. To do that we need to change pg_hba.conf file. I am using vim as my text editor here, you are free to use your preferred editor as well.

Look for this line of code and change peer to md5

sudo vi /var/lib/pgsql/data/pg_hba.conf

Restart PostgreSQL for the changes to take effect.

sudo systemctl restart postgresql

To ascertain that changes did take place login again to your Postgres server, if it asks for the password, then you are good t go.

$ psql -U postgres
psql (14.3)
Type "help" for help.

You can use the following code whenever you want to upgrade PostgreSQL to a higher version.

postgresql-setup upgrade

How to install Datadog Agent on Ubuntu 22.04

In this tutorial, we are going to learn how to install Datadog Agent on Ubuntu 22.04.

What is Datadog?

Datadog is an infrastructure monitoring service, it empowers users to keep track of the cloud infrastructure. It gives analytics for all services running on your infrastructure, with the help of dashboards making it easy for one to escalate errors whenever it occurs.

Datadog helps you monitor servers, databases, and all the applications running on your infrastructure. Datadog’s seamless integration with many products makes its unique saas application. Currently, Datadog can integrate easily with over 500 products. It also supports the integration of different APIs. Another thing also is it supports other apps written in other languages.

In summary, Datadog has the following great features.

  • It supports other apps written in other languages.
  • Dashboards can easily be customized.
  • Has real-time alerting services.
  • It automatically collects and analyzes logs and errors.
  • It has seamless integration with many APIs
  • It can easily integrate with many products out there.

Datadog Agent Architecture.

Here we need to talk about what makes up Datadog Agent. Let’s start with Components.

Agent Components

The Datadog Agent is made up of the following components:

  • The Collector– This is responsible for gathering system and application metrics from the machine by temporarily executing standard utilities such iostat, vmstat etc or connecting to applications monitoring interfaces over TCP and HTTP.
  • The Forwarder– This is responsible for buffering and communicating with Datadog hq love SSL. It does this by listening over HTTP for any incoming requests then buffer them and forward to Datadog HQ over HTTPs protocol.
  • The Dogstatsd- This is responsible for aggregating local metrics sent from your code. Dogstatsd is a python implementation of etsy’s statsD metric aggregation daemon.
  • The supervisord- This is responsible for keeping all previous processes up and running.

Installing Datadog Agent on Ubuntu 22.04

To install Datadog Agent you need to have the account in order to give you an API for the free trial version. So go ahead and create your account.

1. Agent setup

Once you have created your account, you will be taken to a page like the figure below where you will choose your operating system to install the agent. For us here we will choose Ubuntu. It will then gives you step by step guide on how to install the Datadog Agent for the first time and when upgrading.

Nextgentips: Datadog agent

2. Install Datadog

To install Datadog Agent, copy the easy install script onto your terminal and press enter.

$ sudo -i # to take you to root user
$ DD_AGENT_MAJOR_VERSION=7 DD_API_KEY=7b8f7f1e565c731ccb40f86834b51024 DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

If you are successful with installation, you should be in a position to see something like this:

/usr/bin/systemctl
* Starting the Datadog Agent...



Your Datadog Agent is running and functioning properly. It will continue
to run in the background and submit metrics to Datadog.

If you ever want to stop the Datadog Agent, run:

     systemctl stop datadog-agent

And to run it again run:

     systemctl start datadog-agent

Check the version of the Datadog installed.

$ datadog-agent version
Agent 7.38.2 - Commit: ba442fd - Serialization version: v5.0.23 - Go version: go1.17.11

Also, the finish icon at the bottom will automatically become active because the system will sense the existence of the agent. Press finish to take you to your Datadog dashboard.

nextgentips: Datadog Dashboard

How to perform CRUD operations in Django

In this tutorial, we will learn how to operate CRUD functionalities in Django. CRUD functionalities are Create, Read, Update and Delete. These are the main building blocks of any project. At some point you need to perform read operations from the database, you want to do an update or you wish to delete an item from the database. All these are possible thanks to CRUD operations.

In this tutorial, we are building on top of these lectures on How to set up a Python Django Application using Django 4.0 and How to create Django Templates. So make sure to check out first.

If you want to follow along make sure you have the project setup complete, the templates are working fine, the database is up and running and lastly have some data on the database.

Steps to follow

1. Create a Project

To create a project go to your terminal and create a folder name your project whatever you like, the create a virtual environment where all your installations will be staying. To create a virtual environment do the following.

$ mkdir crud_example
$ cd crud_example
#create a virtual environment 
$ python3 -m venv env #env is the name of the virual environment.

To make your work easier open the containing folder in your favorite text editor, for me I will be using Pycharm. Activate the virtual environment as created above.

$ source env/bin/activate

2. Install Django

To install Django in your project, use the following command.

$ pip install django

After Django has been installed make sure you do pip freeze > requirements.txt in order to store all your installed files. This requiremets.txt file is necessary so that someone else who will come back later and want to use your project will just install the requirements from one file.

$ pip freeze > requirements.txt

3. Create a Django project and app

The next step is to create a Django project and an app. To create a project using the following command.

$ django-admin startproject myproject .

Make sure to include the period in the end. It tells Django to create a project in the current directory.

After the project has been created, we need to create an app. To do so use the following command.

$ python manage.py startapp project

When the app has been created, go to the settings.py file and add your app to the installed apps

#installed apps 
...
'project.apps.ProjectConfig',

Still inside the settings.py file create a database of your choice, be it Mysql, PostgreSQL, or db sqlite. For my case, I will be using PostgreSQL. You may want to leave db sqlite and use it for testing purposes, but you will need PostgreSQL or MySQL for production.

4. Create PostgreSQL database

To use PostgreSQL, we need to create it first in our system and then tell django to use it. To create a Postgresql do the following.

Open psql as Postgres user

sudo -u postgres psql
postgres=# 

To create a database, we use the following command inside postgres.

CREATE DATABASE project_db;

Project is the name of the database.

After creating the database, create the user

CREATE USER projectuser WITH PASSWORD 'strpassword';

Then we need to grant privileges to the user created.

GRANT ALL PRIVILEGES ON DATABASE project_db TO projectuser;

Lastly quit the Postgres with \q

We now need to go back to our project and inside settings.py look for databases and change from db sqlite to PostgreSQL

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'project_db',
        'USER': 'projectuser',
        'PASSWORD': 'strpasswrd',
        'HOST': 'localhost',
        'PORT': '',
    }
}

Before we can connect to PostgreSQL, we need to install psycopg2.

pip install psycopg2-binary

Add it to the requirements.txt file

Create superuser

To create a superuser in Django we use the following command. Make sure to follow the prompts in order to create a user, email, and password

python manage.py createsupeuser

Add some data into the tables to play with.

5. Views, models, and Urls

Let’s start with creating models. Models give us the data and how our database will be structured. For this, I will use a simple example.

#models 
from django.db import models
import uuid

class Project(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField(null=True, blank=True)
    id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False)

    def __str__(self):
        return self.title

After this make sure you run makemigrations and migrate in order to populate the database.

$ python manage.py makemigrations
$ python manage.py migrate

Create urls.py and populate

We need to create a urls.py file inside our app because Django doesn’t create it for us.

Your project/urls.py file should look like this

from django.urls import path
from . import views

urlpatterns = [
]

For the main myproject/urls.py it should look like this

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('project.urls'))# add this to serve the app urls 
]

Create Views

This is the engine of your project. To create views use the following

from django.shortcuts import render

def index(request):
    context = {   
    }
    return render(request, 'project/index.html', context)

5. Django Templates

From this part, we need to create templates and from the beginning, I had cover templates. How to create Django Templates.

Create a templates folder and add all the HTML in it. Create an index.html, projectfile.html, and delete.html files.

6. CRUD functionalities

Read Functionality

We can start with Read functionalities. Let’s display what is in the database in our home.

Remember the view we had created earlier, we are going to work from there. To understand more make sure you play with Django ORM.

This will be our final views.py for Read operations.

from django.shortcuts import render
from .models import Project

def index(request):
    projects = Project.objects.all()# fetch all the data from the database

    context = {
        'projects': projects
    }
    return render(request, 'project/index.html', context)

Create functionality

To use create functionality, we need to have a form where we input our data. So now head over to our app and add forms.py file and populate it with the following:

from django.forms import ModelForm

from app.models import Project


class ProjectForm(ModelForm):
    class Meta:
        model = Project
        fields = '__all__'
       

Then go to views.py file and add this also

def createProject(request):
    form = ProjectForm()

    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    context = {
        'form': form
    }
    return render(request, 'project/projectfile.html', context)

Create urls to serve this view like this:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='home'),
    path('create/', views.createProject, name='create-file'),
]

Create Projectfile.html and populate with this:

{% csrf_token %} {{ form.as_p }}

Update functionality

We are still going to use the form we created earlier. What is different only is the addition of a primary key to help us know the section we are updating.

On views.py file add the following

def updateProject(request, pk):
    project = Project.objects.get(id=pk)
    form = ProjectForm(instance=project)

    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
            return redirect('home')

    context = {
        'form': form
    }
    return render(request, 'project/projectfile.html', context)

Here I am still using the same projectfile.html file because its the same form am working on.

On project/urls.py file add this URL link.

path('update//', views.updateProject, name='update-file'),

Inside index.html file we need to add the edit link so that we can redirect to where we need to edit.

This should be the final index.html file.

Projects

{% for project in projects %} # looping inside the function in django using tags {% endfor %}
Title Description Action Action
{{project.title }} {{project.description }} Edit Delete

Delete functionality

Delete functionality is the last and easiest of the three above. What we need to have is the deletefile.html and delete project view.

Let’s start with the deletefile.html. Populate it with the following.

Delete

{% csrf_token %}

Are you sure you want to delete "{{object}}"?

Go back# using url tags

Our URL is this.

path('delete//', views.deleteProject, name='delete-file')

Create a delete view like this

def deleteProject(request, pk):
    project = Project.objects.get(id=pk)
    if request.method == 'POST':
        project.delete()
        return redirect('home')
    context = {
        'object': project
    }

    return render(request, 'project/deletefile.html', context)

Conclusion

We have successfully implemented the CRUD operation in Django. In case of any difficulty refer to my Github repo for the full codebase.

How to install SaltStack on Fedora 36

In this guide, we will walk you through the installation of SaltStack on Fedora 36.

SaltStack is a Python-based, open-source for event-driven It automation, remote task execution, and configuration management. Salt was designed to be highly modular and easily extensible, to make it easy to mold to diverse IT enterprise use cases.

Salt is capable of maintaining remote nodes in defined states that is it can ensure specific packages are installed and that specific services are running. Salt can query and execute commands either on individual nodes or by using arbitrary selection criteria.

The core functions of Salt

  • Salt enables commands on the remote systems to be called in parallel rather than serially.
  • Salt provides a simple programming interface.
  • It uses the smallest and fastest network payload possible
  • Use a secure and encrypted protocol.

Salt Architecture

Salt uses the master client model. Master issues command to the client and the client executes the commands. Salt master is the server that is running the salt-master service. Salt minions are the servers running the salt-minion services.

A target is a group of minions across one or many masters that a job’s salt command applies to.

Grains interface derives information about the underlying system. Grains are collected for the operating system, domain name, IP addresses, kernel os, etc.

Installing salt on Fedora 36

1. Update system repositories

Before we begin, we need to update our system repositories in order to make them up to date.

sudo dnf update 

2. Install Salt on Fedora 36

Salt is readily available on Fedora repositories and the EPEL. So it is easy to run and install Salt using the dnf or the yum package.

To install both Salt master and minion on your system, use the following command and remember that you need to install a master on the control machine and minions on the servers you want the salt to run on.

Install Salt master

$ sudo dnf install salt-master

The following is the output from the above command.

Package                    Arch        Version              Repository    Size
================================================================================
Installing:
 salt-master                noarch      3004.2-1.fc36        updates      3.1 M
Installing dependencies:
 dnf-utils                  noarch      4.2.1-1.fc36         updates       37 k
 libtomcrypt                x86_64      1.18.2-14.fc36       fedora       389 k
 libtommath                 x86_64      1.2.0-7.fc36         fedora        63 k
 libunwind                  x86_64      1.6.2-2.fc36         fedora        67 k
 openpgm                    x86_64      5.2.122-28.fc36      fedora       177 k
 python3-msgpack            x86_64      1.0.3-2.fc36         fedora        86 k
 python3-pycryptodomex      x86_64      3.15.0-1.fc36        updates      1.1 M
 python3-pycurl             x86_64      7.45.1-1.fc36        fedora       186 k
 python3-zmq                x86_64      22.3.0-2.fc36        fedora       403 k
 salt                       noarch      3004.2-1.fc36        updates      9.3 M
 zeromq                     x86_64      4.3.4-3.fc36         fedora       440 k

Transaction Summary
================================================================================
Install  12 Packages

Total download size: 15 M
Installed size: 58 M
Is this ok [y/N]: y

To install Salt minion we use the following command.

sudo dnf install salt-minion

Whenever you want to connect to minions, you need to have proper permission and for this we need to have Salt ssh.

sudo dnf install salt-ssh

In order to install Salt API we use the following command.

sudo dnf install salt-api

3. Post installation tasks

After the installation is complete, you can run post installations tasks on both master and minions.

To enable Salt master start automatically on boot use the following command.

sudo systemctl enable salt-master

To start Salt master, we use the following command

sudo systemctl start salt-master

To enable Salt minion start automatically on boot we use the this command.

sudo systemctl enable salt-minion

To start Salt minion, we use the following command.

sudo systemctl start salt-minion

To check the status of both Salt master and Salt minion, we use the following command.

$ sudo systemctl status salt-master // for salt master
$ sudo systemctl status salt-minion // for salt minion
● salt-master.service - The Salt Master Server
     Loaded: loaded (/usr/lib/systemd/system/salt-master.service; enabled; ven>
     Active: active (running) since Sat 2022-08-13 06:36:03 UTC; 11s ago
       Docs: man:salt-master(1)
             file:///usr/share/doc/salt/html/contents.html
             https://docs.saltproject.io/en/latest/contents.html
   Main PID: 10739 (salt-master)
      Tasks: 32 (limit: 1113)
     Memory: 199.1M
        CPU: 6.621s
     CGroup: /system.slice/salt-master.service
             ├─ 10739 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10743 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10746 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10747 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10750 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10751 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10752 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10759 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10760 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10762 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10766 /usr/bin/python3 /usr/bin/salt-master
             ├─ 10768 /usr/bin/python3 /usr/bin/salt-master

4. Configuration of the Saltstack

To start off, we need to configure the master so that it will know of the existence of the minions. All the configuration files are found on /etc/salt/.The minions or the master must be findable for it to establish the communication.

To configure Salt master go to /etc/salt/master and add your master IP address with Salt-master IP address.

$ sudo vi /etc/salt/master

Uncomment interface and add the salt-master IP address.

Restart Salt-master for the changes to take effect.

sudo systemctl restart salt-master

Next we need to configure Salt-minion, go to /etc/salt/minion and replace master: salt with a master IP address.

sudo /etc/salt/minion

Uncomment master: salt and remove salt and replace with your master IP address.

We need to restart the server again for the changes to take effect.

sudo systemctl restart salt-minion 

5. Test configuration

To see the configuration use the following commands:

sudo salt-key -L

From the above command you be in a position to see the following:

Accepted Keys:
Denied Keys:
Unaccepted Keys:
Rejected Keys:

To accept all keys use the following command.

$ salt-key -A

Conclusion

Congratulations we have installed Salt-master and Salt-Minion on Fedora 36.

How to install PostgreSQL 15 on Ubuntu 22.04

In this guide, we are going to walk through installing PostgreSQL 15 on Ubuntu 22.04.

PostgreSQL is a powerful, open-source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. It was designed to handle a range of workloads from single machines to data warehousing.

Every single database must conform to ACID properties i.e Atomicity, Consistency, Isolation, and Durability. This is true for PostgreSQL as well, it must conform to those features for transactions to pass the tests.

Notable Features introduced for PostgreSQL 15.

  • It removes both the long deprecated exclusive backup and support from Python 2 from PL/Python.
  • It revokes the CREATE permission from all users except for the database owner from the default.
  • It adds the new built-in extension, the pg_walinspect, that lets users inspect the contents of write-ahead log files directly from an SQL interface.
  • Server-level statistics are now collected in shared memory, eliminating the statistics collector process and periodically writing this data to disk.
  • It makes it possible to make an ICU Collation the default collation for a cluster or an individual database.
  • It introduces the new logging format jsonlog which outputs log data using a defined json structure and allows PostgreSQL logs to be processed in structured logging systems. This gives database administrators more flexibility on how users can manage PostgreSQL configurations.
  • It provides more flexibility for managing logical replication. It introduces row filtering and column lists for publishers, letting users choose to replicate a subset of data from a table.
  • It added a feature to simplify conflict management, including the ability to skip replaying a conflicting transaction and to automatically disable a subscription if an error is detected.

1. Update the Ubuntu repository

The first thing to do is to update the ubuntu repository in order to make them up to date.

$ sudo apt update && apt upgrade -y

2. Install PostgreSQL 15 on Ubuntu 22.04

In order to run PostgreSQL 15 on Ubuntu 22.04, we are supposed to add 15 component to /etc/apt/sources.list.d/pgdg.list entry so that version 15 will be available for installation.

In order to add 15 to sources.list file, use the following command.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main 15" > /etc/apt/sources.list.d/pgdg.list'

Next, we need to import the repository signing key.

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

The next thing is to update the system again for the changes to take effect.

sudo apt update 

Lastly, install PostgreSQL with the following command.

apt-get install postgresql-15

You will get the following as the output

The following additional packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5
  libsensors-config libsensors5 libtypes-serialiser-perl pgdg-keyring
  postgresql-client-15 postgresql-client-common postgresql-common ssl-cert
  sysstat
Suggested packages:
  lm-sensors postgresql-doc-15 isag
The following NEW packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5
  libsensors-config libsensors5 libtypes-serialiser-perl pgdg-keyring
  postgresql-15 postgresql-client-15 postgresql-client-common
  postgresql-common ssl-cert sysstat
0 upgraded, 15 newly installed, 0 to remove and 1 not upgraded.
Need to get 43.7 MB of archives.
After this operation, 173 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

After installation is complete, we can check to see if PostgreSQL is running with the following command.

$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
     Active: active (exited) since Fri 2022-10-14 07:14:55 UTC; 3min 55s ago
    Process: 16129 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 16129 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Oct 14 07:14:55 ip-172-31-88-167 systemd[1]: Starting PostgreSQL RDBMS...
Oct 14 07:14:55 ip-172-31-88-167 systemd[1]: Finished PostgreSQL RDBMS.

3. Setting up password for Postgres role

Local connections on Posgtresql use peer to check the authenticated users. That is Postgresql instead of asking for the user password, it only checks on the logged-in user to ascertain if the user has credentials to get access to the resources.

Let’s change the way we log in and use a more strong password instead. Let’s set the password for the Postgres user first.

Open psql as the Postgres user with this command sudo -u postgres psql

$ sudo -u postgres psql

You will get output like this.

could not change directory to "/root": Permission denied
psql (15rc2 (Ubuntu 15~rc2-1.pgdg22.04+1))
Type "help" for help.

postgres=# SHOW server_version;
           server_version            
-------------------------------------
 15rc2 (Ubuntu 15~rc2-1.pgdg22.04+1)
(1 row)

The reason we are getting could not change directory to "/root": Permission denied psql is because of the Postgres authentication, we need to set the password first.

To change the Postgres password use the following command inside of the Postgres interface.

postgres=# ALTER USER POSTGRES WITH ENCRYPTED PASSWORD 'strgpasswd';

After we have set the password, we now need to tell Postgres to use this password. To do that we need to change pg_hba.conf file. I am using vim as my text editor here, you are free to use your preferred editor as well.

Look for this line of code and change peer to md5

local  all  postgres  peer
local  all  postgres  md5

To edit the configuration file use the following command.

sudo vi /etc/postgresql/15/main/pg_hba.conf

Restart PostgreSQL for the changes to take effect.

sudo systemctl restart postgresql

We can also ascertain whether PostgreSQL is running on our system with the following command.

sudo systemctl status postgresql

If you get the status active then we are good to go.

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
     Active: active (exited) since Fri 2022-10-14 07:27:38 UTC; 14s ago
    Process: 16326 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 16326 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Oct 14 07:27:38 ip-172-31-88-167 systemd[1]: Starting PostgreSQL RDBMS...
Oct 14 07:27:38 ip-172-31-88-167 systemd[1]: Finished PostgreSQL RDBMS.

After this, we can log in again to the Postgres

psql -U postgres
Password for user postgres: 
psql (15rc2 (Ubuntu 15~rc2-1.pgdg22.04+1))
Type "help" for help.

postgres=# 

We have successfully changed Postgres to use password authentication.

Conclusion

Congratulations, we have successfully installed PostgreSQL 15 on Ubuntu 22.04 and also set the password for the default user Postgres. For more information get the latest from PostgreSQL documentation.

How to install Monit 5 on Fedora 36

In this tutorial, we are going to learn how to install Monit 5 on Fedora 36.

Monit is a small open source utility for monitoring and managing Unix systems. It performs automatic maintenance whenever there is downtime in your system.

Uses of Monit.

Monit can have many use cases because of its versatility. Let’s look at the following:

  • Monit can be used to monitor files and directories, Monit monitor this system for any changes such as file timestamp, security changes or file size changes, etc.
  • Monit acts proactively, whereby in case of an error in the system functionality, Monit can send an alert to inform that such a process wasn’t complete.
  • Monit can be used to test programs and scripts such as cron jobs do. You can monitor and check the scripts you want to use in any scenario.
  • We use Monit to monitor any daemon processes or any other process running on the localhost such as sshd, Nginx, or MySQL processes.
  • Monit can be used to monitor general system functionality such as CPU and RAM usage.
  • It can be used to monitor network connections on various servers because Monit has built-in tests for Internet protocols such as SMTP, and HTTP.

How to Install Monit 5 on Fedora 36

1. Update system repositories.

Before you begin any installation, make sure you update all the system packages in order to make them up to date. To update Fedora use sudo dnf update.

$ sudo dnf update

Follow the prompts in order to complete updates successfully.

2. Install Monit 5 on Fedora 36

Monit is readily available on the Fedora packages, so to install you use the following command sudo dnf install monit.

$ sudo dnf install monit 

You should be in a position to see the following output.

Fedora Modular 36 - x86_64 - Updates             12 kB/s |  15 kB     00:01    
Dependencies resolved.
================================================================================
 Package        Architecture    Version                  Repository        Size
================================================================================
Installing:
 monit          x86_64          5.32.0-1.fc36            updates          391 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 391 k
Installed size: 990 k
Is this ok [y/N]: y
Downloading Packages:
monit-5.32.0-1.fc36.x86_64.rpm                  949 kB/s | 391 kB     00:00    
--------------------------------------------------------------------------------
Total                                           619 kB/s | 391 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : monit-5.32.0-1.fc36.x86_64                             1/1 
  Running scriptlet: monit-5.32.0-1.fc36.x86_64                             1/1 
  Verifying        : monit-5.32.0-1.fc36.x86_64                             1/1 

Installed:
  monit-5.32.0-1.fc36.x86_64                                                    

Complete!

3. Configure Monit service

To configure Monit to start on boot we use the following command sudo systemctl enable monit

$ sudo systemctl enable monit

To start Monit immediately we use the following command.

$ sudo systemctl start monit 

To check the status of Monit we use the following command.

$ sudo systemctl status monit 
● monit.service - Pro-active monitoring utility for unix systems
     Loaded: loaded (/usr/lib/systemd/system/monit.service; enabled; vendor pre>
     Active: active (running) since Thu 2022-08-11 08:00:10 UTC; 12s ago
       Docs: man:monit(1)
             https://mmonit.com/wiki/Monit/HowTo
   Main PID: 15788 (monit)
      Tasks: 2 (limit: 1113)
     Memory: 2.0M
        CPU: 29ms
     CGroup: /system.slice/monit.service
             └─ 15788 /usr/bin/monit -I

Aug 11 08:00:10 localhost.localdomain systemd[1]: Started monit.service - Pro-a>
Aug 11 08:00:10 localhost.localdomain monit[15788]:  New Monit id: d45a290ce0d6>
                                                     Stored in '/root/.monit.id'
Aug 11 08:00:10 localhost.localdomain monit[15788]: Starting Monit 5.32.0 daemo>
Aug 11 08:00:10 localhost.localdomain monit[15788]: 'localhost.localdomain' Mon>

There are packages installed with Monit automatically. To check those files you can use the following command rpm -ql monit.

$ sudo rpm -ql monit
/etc/monit.d
/etc/monitrc
/usr/bin/monit
/usr/lib/.build-id
/usr/lib/.build-id/9a
/usr/lib/.build-id/9a/670fe3396cb159ea1c384f1f673a420b3691ed
/usr/lib/systemd/system/monit.service
/usr/share/doc/monit
/usr/share/doc/monit/CHANGES
/usr/share/doc/monit/COPYING
/usr/share/man/man1/monit.1.gz

NB: Prefix sudo whenever you are working as a regular user.

Conclusion

We have successfully installed and configured Monit on Ubuntu 22.04. For further reference check the Monit documentation.

How to install Monit 5 on Ubuntu 22.04

Monit is a small open source utility for monitoring and managing Unix systems. It performs automatic maintenance whenever there is downtime in your system. From this tutorial, you are going to learn how to install Monit on Ubuntu 22.04.

Uses of Monit.

Monit can have many use cases because of its versatility. Let’s look at the following:

  • Monit can be used to monitor files and directories, Monit monitor this system for any changes such as file timestamp, security changes or file size changes, etc.
  • Monit acts proactively, whereby in case of an error in the system functionality, Monit can send an alert to inform that such a process wasn’t complete.
  • Monit can be used to test programs and scripts such as cron jobs do. You can monitor and check the scripts you want to use in any scenario.
  • We use Monit to monitor any daemon processes or any other process running on the localhost such as sshd, Nginx, or MySQL processes.
  • Monit can be used to monitor general system functionality such as CPU and RAM usage.
  • It can be used to monitor network connections on various servers because Monit has built-in tests for Internet protocols such as SMTP, and HTTP.

How to install Monit on Ubuntu 22.04

1. Run system updates.

Before we begin the installation, let’s start by updating our system repositories to make them up to date.

sudo apt update && apt upgrade -y

2. Install Monit from the packages.

Because Monit is available on the Ubuntu package repository, we are only going to use the following command to do the install apt install monit.

$ sudo apt install monit

You should be in a position to see the following output.

Suggested packages:
  default-mta | postfix | mail-transport-agent sysvinit-core
The following NEW packages will be installed:
  monit
0 upgraded, 1 newly installed, 0 to remove and 304 not upgraded.
Need to get 399 kB of archives.
After this operation, 1,100 kB of additional disk space will be used.
Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 monit amd64 1:5.31.0-1 [399 kB]
Fetched 399 kB in 1s (497 kB/s)
Selecting previously unselected package monit.
(Reading database ... 330871 files and directories currently installed.)
Preparing to unpack .../monit_1%3a5.31.0-1_amd64.deb ...
Unpacking monit (1:5.31.0-1) ...
Setting up monit (1:5.31.0-1) ...
Processing triggers for man-db (2.10.2-1) ...

After the installation is complete, we can check the version with the following command monit --version.

$ monit --version
This is Monit version 5.31.0
Built with ssl, with ipv6, with compression, with pam and with large files
Copyright (C) 2001-2022 Tildeslash Ltd. All Rights Reserved.

3. Configure Monit service

To configure Monit to start on boot we use the following command sudo systemctl enable monit

$ systemctl enable monit

To start Monit immediately we use the following command.

$ sudo systemctl start monit 

To check the status of Monit we use the following command.

$ sudo systemctl status monit 
● monit.service - LSB: service and resource monitoring daemon
     Loaded: loaded (/etc/init.d/monit; generated)
     Active: active (running) since Thu 2022-08-11 08:47:50 EAT; 15min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 1 (limit: 9355)
     Memory: 2.6M
        CPU: 141ms
     CGroup: /system.slice/monit.service
             └─16979 /usr/bin/monit -c /etc/monit/monitrc

Ago 11 08:47:50 zx-pc systemd[1]: Starting LSB: service and resource monitoring>
Ago 11 08:47:50 zx-pc monit[16966]:  * Starting daemon monitor monit
Ago 11 08:47:50 zx-pc monit[16966]:    ...done.
Ago 11 08:47:50 zx-pc systemd[1]: Started LSB: service and resource monitoring >
lines 1-14/14 (END)

Conclusion

We have successfully installed and configured Monit on Ubuntu 22.04. For further reference check the Monit documentation.

Home for all your Linux tech tips

Exit mobile version