Configuration Management--finally to the point.
When it comes to configuration management, it's important to understand the several concepts that are discussed below.
Salt is the state of the Minion side that is managed through a file TOP.SLS.
This file, Top.sls, is called a portal file, which records one or more environments in which a minion-side ID that needs to be managed in an environment.
And records the state that the managed Minion side needs to be matched, and the state typically has multiple states.
Say what I understand state, the state is a set of configuration, the configuration contains the Minion side needs to install the software name and set up the configuration file, salt is through the configuration file to declare. This profile name must end with a . SLS .
I understand the environment, the environment can be regarded as a large state, under the environment can go to match multiple target minion. The environment is configured in the main configuration file of the salt.
To further understand the concepts mentioned above, here are a few examples to illustrate:
The format of the salt's desired profile is in YAML format, which has been mentioned a few times before and is mentioned again below.
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/86/FC/wKioL1fQLPGhVGqsAAD_HrvY618844.png-wh_500x0-wm_3 -wmp_4-s_1707753958.png "title=" Master.png "width=", "height=" 305 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width : 750px;height:305px; "alt=" Wkiol1fqlpghvgqsaad_hrvy618844.png-wh_50 "/>
From the configuration options in the environment base, for example, you can know that the root directory of the environment Bese is
/etc/salt/stats
As mentioned above, salt is managed by the portal file to manage the state of the Minion side, so there should be a Top.sls file
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/86/FC/wKioL1fQMAKghw06AACP5L5Zli8469.png-wh_500x0-wm_3 -wmp_4-s_3492036175.png "title=" Aaa.png "width=", "height=" 313 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px ; height:313px; "alt=" Wkiol1fqmakghw06aacp5l5zli8469.png-wh_50 "/>650) this.width=650; src=" http://s4.51cto.com /wyfs02/m00/86/fc/wkiol1fqmdkzydfraacr0kg2k1e475.png-wh_500x0-wm_3-wmp_4-s_587465134.png "title=" Bbb.png "width= "Height=" "302" border= "0" hspace= "0" vspace= "0" style= "width:750px;height:302px;" alt= " Wkiol1fqmdkzydfraacr0kg2k1e475.png-wh_50 "/>
As you can see from the picture above, an environment base is declared in the Top.sls file, and the Minion end that can be matched to in this environment is all Minion;salt master will use its configured state to synchronize the configured state to the Minion host.
The statuses are:
Init.pkg
Init.limit
Init.zabbix_agent, etc.
Init.pkg means that there is a pkg.sll file in the init directory that ends with a. SLS, which records the specific status.
This init directory is relative to the root of the base environment, that is, the absolute path to the init directory is:
/etc/salt/status/init
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/86/FE/wKiom1fQN6PzJzvbAAA3xoDmFHM790.png-wh_500x0-wm_3 -wmp_4-s_282455251.png "title=" Ccc.png "width=", "height=" 252 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:252px; "alt=" Wkiom1fqn6pzjzvbaaa3xodmfhm790.png-wh_50 "/>
It is not hard to see that there are several status files in the/etc/salt/stats/init directory:
Limit.sls, Pkg.sls, Zabbix_agent.sls
When these states are declared in the portal file, there is no need to write in the file name. SLS, which is also required to comply with the regulations.
Now, have you noticed where the portal file is configured?
Also defined in the main configuration file of Salt master, see:
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/86/FE/wKiom1fQOerjGwl5AACRTZSoQWE150.png-wh_500x0-wm_3 -wmp_4-s_1607088606.png "title=" Dd.png "width=", "height=" 188 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:188px; "alt=" Wkiom1fqoerjgwl5aacrtzsoqwe150.png-wh_50 "/>
To get a good handle on salt configuration management, it is important to remember the process steps for configuration management, especially when troubleshooting:
1. Configure the required environment and the root directory of the environment under File_roots in configuration file/etc/salt/master
2. Create and configure the Top.sls file at the root of the environment to define which Minion end needs to match which environment (typically the environment directory name) executes the corresponding state
Status: Is the related state defined in the files in the environment directory that end with. SLS, for example: pgk.installed file.managed service.runing
3. In the state file declared in the Top.sls file, configure the actual state to minion the end match
4. When Minion finds the corresponding. sls file, the Minion side performs the related functions (so-called states) provided by the relevant modules defined in the file.
Again, all the configuration files about Saltstack are in YAML format, and the following points are written:
Writing one:
Www:
Pkg
-Installed
State2:
-State:states
Explain:
WWW: Defines the ID of a state, which can be customized
PKG: Represents a module in a salt
-Represents the beginning of a method in a module (PKG), here is installed
State2: Represents another module
States: Represents a specific method in another module
There must be indentation between different levels, and each level of indentation must use a format that increments 2 spaces per layer, and cannot have the TAB key
-There must be 1 spaces behind the crossbar
: Must have 1 spaces after a colon
Duplicate status cannot occur in the same ID
Two:
Pkg.init: #ID
Pkg.installed: #pkg为模块, Installed is the method
-names: #names方法 so that you can write multiple packages.
-HTTPd #软件包的名称
-Lrzsz
some things to note when writing a configuration file :
1. To use the regular in the profile Top.sls, you need to join-match:pcre
For example:
Base
' Minion (1|2). Salt.com ':
-Match:pcre #这里的参数, meaning to use regular expressions to match the above Minion end host ID
2. You can include the configured status in the current edit configuration file.
Include # can refer to configuration files for other states defined within the Top.sls file
-Init.pkg # Indicates the state in the Pkg.sls file referenced in the init directory
A simple example of building a lamp environment takes you into the world of how to write a configuration file:
Let's follow the above steps to clarify the idea of editing the configuration file.
Configure the status and its root directory in the master configuration file:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/87/38/wKioL1fYDqmB5IjeAACO5vuEFsg866.png-wh_500x0-wm_3 -wmp_4-s_4265519585.png "title=" A.png "width=", "height=" 172 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:172px; "alt=" Wkiol1fydqmb5ijeaaco5vuefsg866.png-wh_50 "/>2. Create and configure the Top.sls file under the Environment root directory defined in:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/87/3B/wKiom1fYELWibvawAAB5DC7U-dU741.png-wh_500x0-wm_3 -wmp_4-s_3442824565.png "title=" B.png "width=", "height=" 231 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:231px; "alt=" Wkiom1fyelwibvawaab5dc7u-du741.png-wh_50 "/>3. Configuring related states
First configure the status of MySQL:
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/87/4A/wKiom1fasovBGS_1AADLpDoAdF8953.png-wh_500x0-wm_3 -wmp_4-s_1094746692.png "title=" 2.png "width=" "height=" 276 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:276px; "alt=" Wkiom1fasovbgs_1aadlpdoadf8953.png-wh_50 "/>
Simple analysis:
As you can see, I configured a status in the/etc/salt/stats/lamp/mysql.sls state file to install and start the MySQL service.
Next configure the status of Apache:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/87/4A/wKiom1fanFyDpnj7AADr8ZsPEp0042.png-wh_500x0-wm_3 -wmp_4-s_2384805605.png "title=" 1.png "width=" "height=" 405 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:405px; "alt=" Wkiom1fanfydpnj7aadr8zspep0042.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/87/47/wKioL1fanHbBxForAACnnhO7WVg605.png-wh_500x0-wm_3 -wmp_4-s_907174540.png "title=" 2.png "width=" "height=" 325 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:325px; "alt=" Wkiol1fanhbbxforaacnnho7wvg605.png-wh_50 "/>
Analysis, it is not difficult to see, Apache state file Absolute path is in:
/etc/salt/stats/lamp/httpd.sls, which is then customized in the Top.sls file.
The state file defines the specific states on which the Minion side needs to be synchronized, including:
Packages that need to be installed and configuration files that need to be synchronized
4. Configure PHP, here is left to crossing you, practice it, you can use the first RPM installation.
Of course, later I will share with you how to configure the LNMP environment with salt, and when to share the compilation and installation of PHP.
5. Implementation takes effect
How do I synchronize the configured state of the master side to the Minion side?
You can use the following method:
Specify a single, specific state synchronization
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/87/4A/wKiom1fariuh2PLOAAASuoAbyL4605.png-wh_500x0-wm_3 -wmp_4-s_3472883166.png "title=" 3.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:59px; "alt=" Wkiom1fariuh2ploaaasuoabyl4605.png-wh_50 "/>
The following are the best results to return, with the results showing 2 successes, 0 failures, and a total of 2 states being synchronized.
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/87/47/wKioL1fareWwhVA-AAAPrDejvQo047.png-wh_500x0-wm_3 -wmp_4-s_1389992575.png "title=" 4.png "width=" "height=" 236 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:236px; "alt=" Wkiol1farewwhva-aaaprdejvqo047.png-wh_50 "/>
It is worth noting that the test=true meaning of the latter means testing first, not really synchronizing the state to the Minion side.
Said to be successful
2. Synchronize all the states to the Minion side
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/87/47/wKioL1farwyBOGz3AAAO_ZdhcJ4490.png-wh_500x0-wm_3 -wmp_4-s_2912479010.png "title=" 5.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:38px; "alt=" Wkiol1farwybogz3aaao_zdhcj4490.png-wh_50 "/>
After the test is complete, you can remove the test=true from the back and make a real deployment.
To deploy to those minion, look at the configuration in the Top.sls file:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/87/48/wKioL1fas8izxgt9AACZiMIq7e4182.png-wh_500x0-wm_3 -wmp_4-s_196221747.png "title=" 6.png "width=" "height=" 205 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px; height:205px; "alt=" Wkiol1fas8izxgt9aaczimiq7e4182.png-wh_50 "/>
At this point, the basic introduction of salt is shared, and will be added to the actual project
This article is from the "Watermelon Sweet" blog, please be sure to keep this source http://sharkyun.blog.51cto.com/10455795/1853017
Saltstack of operation and maintenance Automation (V) configuration management