Install apache services in batches using salt in linux

Source: Internet
Author: User
Tags fpm

Top. sls is the entry file for configuration management. Everything starts from here. On the master host, it is stored in the/srv/salt/directory by default. top. by default, sls will start parsing and executing from the base tag. The next level is the operation target, which can be matched by regular expressions, grain modules, or group names. The next level is the state file to be executed, do not change the extension.

1. Create/srv/salt/top. sls

[Root @ localhost salt] # cat top. sls
Base:
'*':
-Apache
II. Define the pillar file

[Root @ localhost pillar] # cat apache/init. sls
Apache:
{% If grains. id = "salt-minion-01" %}
Port: 8090
{% Elif grains. id = "salt-minion-02" %}
Port: 8093
{% Else %}
Port: 80
{% Endif %}
[Root @ localhost pillar] # pwd
/Srv/pillar
# Refresh pillar Data
[Root @ localhost pillar] # salt '*' saltutil. refresh_pillar
Salt '*' saltutil. refresh_pillar
Salt-minion-01:
True
Salt-minion-02:
True
# View all the values defined in pillar
[Root @ localhost salt] # salt '*' pillar. data
Salt-minion-01:
----------
Apache:
----------
Port:
8090
Salt-minion-02:
----------
Apache:
----------
Port:
8093
# View apache values
[Root @ localhost salt] # salt '*' pillar. get apache
Salt-minion-02:
----------
Port:
8093
Salt-minion-01:
----------
Port:
8090
[Root @ localhost salt] #
Pillar VS grains

Pillar defines variables on the master and grains obtains the minion value.

3. Compile an apache file

[Root @ localhost salt] # pwd
/Srv/salt
[Root @ localhost salt] # cat apache/init. sls
Apache_install:
Pkg:
-Name: httpd
-Installed

File. managed:
-Source: salt: // apache/files/httpd. conf
-Name:/etc/httpd/conf/httpd. conf
-Template: jinja
-Defaults:
Port: {salt ['pillar. Get'] ('Apache: port', 80 )}}
-Require:
-Pkg: apache_install
Service. running:
-Name: httpd
-Enable: True
-Reload: True
-Watch:
-File:/etc/httpd/conf/httpd. conf
-Pkg: apache_install
Apache_install is the ID number that can be customized.

Pkg, file, service is the state module of salt

Require: depends on a certain state. Before running this state, run the dependent state first. The dependency can have multiple

Watch: run this mode when a state changes

Port: {salt ['pillar. Get'] ('Apache: port', 80)} obtain the apache port value defined in pillar.

4. Modify the httpd. conf template file

Blob.png

After the definition is complete, you can publish the file.

5. Publish to the salt-minion node

Salt '*' state. highstate
Blob.png

Supplement:

 

1. To install multiple software packages, start multiple services. Here we take the installation of http and php-fpm software packages as an example.

[Root @ localhost apache] # cat init. sls. bak
Apache_install:
Pkg:
-Name: httpd
-Pkgs:
-Httpd
-Php-fpm
-Installed

File. managed:
-Source: salt: // apache/files/httpd. conf
-Name:/etc/httpd/conf/httpd. conf
-Template: jinja
-Defaults:
Port: 8029
-Require:
-Pkg: apache_install
Service. running:
-Name: httpd
-Enable: True
-Reload: True
-Watch:
-File:/etc/httpd/conf/httpd. conf
-Pkg: apache_install
Php-fpm:
Service. running:
-Enable: True
-Reload: True
-Watch:
-Pkg: apache_install
2. The top. sls file not only supports regular expressions, but also supports grouping and grains.

Example of regular expression matching,

Base:
'*':
-Webserver
For an example of matching by group name,-match: nodegroup is required.

Base:
Group1:
-Match: nodegroup
-Webserver
For an example of matching through the grain module,-match: grain is required.

Base:
'OS: ORA ':
-Match: grai
-Webserver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.