In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The latest version of actual combat Latest release: 3000 (February 10, 2020)
Refer to the official documentation of saltStack
ON THE SALT MASTER
Run these commands on the system that you want to use as the central management point.
Curl-L https://bootstrap.saltstack.com-o install_salt.shsudo sh install_salt.sh-P-MYour Salt master can manage itself, so a Salt minion is installed along with the Salt master. If you do not want to install the minion, also pass the-N option.
ON EACH SALT MINION
Run these commands on each system that you want to manage using Salt.
Curl-L https://bootstrap.saltstack.com-o install_salt.shsudo sh install_salt.sh-P
The actual combat configuration server is as follows
Master 192.168.0.120 centos120 node1 192.168.0.121 centos121node2 192.168.0.122 centos122
The above three services all turn off selinux, firewalld, setup / etc/hosts, that is, they can hostname each other and access the Internet. These simple operations will not show the steps here.
1. Let's start the installation
On the master side
[root@centos120 ~] # curl-L https://bootstrap.saltstack.com-o install_salt.sh% Total% Received% Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 283k 100 283k 00 51683 00: 00:05 0:00:05--:-70732 [root@centos120 ~] # ll install_salt.sh-rw-r-- Rmure-1 root root 290571 Mar 8 13:09 install_ Salt.sh [root @ centos120 ~] # [root@centos120 ~] # sh install_salt.sh-P-M * INFO: Running version: 2020.02.24 * INFO: Executed by: sh * INFO: Command line: 'install_salt.sh-P-M' * INFO: System Information: * INFO: CPU: GenuineIntel * INFO: CPU Arch: x86 * 64 * INFO: OS Name: Linux * INFO: OS Version: 3.10.0-957.el7.x86_64 * INFO: Distribution: CentOS 7.6 * INFO: Installing minion * INFO: Installing master * INFO: Found function install_centos_stable_deps * INFO: Found function config_salt * INFO: Found function preseed_master * INFO: Found function install_centos_stable * INFO: Found function install_centos_stable_post * INFO: Found function install_centos_restart_ Daemons * INFO: Found function daemons_running * INFO: Found function install_centos_check_services * INFO: Running install_centos_stable_deps (). Installed: salt-master.noarch 0rig 3000-1.el7 salt-minion.noarch 0rig 3000-1.el7 Dependency Installed: libsodium.x86_64 0rig 1.0.18-1.el7 Libtomcrypt.x86_64 0VOR 1.17-26.el7 libtommath.x86_64 0UR 0.42.0-6.el7 openpgm.x86_64 0RU 5.2.122-2.el7 python-babel .noarch 0VOR 0.9.6-8.el7 python-backports_abc.noarch 0RU 0.5-11.el7 python-jinja2.noarch 0Ro 2.7.2-4.el7 python-markupsafe.x86_64 0:0. 11-10.el7 python-requests.noarch 0rig 2.6.0-8.el7_7 python-singledispatch.noarch 0vl 3.4.0.3-16.el7 python-six.noarch 0vir 1.9.0-2.el7 Python-urllib3.noarch 0RO 1.10.2-7.el7 python-zmq.x86_64 0RO 15.3.0-3.el7 python2-crypto.x86_64 0RO 2.6.1-16.el7 Python2-futures.noarch 0VOR 3.1.1-5.el7 python2-msgpack.x86_64 0RU 0.6.2-2.el7 python2-psutil.x86_64 0RO 5.6.7-1.el7 Salt.noarch 0UR 3000-1.el7 systemd-python.x86_64 0RU 219-67.el7_7.3 zeromq.x86_64 0RU 4.1.4-7.el7 Dependency Updated: python-setuptools.noarch 0lv 36.6.0-2.ius.el7 systemd.x86_64 0V 219-67.el7_7.3 systemd-libs.x86_64 0V 219-67.el7_7.3 Systemd-sysv.x86_64 0INFO 219-67.el7_7.3 Complete! * INFO: Running install_centos_stable_post () * INFO: Running install_centos_check_services () * INFO: Running install_centos_restart_daemons () * INFO: Running daemons_running () * INFO: Salt installed! [root@centos120 ~] #
From the above, you can know which packages are installed, and here the master side is installed successfully, that is, the management node.
Let's start installing minion nodes, that is, nodes that need to be managed (in production environments, such as web service nodes, database nodes, storage nodes, which require batch distribution of code Configure server, etc.) [root@centos121 ~] # curl-L https://bootstrap.saltstack.com-o install_ salt.sh [root @ centos121 ~] # ll install_salt.sh-rw-r--r-- 1 root root 290571 Mar 8 13:13 install_ salt.sh [root @ centos121 ~] # [root@centos121 ~] # sh install_salt.sh- P* INFO: Running version: 2020.02.24 * INFO: Executed by: sh * INFO: Command line: 'install_salt.sh-P' * INFO: System Information: * INFO: CPU: GenuineIntel * INFO: CPU Arch: x86' 64 * INFO: OS Name: Linux * INFO: OS Version: 3.10.0-957.el7.x86_64 * INFO: Distribution: CentOS 7.6 * INFO: Installing minion * INFO: Found function install_centos_stable_deps * INFO: Found function config_salt * INFO: Found function preseed_master * INFO: Found function install_centos_stable * INFO: Found function install_centos_stable_post * INFO: Found function install_centos_restart_daemons * INFO: Found function daemons_running * INFO: Found function install_centos_check_services * INFO: Running install_centos_stable_deps (). Installed: salt-minion.noarch 0VR 3000-1.el7 Dependency Installed: libsodium.x86_64 0V 1.0.18-1.el7 libtomcrypt.x86_64 0V 1.17-26.el7 libtommath .x86 _ 64 0purl 0.42.0-6.el7 openpgm.x86_64 0vir 5.2.122-2.el7 python-babel.noarch 0vir 0.9.6-8.el7 python-backports .x86 _ 640 11.el7 python-ipaddress.noarch 1.0-8.el7 python-backports-ssl_match_hostname.noarch 0V 3.5.0.1-1.el7 python-backports_abc.noarch 0V 0.5-11.el7 python-ipaddress.noarch 0v 1.0.16-2.el7 Python-jinja2.noarch 0VOR 2.7.2-4.el7 python-markupsafe.x86_64 0RU 0.11-10.el7 python-requests.noarch 0RU 2.6.0-8.el7_7 Python-setuptools.noarch 0VOR 36.6.0-2.ius.el7 python-singledispatch.noarch 0RU 3.4.0.3-16.el7 python-six.noarch 0RU 1.9.0-2.el7 Python-urllib3.noarch 0RO 1.10.2-7.el7 python-zmq.x86_64 0RO 15.3.0-3.el7 python2-crypto.x86_64 0RO 2.6.1-16.el7 Python2-futures.noarch 0VOR 3.1.1-5.el7 python2-msgpack.x86_64 0RU 0.6.2-2.el7 python2-psutil.x86_64 0RO 5.6.7-1.el7 salt.noarch 0 : 3000-1.el7 systemd-python.x86_64 0rig 219-67.el7_7.3 zeromq.x86_64 0vl 4.1.4-7.el7 Dependency Updated: systemd.x86_ 64 0INFO 219-67.el7_7.3 systemd-libs.x86_64 015 219-67.el7_7.3 systemd-sysv.x86_64 015 67.el7_7.3 Complete! * INFO: Running install_centos_stable_post () * INFO: Running install_centos_check_services () * INFO: Running install_centos_restart_daemons () * INFO: Running daemons_running () * INFO: Salt installed! [root@centos121 ~] #
Similarly, the centos122 node minion, where the installation of the minion side is complete.
3. Let's start the configuration.
What you need to know before configuration:
Brief introduction of saltstack
Saltstack is a new way of infrastructure management, a centralized management platform for server infrastructure, which can be run in a few minutes, fast enough, second communication between servers, good scalability, easy to manage tens of thousands of servers in batches, significantly reducing labor and operation and maintenance costs; it has the functions of configuration management, remote execution, monitoring and other functions, which can be understood as simplified version of puppet and enhanced version of func. Through the deployment of SaltStack environment, you can execute commands in batches on thousands of servers, configure centralized management, distribute files, collect server data, operating system foundation and software package management according to different business characteristics. SaltStack is a sharp weapon for operators to improve work efficiency and standardize business configuration and operation. SaltStack is implemented in Python language, combined with lightweight message queuing (ZeroMQ) (the communication mode of SaltStack is divided into two modes: ZeroMQ and REAT. Since REAT is not too stable at present, it usually chooses ZeroMQ mode) and Python third-party modules (Pyzmq, PyCrypto, Pyjinjia2, python-msgpack and PyYAML, etc.).
Saltstack operation mode:
Local: local, a machine to play, not recommended.
Master/Minion: managed through server/agent, with high efficiency (batch management of 1000 machines, 25 seconds).
Salt SSH: it is relatively inefficient to manage through SSH (batch management of 1000 machines, 83 seconds).
The three main functions of Saltstack:
Remote execution (remote command execution)
Configuration management (state management)
Cloud management
Saltstack characteristics:
1) simple and convenient deployment
2) support most UNIX/Linux and Windows environments
3) Master-slave centralized management
4) simple configuration, powerful function and strong expansibility
5) the main control terminal (master) and the controlled terminal (minion) are safe and reliable based on certificate authentication.
6) support API and custom modules, which can be easily extended through Python.
Master and Minion certification:
1) when minion starts for the first time, it automatically generates minion.pem (private key) and minion.pub (public key) under / etc/salt/pki/minion/ (the path is set in / etc/salt/minion), and then sends minion.pub to master.
2) after receiving the public key of minion, master uses the salt-key command accept minion public key, so that the public key named minion id will be stored under / etc/salt/pki/master/minions of master, and then master can send instructions to minion.
Connection between Master and Minion:
1) when SaltStack master starts, it listens on ports 4505 and 4506 by default. 4505 (publish_port) is the message publishing system of saltstack, and 4506 (ret_port) is the port of communication between the saltstack client and the server. If you use lsof to view port 4505, you will find that all minion remains in the ESTABLISHED state on port 4505.
2) the communication mode between minion and master is as follows:
Now start to configure
First check which files are installed on the server:
[root@centos120] # ll / etc/salt/total 132 RW-1 root root 2927 Feb 2 07:15 clouddrwx- 2 root root 6 Feb 5 02:46 cloud.conf.ddrwx- 2 root root 6 Feb 5 02:46 cloud.deploy.ddrwx- 2 root root 6 Feb 5 02:46 cloud.maps.ddrwx- 2 root root 6 Feb 5 02:46 cloud.profiles .ddrwx-2 root root 6 Feb 5 02:46 cloud.providers.d-rw-r- 1 root root 51534 Feb 2 07:15 masterdrwxr-xr-x 2 root root 6 Feb 5 02:46 master.d-rw-r- 1 root root 37370 Feb 2 07:15 miniondrwxr-xr-x 2 root root 6 Feb 5 02:46 minion.d-rw-r--r-- 1 root root 9 Mar 8 13:13 minion_ Iddrwxr-xr-x 4 root root 34 Mar 8 13:13 pki-rw-r- 1 root root 28289 Feb 2 07:15 proxydrwxr-xr-x 2 root root 6 Feb 5 02:46 proxy.d-rw-r- 1 root root 344 Feb 2 07:15 roster [root@centos120 ~] #
What files are installed on the minion side
[root@centos121] # ll / etc/salt/total 132 RW-1 root root 2927 Feb 2 07:15 clouddrwx- 2 root root 6 Feb 5 02:46 cloud.conf.ddrwx- 2 root root 6 Feb 5 02:46 cloud.deploy.ddrwx- 2 root root 6 Feb 5 02:46 cloud.maps.ddrwx- 2 root root 6 Feb 5 02:46 cloud.profiles .ddrwx-2 root root 6 Feb 5 02:46 cloud.providers.d-rw-r- 1 root root 51534 Feb 2 07:15 masterdrwxr-xr-x 2 root root 6 Feb 5 02:46 master.d-rw-r- 1 root root 37370 Feb 2 07:15 miniondrwxr-xr-x 2 root root 6 Feb 5 02:46 minion.d-rw-r--r-- 1 root root 9 Mar 8 13:45 minion_ Iddrwxr-xr-x 4 root root 34 Mar 8 13:45 pki-rw-r- 1 root root 28289 Feb 2 07:15 proxydrwxr-xr-x 2 root root 6 Feb 5 02:46 proxy.d-rw-r- 1 root root 344 Feb 2 07:15 roster [root@centos121 ~] #
Configure the master:
[root@centos120 salt] # cp-p master master.bk.20200308 [root@centos120 salt] # vi master [root@centos120 salt] # diff master master.bk.20200308 15c15
< interface: 192.168.0.120---># interface: 0.0.0.0 [root@centos120 salt] #
Configure the minion side with a total of 3 minion:
[root@centos120 salt] # cp-p minion minion.bk.20200308 [root@centos120 salt] # diff minion minion.bk.20200308 16c16
< master: 192.168.0.120---># master: salt [root@centos120 salt] # [root@centos121 salt] # cp-p minion minion.bk.20200308 [root@centos121 salt] # diff minion minion.bk.20200308 16c16
< master: 192.168.0.120---># master: salt [root@centos121 salt] # [root@centos122 salt] # cp-p minion minion.bk.20200308 [root@centos122 salt] # diff minion minion.bk.20200308 16c16
< master: 192.168.0.120---> < pillar_roots:< base:< - /srv/pillar---># pillar_roots: # base: > #-/ srv/pillar
Create the directory where the pillar files are stored:
[root@centos120 salt] # mkdir-p / srv/pillar [root@centos120 salt] # cd! $cd / srv/pillar [root@centos120 pillar] #
Create a configuration file and edit the following:
[root@centos120 pillar] # vi httpd.sls [root@centos120 pillar] # cat httpd.sls conf: / etc/httpd/conf/httpd.confservername: web1.com
Notice the space after the colon
Create and write portal configuration file, that is, top.sls file
[root@centos120 pillar] # pwd/srv/pillar [root@centos120 pillar] # vi top.sls [root@centos120 pillar] # cat top.sls base: 'centos121':-httpd [root@centos120 pillar] #
Attention-followed by a space
Restart the salt-master service
[root@centos120 pillar] # systemctl restart salt-master [root@centos120 pillar] #
You can refresh to get a new status
[root@centos120 pillar] # salt'* 'saltutil.refresh_pillarcentos121: Truecentos122: Truecentos120: True [root@centos120 pillar] #
View
[root@centos120 pillar] # salt'* 'pillar.itemscentos120:-centos121:-conf: / etc/httpd/conf/httpd.conf servername: web1.comcentos122:-[root@centos120 pillar] #
9. Saltstack configuration Management Service
1. Configure and install apache
Uncomment the following three lines and pay attention to the spaces
[root@centos120 salt] # cp-p master master.bk.20200308-3 [root@centos120 salt] # vi master [root@centos120 salt] # diff master master.bk.20200308-3657659c657659
< file_roots:< base:< - /srv/salt/---># file_roots: > # base: > #-/ srv/salt/ [root@centos120 salt] #
Create a configuration file storage directory and create an entry file
[root@centos120 ~] # mkdir / srv/salt [root@centos120 ~] # cd! $cd / srv/salt [root@centos120 salt] # vi top.sls [root@centos120 salt] # cat top.sls base: 'centos121':-apache [root@centos120 salt] #
Restart the service:
[root@centos120 salt] #! systesystemctl restart salt-master [root@centos120 salt] #
Create a configuration file for writing apache modules
[root@centos120 salt] # vi apache.sls [root@centos120 salt] # cat apache.sls apache-service: pkg.installed:-names:-httpd- httpd-devel service.running:-name: httpd- enable: True [root@centos120 salt] #
Note: line alignment-with spaces
Apache-service is the name of ID, customized. 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.
Configure the file, execute
[root@centos120 salt] # salt 'centos121' state.highstatecentos121:- ID: apache-service Function: pkg.installed Name: httpd Result: True Comment: The following packages were installed/updated: httpd Started: 18 centos121' state.highstatecentos121:- ID 43 ms Changes 58.483864 Duration: 18618.516 ms Changes:-apr: -new: 1.4.8-5.el7 old: apr-util:-new: 1.5.2-6.el7 Old: httpd:-new: 2.4.6-90.el7.centos old: httpd-tools:-new: 2.4.6-90.el7.centos old: mailcap:-new: 2.1.41-2.el7 old:- ID: apache-service Function: pkg.installed Name: httpd-devel Result: True Comment: The following packages were installed/updated: httpd-devel Started: 18True Comment: Duration: 7455.336 ms Changes:-apr-devel:-new: 1.4.8-5.el7 old: apr-util-devel:-new: 1.5.2-6.el7 old: cyrus-sasl:-- -new: 2.1.26-23.el7 old: cyrus-sasl-devel:-new: 2.1.26-23.el7 Old: expat-devel:-new: 2.1.0-10.el7_3 old: httpd-devel:-new: 2.4.6-90.el7.centos old: libdb:-new: 5.3.21-25.el7 old: 5.3.21-24.el7 Libdb-devel:-new: 5.3.21-25.el7 old: libdb-utils:-new: 5 .3.21-25.el7 old: 5.3.21-24.el7 openldap:-new: 2.4.44-21.el7_6 old: 2 .4.44-20.el7 openldap-devel:-new: 2.4.44-21.el7_6 old:- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled And is running Started: 18 TrueSummary for centos121-Succeeded 4415 Duration: 211.858 ms Changes:-httpd: TrueSummary for centos121-Succeeded: 3 (changed=3) Failed: 0-Total states run: 3Total run time: 26.286 s [root@centos120 salt] #
As can be seen from the above results, it can be successfully implemented.
Check that httpd on the executed minion is indeed installed, started, and enabled
[root@centos121 salt] # netstat-antupl | grep 80tcp6 00 grep 80tcp6:: 80 LISTEN 10233/httpd udp6 0 0 fe80::2f47:1e27:f7e:123: * 6525/ntpd [root@centos121 salt] # [root@centos121 salt] # systemctl is-enabled httpd enabled [root@centos121 salt] #
10. Configure remote file management
Create a file management module
[root@centos120 salt] # pwd/etc/salt [root@centos120 salt] # vi filecopy.sls [root@centos120 salt] # cat filecopy.sls filecopy: file.managed:-name: / tmp/test.file-source: salt://test/index.php-user: root-group: root-mode: 644 [root@centos120 salt] #
Note: the filecopy in 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 files are copied, where the test directory is equivalent to the / srv/salt/test directory; and name specifies the files to be generated by the remote client.
Create a new source file to test
[root@centos120 srv] # mkdir-p / srv/salt/test [root@centos120 srv] # echo "test salt file managed" > / srv/salt/test/index.php
Add a module to the entry file
[root@centos120 salt] # vi top.sls [root@centos120 salt] # cat top.sls base: 'centos121':-apache-filecopy [root@centos120 salt] #
Test execution
[root@centos120 salt] # salt 'centos121' state.highstatecentos121:- ID: apache-service Function: pkg.installed Name: httpd Result: True Comment: All specified packages are already installed Started: 22 apache-service Function 38 Swiss 32.908055 Duration: 760.4 ms Changes:-ID: apache-service Function: pkg.installed Name: httpd-devel Result: True Comment: All specified packages are already installed Started: 22 ms Changes 38 Duration 33.668754 Duration: 16.474 ms Changes:-ID: apache-service Function: service.running Name: True Comment: The service httpd is already running Started: 22 Duration:- ID: filecopy Function: file.managed Name: / tmp/test.file Result: True Comment: File / tmp/test.file updated Started: 22 ghetto 38 purl 33.753042 Duration: 32.348 ms Changes:-diff: New file mode: 0644Summary for centos121-Succeeded: 4 (changed=1) Failed: 0-Total states run: 4Total run time: 856.160 ms [root@centos120 salt] #
View the result
[root@centos121 ~] # ll / tmp/test.file-rw-r--r-- 1 root root 23 Mar 8 22:38 / tmp/test.file [root@centos121 ~] # cat! $cat / tmp/test.filetest salt file managed [root@centos121 ~] #
twelve。 Configure folder management:
Create a folder management module
[root@centos120 salt] # cat filedir.sls file_dir: file.recurse:-name: / tmp/testdir-source: salt://test-user: root-group: root-file_mode: 644-dir_mode: 755-mkdir: True-clean: True
Add a module to the entry file
[root@centos120 salt] # vi top.sls [root@centos120 salt] # cat top.sls base: 'centos121':-apache-filecopy-filedir [root@centos120 salt] #
Test folder management
[root@centos120 salt] # salt 'centos121' state.highstatecentos121:- ID: apache-service Function: pkg.installed Name: httpd Result: True Comment: All specified packages are already installed Started: 22 centos121' state.highstatecentos121:- ID 47 centos121' state.highstatecentos121:- ID 17.475869 Duration: 636.77 ms Changes:-ID: apache-service Function: pkg.installed Name: httpd-devel Result: True Comment: All specified packages are already installed Started: 22 Duration: 18.112930 Duration: 16.986 ms Changes:-ID: apache-service Function: service.running Name: httpd Result: True Comment: The service httpd is already running Started: 22 ID: filecopy Function: file.managed Name: / tmp/test.file Result: True Comment: File / tmp/test.file is in the correct state Started: 22 Paradise 47! 18.179219 Duration: 21.548 ms Changes:-ID: file_dir Function: file.recurse Name: / tmp/testdir Result: True Comment: Recursively updated / tmp / testdir Started: 22 ms Changes 47 ms Changes:-/ tmp/testdir/index.php:-diff: New file mode: 0644Summary for centos121-Succeeded: 5 (changed=1) Failed: 0-Total states run: 5Total run time: 807.075 ms [root@centos120 salt] #
Client checks to see if there is a / tmp/testdir directory
[root@centos121 ~] # ls-ltr / tmp/testdirtotal 4murr RWMurray / tmp/testdirtotal RWWhi-1 root root 23 Mar 8 22:47 index.php [root@centos121 ~] # saltstack remote execute commands
Create a configuration file to execute the command:
[root@centos120 salt] # vi cmd.sls [root@centos120 salt] # cat cmd.sls cmd_test: cmd.run:-unless: test-f / tmp/gnu.index-names:-touch / tmp/cmdfile.index-mkdir / tmp/cmd-user: root [root@centos120 salt] #
Note: unless: means that if the / tmp/gnu.index file does not exist, that is, the result is True, then execute the command after-name, if false is not executed; you can also use onlyif to indicate that if the / tmp/gnu.index file exists, then execute the following command; the two are just the opposite.
Add a module to the entry file
[root@centos120 salt] # vi top.sls [root@centos120 salt] # cat top.sls base: 'centos121':-apache-filecopy-filedir-cmd [root@centos120 salt] #
Test execution command
[root@centos120 salt] # salt 'centos121' state.highstatecentos121:- ID: apache-service Function: pkg.installed Name: httpd Result: True Comment: All specified packages are already installed Started: 22 pkg.installed Name 53 apache-service Function 35.762137 Duration: 635.316 ms Changes:-ID: apache-service Function: pkg.installed Name: httpd-devel Result: True Comment: All specified packages are already installed Started: 22 All specified packages are already installed Started 53 Duration 36.397764 Duration: 16.511 ms Changes:-ID: apache-service Function: service.running Name: True Comment: The service httpd is already running Started: 2215 53 Duration: 44.985 ms Changes:- ID: filecopy Function: file.managed Name: / tmp/test.file Result: True Comment: File / tmp/test.file is in the correct state Started: 22 True Comment 53 True Comment 36.463189 Duration: 21.523 ms Changes:-ID: file_dir Function: file.recurse Name: / tmp/testdir Result: True Comment: The directory / tmp / testdir is in the correct state Started: 22 ms Changes 53 cmd_test Function 36.484894 Duration: 29.106 ms Changes:-ID: cmd_test Function: cmd.run Name: touch / tmp/cmdfile.index Result: True Comment: Command "touch / tmp/cmdfile.index" run Started: 22 52 52 364 Duration: 31.084 ms Changes: -pid: 11407 retcode: 0 stderr: stdout:- ID: cmd_test Function: cmd.run Name: mkdir / tmp/cmd Result: True Comment: Command "mkdir / tmp/cmd" run Started: 22 retcode 53 Duration: 20.647 ms Changes:-pid: 11409 retcode: 0 stderr: stdout:Summary for centos121-Succeeded: 7 (changed=2) Failed: 0- -Total states run: 7Total run time: 799.172 ms [root@centos120 salt] #
View client results
[root@centos121] # ls-ltr / tmp/ | tail-2 cmd [root@centos121] # root root 0 Mar 8 22:53 cmdfile.indexdrwxr-xr-x 2 root root 6 Mar 8 22:53 cmd [root@centos121] #
14.saltstack remotely executes shell scripts
Create a profile for executing shell scripts
[root@centos120 salt] # vi shell.sls [root@centos120 salt] # cat shell.sls shell_test: cmd.script:-source: salt://test/gnu.sh-user: root [root@centos120 salt] #
Create a shell script
[root@centos120 salt] # vi test/gnu.sh [root@centos120 salt] # cat test/gnu.sh #! / bin/bashsystemctl stop httpd > > / tmp/log
Add an execution configuration to the portal file
[root@centos120 salt] # cat top.sls base: 'centos121':-shell [root@centos120 salt] #
Test execution
[root@centos120 salt] # salt 'centos121' state.highstatecentos121:- ID: shell_test Function: cmd.script Result: True Comment: Command' shell_test' run Started: 23 centos121' state.highstatecentos121:- ID 03purl 13.523069 Duration: 1064.226 ms Changes:-pid: 11703 Retcode: 0 stderr: stdout:Summary for centos121-Succeeded: 1 (changed=1) Failed: 0-Total states run: 1Total run time: 1.064 s [root@centos120 salt] #
View the result
[root@centos121 ~] # cat / tmp/log [root@centos121 ~] #
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.