SaltStack is a powerful automation and configuration management software that allows you to manage your infrastructure from a centralized location. In this article, we will guide you through the process of installing and configuring SaltStack Master and Minion on Debian 11. By the end of this tutorial, you will be able to control and manage your minions effortlessly.
Prerequisites
Before we begin, make sure you have the following:
- Two servers running Debian 11
- Root password configured on both servers
Install Saltstack Master
By default, SaltStack is not included in the Debian 11 default repository. To add the SaltStack repository to APT, execute the following command:
curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/debian/11/amd64/latest/salt-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/debian/11/amd64/latest bullseye main" | tee /etc/apt/sources.list.d/salt.list
Once the repository is added, update the repository cache:
apt-get update -y
Next, install the required dependencies:
apt-get install python3 salt-common -y
Finally, install the SaltStack master:
apt-get install salt-master -y
Configure Saltstack Master
After the successful installation of SaltStack Master, proceed with the configuration. Open the SaltStack configuration file:
nano /etc/salt/master
Locate the line that begins with interface
and change it to the following:
interface: 0.0.0.0
Save and close the file. Then, restart the SaltStack master:
systemctl restart salt-master
To verify the status of the SaltStack master, execute the following command:
systemctl status salt-master
You should see output similar to the following:
? salt-master.service - The Salt Master Server
Loaded: loaded (/lib/systemd/system/salt-master.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-12 07:39:48 UTC; 9s ago
Docs: man:salt-master(1)
file:///usr/share/doc/salt/html/contents.html
https://docs.saltproject.io/en/latest/contents.html
Main PID: 19403 (salt-master)
Tasks: 32 (limit: 2341)
Memory: 201.5M
CPU: 6.109s
CGroup: /system.slice/salt-master.service
??19403 /usr/bin/python3 /usr/bin/salt-master
??19407 /usr/bin/python3 /usr/bin/salt-master
??19431 /usr/bin/python3 /usr/bin/salt-master
??19434 /usr/bin/python3 /usr/bin/salt-master
??19435 /usr/bin/python3 /usr/bin/salt-master
??19436 /usr/bin/python3 /usr/bin/salt-master
??19437 /usr/bin/python3 /usr/bin/salt-master
??19444 /usr/bin/python3 /usr/bin/salt-master
??19445 /usr/bin/python3 /usr/bin/salt-master
??19446 /usr/bin/python3 /usr/bin/salt-master
??19448 /usr/bin/python3 /usr/bin/salt-master
??19451 /usr/bin/python3 /usr/bin/salt-master
??19454 /usr/bin/python3 /usr/bin/salt-master
Feb 12 07:39:48 debian11 systemd[1]: Starting The Salt Master Server...
Feb 12 07:39:48 debian11 systemd[1]: Started The Salt Master Server.
Install and Configure Saltstack Minion
With the SaltStack Master installed and configured, it’s time to install the SaltStack Minion on another machine. Start by adding the SaltStack Minion repository:
curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/debian/11/amd64/latest/salt-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/debian/11/amd64/latest bullseye main" | tee /etc/apt/sources.list.d/salt.list
Update the repository cache:
apt-get update -y
Install the SaltStack Minion:
apt-get install salt-minion -y
After the successful installation, edit the SaltStack Minion configuration file:
nano /etc/salt/minion
Locate the line that begins with master
and replace salt-master-ip
with the IP address of your SaltStack Master.
master: salt-master-ip
Save and close the file. Then, authenticate the Minion using the master’s public fingerprint. On the Salt Master machine, list all fingerprints:
salt-key --finger-all
Copy the master.pub
fingerprint and add it to the Minion configuration file:
nano /etc/salt/minion
Add the master fingerprint as shown below:
master_finger: '5e:4f:2b:37:41:cc:4b:9c:b0:ed:cb:0a:fb:c7:59:54:5f:11:34:ab:d2:99:96:c1:e7:ef:4d:95:b0:7c:d3:d1'
You also need to define the name of the Minion:
id: Minion1
Save and close the file. Then, restart the SaltStack Minion:
systemctl restart salt-minion
To verify the status of the SaltStack Minion, execute the following command:
systemctl status salt-minion
You should see output similar to the following:
? salt-minion.service - The Salt Minion
Loaded: loaded (/lib/systemd/system/salt-minion.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-12 07:46:04 UTC; 7s ago
Docs: man:salt-minion(1)
file:///usr/share/doc/salt/html/contents.html
https://docs.saltproject.io/en/latest/contents.html
Main PID: 2324 (salt-minion)
Tasks: 8 (limit: 2341)
Memory: 59.9M
CPU: 1.185s
CGroup: /system.slice/salt-minion.service
??2324 /usr/bin/python3 /usr/bin/salt-minion
??2326 /usr/bin/python3 /usr/bin/salt-minion
??2328 /usr/bin/python3 /usr/bin/salt-minion
Feb 12 07:46:04 debian11 systemd[1]: Starting The Salt Minion...
Feb 12 07:46:04 debian11 systemd[1]: Started The Salt Minion.
You can also check the minion fingerprint using the following command:
salt-call key.finger --local
On the SaltStack Master machine, match the fingerprint using the following command:
salt-key --finger-all
Accept the Minion on the SaltStack Master:
salt-key -a Minion1
Finally, verify the connection between the Master and Minion:
salt Minion1 test.ping
If the connection is successful, you should see Minion1: True
as the output.
Control Minions from the Master
Now that the connection between the Master and Minion is established, let’s explore how to control the minions from the master.
To list the available disk space on the Minion, run the following command on the master:
salt '*' disk.usage
This will display information about the disk usage on the Minion.
To install the Apache package on the Minion, execute the following command on the master:
salt Minion1 pkg.install apache2
This will install the Apache package on the Minion.
To check the free memory on the Minion, run the following command on the master:
salt '*' cmd.run 'free -m'
This will display information about the free memory on the Minion.
Use Salt State File to Manage Minions
Salt State Files are powerful tools for configuring and managing minions. Let’s create a state file to install PHP, UNZIP, and Apache packages on the minions.
First, create the environment base for SaltStack:
mkdir /src/salt
Next, create a state file for the setup:
nano /src/salt/setup.sls
Add the following code to the file:
network_utilities: pkg.installed: - pkgs: - php - unzip apache2_pkg: pkg.installed: - name: apache2 apache2_service: service.running: - name: apache2 - enable: True - require: - pkg: apache2_pkg
Save and close the file.
To apply the configuration to all minions, use the following command on the master:
salt '*' state.apply setup
This will install PHP, UNZIP, and Apache packages on all minions.
Conclusion
Congratulations! You have successfully installed and configured SaltStack Master and Minion on Debian 11. You have also learned how to control and manage minions from the master using Salt State Files and command-line instructions. With SaltStack, you can efficiently automate and manage your infrastructure from a centralized location. If you have any further questions or need assistance, feel free to reach out to the Shape.host team, a reliable provider of Linux SSD VPS services.