Use Salt States to Create LAMP Stack and Fail2ban Across Salt minions

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $100 credit.
This credit will be applied to any valid services used during your first 60 days.

Salt States can install and define a server setup on other servers. This tutorial demonstrates the use of Salt States to create a LAMP stack across all Salt Minions.

Configure the Salt Master

Before configuration, install a Salt Master and Salt Minions with the Linode Install Salt guide. This tutorial is written for Debian 8, but can easily be adjusted for other Linux Distributions.

  1. Open the /etc/salt/master file. Then search for file_roots, optionally read the surrounding “File Server settings” section, and edit the following:

    File: /etc/salt/master
    1
    2
    3
    4
    
    # Example:
      file_roots:
        base:
          - /etc/salt/base
    Note
    Copy the above text exactly to ensure the proper two-space nesting of YAML formatting. Also notice the other possible Minion States listed under the example base file root.
  2. Create the newly listed file root directory:

    mkdir /etc/salt/base
    

The Salt Master’s configuration file has now been adjusted for a new base directory. The base directory typically contains the SLS files that create a tree like organization for Salt States pertaining to that directory. Additional directories, similar to the base directory, could be created with additional SLS files for different Salt State categories.

Create the Top and Additional SLS Files

The top file creates the top level organization for Salt States and Minions within the directory. Other SLS files typically correspond to the top file listings.

As mentioned in the note above, each of these configuration files requires specific spacing. To ensure consistency, copy the examples below, including

  1. Create the /etc/salt/base/top.sls file and add the following. Again, ensure exact formatting for the YAML two space nesting.

    File: /etc/salt/base/top.sls
    1
    2
    3
    4
    
    base:
      '*':
         - lamp
         - extras
  2. Create the /etc/salt/base/lamp.sls file referred to in Step 1, and add the following:

    File: /etc/salt/base/lamp.sls
    1
    2
    3
    4
    5
    6
    7
    
    lamp-stack:
      pkg.installed:
        - pkgs:
          - mysql-server
          - php5
          - php-pear
          - php5-mysql

    This file defines a simple Salt State using the pkg State Module. This Salt State ensures that a LAMP stack is installed across Minions.

  3. The second bullet listed in top.sls declares an extras file which will list and install additional software. Create a /etc/salt/base/extras.sls file and add the following:

    File: /etc/salt/base/extras.sls
    1
    2
    
    fail2ban:
      pkg.installed
  4. Restart the Salt Master:

    systemctl restart salt-master
    

Create the Salt State on the Minions

  1. To install the packages listed above and create a Salt State, run:

    salt '*' state.highstate
    

    This process will take a few minutes. If successful, a report will be displayed with a summary similar to the following:

    Summary
    ------------
    Succeeded: 2 (changed=2)
    Failed:    0
    ------------
    Total states run:     2
    
  2. For additional verification that the services are active on the minion, run:

    salt '*' cmd.run "service --status-all | grep 'apache2\|mysql\|fail2ban'"
    

A LAMP stack and Fail2ban Salt State has been created on all listed Salt Minions. For more information on how to configure the LAMP Stack, refer to the Salt States for Configuration of Apache, MySQL, and PHP (LAMP) guide.

This page was originally published on


Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.