In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Grains
Grains is the information collected during minion startup, such as operating system type, network card ip, kernel version, cpu architecture, and so on.
# salt 'yw02' grains.ls lists all grains project names # salt' aming-02' grains.items lists all grains projects and values
The information of grains is not dynamic and does not change in real time, it is collected when minion starts.
We can do configuration management based on some information collected by grains.
Grains supports custom information.
Custom grains
On minion:
# vim / etc/salt/grains / / added, preceded by item and followed by value. It's all custom. Role: nginx env: test
Restart the minion service
# systemctl restart salt-minion
On master:
Get grains:
# salt'* 'grains.item role env / / you can write any item at will. If there is no one on the minion side, nothing will be displayed.
You can use the item of grains to match the corresponding host to execute tasks or commands
# salt-G role:nginx cmd.run 'hostname'
If you want to group machines, you can customize a grains.
II. Pillar
Unlike grains, pillar is defined on master and is for some information defined by minion. For example, some important data (passwords) can be stored in pillar, and variables can be defined.
Configure Custom pillar
# vim / etc/salt/master find the following configuration: / / remove the previous # pillar_roots: / / can be considered as the next configuration project. Base: # there are two spaces in front of this line, and its value in the project is called base. -/ srv/pillar # there are four spaces before this line, and the value in value is called / srv/pillar. Restart master / / the service needs to be restarted only if / etc/salt/master is modified. Later, just refresh the pillar configuration. # systemctl restart salt-master # mkdir / srv/pillar# vim / srv/pillar/test.sls / / sub-configuration file, the content is as follows. The configuration file of saltstack usually uses sls as the suffix name, which is easy to distinguish. The contents of conf: / etc/123.conf # vi / srv/pillar/top.sls / / are as follows, and this top.sls file serves as a general entry. Base: # base indicates that this is a root 'yw02': # this line is preceded by two spaces for the hostname of the machine. -test # this line is preceded by four spaces, indicating which configuration file to load. -equivalent to the nature of a separator. -test1 # write multiple lines' fuxi01': # can also write multiple machines-the format of the test2 file must be noted that there are two gear in front of the machine and four spaces in the corresponding configuration file.
When you have changed the pillar configuration file, get the new pillar status by refreshing the pillar configuration:
# salt'* 'saltutil.refresh_pillar verification: # salt' * 'pillar.item conf
Pillar can also be used to match the corresponding host.
Such as salt-I 'conf:/etc/123.conf' test.ping;salt-I' conf:/etc/123.conf' cmd.run w
3. Install and configure httpd
On master
# vi / etc/salt/master / / search to find file_roots and open a comment on the following: file_roots: base: # there are two spaces in front of-/ srv/salt # there are four spaces in front of # mkdir / srv/salt Cd / srv/salt# vi / srv/salt/top.sls / / defines the main entry, adding the following base:'*': # preceded by two spaces,-httpd # preceded by four spaces # systemctl restart salt-master
The'* 'means that the httpd module is executed on all minion clients, or you can write a separate machine.
On master
# vi / srv/salt/httpd.sls / / add the following, which is the content of the httpd module httpd-service: # the service name defined by pkg.installed: # salt comes with the module, similar to cmd.run. -names: # is followed by the name of the package to be installed. If there is only one service here, it can be written as-name: httpd no longer need to change a line. -httpd- httpd-devel service.running: # the purpose of this module is to start the service. -name: httpd # starts the service httpd-enable: True # True means to start, but false does not start.
Description: httpd-service is the name of id, custom. Pkg.installed is the package installation function. Here is the name of the package to be installed. Service.running is also a function to ensure that the specified service is started, and enable means boot.
Execution: salt 'yw02' state.highstate / / the execution process will be slow, because on the client side, as long as the state.highstate command is executed, it will go to the / srv/salt directory to find top.sls, and all the relevant modules mentioned in this configuration file will be executed.
After # ls / lib/systemd/system/httpd.service / / is installed, you will have a package for this service.
IV. Configuration management files
On master
# vi / srv/salt/test.sls / / add the following content: file_test: file.managed: # module referenced-name: / tmp/aminglinux.com # the file path to be given to the minion side-source: salt://test/123/1.txt-user: root # file to its master group and permissions after the past. -group: root-mode: 600
Description: the file_test on the first line is a custom name, indicating the name of the configuration segment, which can be referenced in other configuration segments. Source specifies where the file is copied from, the source file, where the salt://test/123/1.txt is equivalent to / srv/salt/test/123/1.txt,salt://, which represents the root path / srv/salt defined by file_roots in the / etc/salt/master file.
Function: for example, for a group of machines, change the configuration file of a service, first get the template of the modified configuration file, and then tell the minion to which directory the file is to be distributed to. After distribution, you may have to do some other operations, such as restarting the service.
# mkdir / srv/salt/test/123# cp / etc/passwd / srv/salt/test/123/1.txt# vi / srv/salt/top.sls / / because salt is looking for top.sls by default, which is the main entry. Top will tell us which sub-configuration file to find next. So here we have to change it to test:base:'*':-test # salt 'yw02' state.highstateyw02:- ID: file_test Function: file.managed Name: / tmp/aminglinux.com Result: True Comment: File / tmp/aminglinux.com updated Started: 19 salt 37 Duration: 591.057 ms Changes:-- -diff: New fileSummary for yw02-Succeeded: 1 (changed=1) Failed: 0-Total states run: 1Total run time: 591.057 ms
Check to see if there is / tmp/aminglinux.com on yw02, check the content and permissions.
V. configuration management directory
On master
# vi / srv/salt/test_dir.sls / / add the following content file_dir: file.recurse: # module-name: / tmp/testdir # directory of the other machine-source: salt://test/123 # template directory-user: root # to the past directory, File owner and permissions-file_mode: 640-dir_mode: 750-mkdir: True-clean: True # # after adding it Delete the source file or directory, and the destination will also be deleted, otherwise it will not be deleted.
Modify top.sls
# vi / srv/salt/top.sls / / add test_dirbase:'*':-test_dir # salt 'yw02' state.highstate
Check whether / tmp/testdir is available on yw02, and check the directories, files, and permissions in it.
Note: a feature of saltstack, if there is an empty directory in the directory corresponding to source, it will not be synchronized on the client side, it will think that this is useless.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.