Salt States by Example | Part 1 | Install a Salt Minion on CentOS or Debian

By: rahul On: Thu 28 September 2017
In: Devops
Tags: #devops #configuration-management #linux #saltstack

Greetings Wanderer!

This is a run-down on how to create a complete Salt State. The aim of this article is to discuss how to write a complete Salt state from end-to-end. It is highly recommended that you go through the links below, which serve as an entry point into Saltstack, Saltstack installation, Saltstack configuration, Basic Saltstack commands and a few examples.

> Saltstack By Example | Part 1 | Installation
> Saltstack By Example | Part 2 | Configuration
> Saltstack By Example | Part 3 | Basic Commands
> Saltstack By Example | Part 4 | Salt State Examples

In this article, we'll aim to build a complete LEMP server AND install a Wordpress application. The process is broken down into 2 parts, which are listed below.

Objectives

1. LEMP Installation

  • Install Nginx from Nginx's repository
  • Install MySQL (5.5) on Debian-based OSes
  • Install PHP (PHP 5.6), and PHP-FPM
    • Copy a default info.php file to Nginx's default Document Root (/usr/share/nginx/html/)
    • Edit the default php.ini file
    • Edit the default www.conf
  • Configure Nginx's default configuration file (default.conf) to use PHP and PHP-FPM.
  • Configure Nginx to use virtual hosts.

2. Wordpress Installation

  • Create a new username (under /home)
  • Create the necessary sub-directories under the user's home-directory (/logs, /public_html)
  • Create a virtual host (under Nginx) for the new user
  • Download and install wpcli (system-wide)
  • Use wpcli to download and install Wordpress under /home/{username}/public_html
Prerequisites

In while the installation and configuration of a Salt Master and Salt Minion has been covered in the links above, here's a quick outline on installing a Salt Minion:

1. DEBIAN (minion)

1a. Add the Saltstack repo:

root@debianbase71:~# wget -O - https://repo.saltstack.com/apt/debian/8/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -

root@debianbase71:~# vim /etc/apt/sources.list.d/saltstack.list
#ADD THIS LINE:
deb http://repo.saltstack.com/apt/debian/8/amd64/latest jessie main

2b. Install the Salt-Minion service:

root@debianbase71:~# apt-get update
root@debianbase71:~# apt-get install salt-common salt-minion salt-ssh -y

2c. Enable and start the Minion service:

root@debianbase71:~#  systemctl enable salt-minion
Synchronizing state for salt-minion.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d salt-minion defaults
Executing /usr/sbin/update-rc.d salt-minion enable

root@debianbase71:~#  systemctl start salt-minion

2. CENTOS (minion)

2a. Install the Salt-Minion service: First, create the repo file for Saltstack, under /etc/yum.repos.d/saltstack.repo

[root@localhost ~]# vim /etc/yum.repos.d/saltstack.repo
Add the following:

[saltstack-repo]
name=SaltStack repo for Red Hat Enterprise Linux $releasever
baseurl=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest
enabled=1
gpgcheck=1
gpgkey=https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/SALTSTACK-GPG-KEY.pub
       https://repo.saltstack.com/yum/redhat/$releasever/$basearch/latest/base/RPM-GPG-KEY-CentOS-7

Now, install Salt-Minion, using yum:

[root@localhost ~]# yum install salt-minion salt-ssh -y

2b. Enable and start the Minion service:

[root@localhost ~]# systemctl enable salt-minion
Created symlink from /etc/systemd/system/multi-user.target.wants/salt-minion.service to /usr/lib/systemd/system/salt-minion.service.

[root@localhost ~]# systemctl start salt-minion

Once this is complete, enable port 4506 on the Salt Minion, add the Salt Master's IP or Hostname to the Minion's configuration file (/etc/salt/minion), restart the salt-minion service and accept the Minion's key on the Salt Master.

If you'd rather use a shell script to install Salt Minion, here's a link to an easy to use bash script:
install_salt_minion.sh

Now that we have a functional Minion(and a Salt-Master), in the next post, we'll create and analyze a complete Salt state.

EOF.


If you found the article helpful, please share or cite the article, and spread the word:


For any feedback or corrections, please write in to: rahul [at] muchbits [dot] com