In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly analyzes how to analyze the common modules of Saltstack and the relevant knowledge points of API, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor to have a look, and follow the editor to learn more about "how to analyze the common modules of Saltstack and API".
Description salt'* 'sys.list_modules # lists the modules supported by the current version
The API principle is realized by calling the master client module, instantiating a LocalClient object, and then calling the cmd () method.
The following example of API implementing test.ping: (other API calls only need to change cmd)
# using gunzip to extract sourcefile.txt.gz package salt'* 'archive.gunzip sourcefile.txt.gz# using gzip to compress sourcefile.txt file salt' * 'archive.gzip sourcefile.txt
API call:
Client.cmd ('*', 'archive.gunzip', [' sourcefile.txt.gz']) cmd module
Function: remote command line call execution (root operation permission is available by default, and risk assessment is required when using it)
Example:
# get the memory usage of the host you want to be accused of salt'* 'cmd.run' free-wx # run the test.py script on the wx host, where script/test.py is stored in the directory specified by file_roots (default is / srv/salt, custom defined in / etc/salt/master file). # this command will do two actions: first synchronize test.py to the cache directory of minion Get up and run the script salt 'wx' cmd.script salt://script/test.py
API call:
Client.cmd ('*', 'cmd.run', [' free-m']) cp module
Function: copy remote files and directories, and download URL files
Example:
Client.cmd ('*', 'cp.get_file', [' salt://script/test.py','/minion/test.py']) cron module
Function: realize the crontab operation of the controlled host
Example:
Client.cmd ('wx','cron.set_job', [' root','*',1,'/usr/local/weekly']) dnsutil module
Function: to realize the general DNS operation of the controlled host
Example:
# add the host configuration item salt 'wx' dnsutil.hosts_append / etc/hosts 127.0.0.1 adl.yuk.com,ad2.yuk.com# of the specified controlled host hosts and delete the host configuration item salt' wx' dnsutil.hosts_remove / etc/hosts ad1.yuk.com of the hosts of the specified controlled host
API call:
Clietn.cmd ('wx','dnsutil.hosts_append', [' / etc/hosts','127.0.0.1','ad1.yuk.com','ad2.yuk.com']) file module
Functions: common file operations of the controlled host, including file read and write, permissions, search and verification
Example:
Client.cmd ('*', 'file.remove', [' / tmp/foo']) iptables module
Function: iptables support of the controlled host
Example:
Client.cmd ('*', 'iptables.append', [' filter','INPUT','rule=\'- p tcp-- sport 80-j ACCEPT\']) network module
Function: return the network information of the controlled host
Example:
Client.cmd ('wx','network.ip_addrs') pkg package Management Module
Function: package management of the controlled host, such as yum, apt-getdegn
Example:
Client.cmd ('*', 'pkg.remove', [' php']) service service module
Function: package service management of the controlled host
Example:
Client.cmd ('*', 'service.stop', [' nginx']) other modules
In addition to the above modules, saltstack also provides user (system user module), group (system group module), partition (system partition module), puppet (puppet management module), system (system restart and shutdown module), timezone (time zone management module), nginx (nginx management module), mount (file system mount module) and so on. Of course, we can also use the Python extension module to meet the needs.
This is the end of the introduction on "how to analyze Saltstack common modules and API". More related content can be searched for previous articles, hoping to help you answer questions and questions, please support the website!
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.