Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common modules and API of operation and maintenance tool SaltStack

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Common modules and API of operation and maintenance tool SaltStack

1.Archive module: implements system-level calls to compressed packages, supporting gzip, gunzip, rar, tar, unrar, unzip, etc.

Example:

# salt 'minion01' archive.gzip test.txt # compress test.txt files with gzip

2.cmd module: implement remote command line call execution (with root operation permission by default)

Example:

# salt 'minion01' cmd.run' fdisk-l' # get the hard disk information of the controlled host # salt 'minion01' cmd.script salt://script/test.py # this command first synchronizes test.py to the cache directory of the minion client and runs the script. Where script/test.py is stored in the directory specified by file_roots (default is / srv/salt (need to be created), defined in / etc/salt/master file)

3.cp module: replication of remote files and directories

Example:

# salt 'minion01' cp.get_dir salt://script/ / opt/minion/ # copy the directory under the specified location of Masterside file _ roots (default is / srv/salt) to the minion01 host / opt/minion/ directory

4.cron module: crontab operation of minion host

Example:

# salt 'minion01' cron.set_job root' *'1 / home/timesyc.sh # minion01 host root user add task job

5.dnsutil module: general DNS operation of Minion host

Example:

# salt 'minion01' dnsutil.hosts_append / etc/hosts 192.168.2.71 www.test.com # add 192.168.2.71 www.test.com to Minion01 / etc/hosts

6.file module: common file operations, including file read and write, permissions, lookup, etc.

Example:

# salt 'minion01' file.chown / mydata/data root root # modify the group and user permissions of the minion01 host / mydata/data file, which is equivalent to chown root:root / mydata/data#salt' minion01' file.copy / mydata/data / home/data # minion01 host copy / mydata/data file to the local / home/data directory # salt 'minion01' file.get_mode / mydata/data# to obtain the permission mode of the minion01 host / mydata/data, such as: 755 644#salt'* 'file.mkdir / home/test# all Minion hosts create / home/test#salt' * 'file.set_mode / home/test 075' all Minion hosts / home/test permissions mode delete the / home/test file of the minion01 host for 0755#salt' minion01' file.remove / home/test#

7.iptables module: iptables support for hosts

Example:

Salt'* 'iptables.append filter INPUT rule='-m state-- state RELATED,ESTABLISHED-j ACCEPT'salt' * 'iptables.insert filter INPUT position=3 rule='-m state-- state RELATED,ESTABLISHED-j ACCEPT'

Description: append (append) and insert (insert) iptables rules to all Minion hosts, where INPUT is the input chain

Salt'* 'iptalbes.delete filter INPUT position=3salt' * 'iptables.delete filter INPUT rule='-m state-state RELATEC,ESTABLISHED-j ACCEPT'

Description: delete the rule with chain number 3 (position=3) or rule that exists on all Minion hosts

8.network module: returns the network information of Minion hosts

Example:

# salt 'minion01' network.ping www.baidu.com # minion01 host ping domain name information

9.pkg package management module: package management, such as yum installation

Example:

# salt'* 'pkg.install httpd # all Minion host installations are equivalent to yum-y install httpd,pkg.remove for removal

10.service service module: package service management (e. G.: boot automatic startup, service restart, etc.)

Example:

# salt'* 'service.enable httpd # all Minion hosts httpd services boot self-startup script, service.disable to disable # salt' * 'service.restart httpd # all Minion hosts httpd services restart, service.reload (load), service.start (start), service.stop (stop), service.status (status)

Note: 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.

11. You can use API through the Python extension module. By calling the master client module, instantiating a LocalClient object, and then calling the cmd () method to implement

For example, API implements archive.gzip

# vim / root/archive_gzip.pyimport salt.clientclient = salt.client.LocalClient () ret = client.cmd ('*', 'archive.gzip','/root/test.txt') print ret

The execution result returns a dictionary

{'minion01':' / root/test.txt.gz'}

twelve。 Remote execution destination (target)

Common command parameters:

Globbing # specifies id to match by default

L # matches in the form of host ID list, with different host id names separated by commas

E # matching based on regular expressions of id

G # matching filtering based on grains information

I # match based on the pillar information assigned to minion by master

N # match based on grouping names in master configuration files

S # IP address or IP subnet match based on minion

C # compound matching. The above parameters can be combined.

# salt 'minion01' test.ping#salt-L' minion01,minion02' test.ping#salt-E'. * 01' test.ping#salt 'minion01' grains.items#salt' minion01' grains.get os#salt-S '192.168.2.71' test.ping#salt-C' E@m.*01 or GambiidRose minion02 'test.ping#salt' * 'pillar.get mysql

13.State built-in module

State is the core function of Saltstack. The pre-customized SLS describes (supports YAML syntax) the target state of the system (package (pkg), file (file), network configuration (network), system service (service), system user (user), etc.). This is often referred to as configuration management.

The entry file for state is the same as pillar, with the file name top.sls, but state requires that the sls file must be stored in the directory defined by Saltstack base (default is / srv/salt).

State description configuration * .sls supports jinjia templates, grains and pillar references. After the logical level definition of state is completed, it will take effect through salt'* 'state.highstate.

Available execution command

# salt'* 'state.highstate # all Minion go to Master to fetch SLS definition, and then call the corresponding state module (user,pkg,service, etc.) locally to achieve the state described by SLS. # salt-call state.highstate-l debug # outputs debug information for easy debugging.

Such as:

Apache: # ID declaration, state name: apache pkg: # management object type states:pkg, software installation (yum, apt)-installed # pkg method to be executed: install, if not installed, install service: # management object type states:service, manage system daemon-running # service method to be executed: running, start if not running-require: # keyword require Ensure that the apache service starts only after the package has been successfully installed-pkg: apache

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report