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

Saltstack for automatic operation and maintenance (1) installation and common methods

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Software environment:

[root@localhost ~] # cat / etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@localhost ~] # uname-aLinux localhost.localdomain 3.10.0-514.el7.x86_64 # 1 SMP Tue Nov 22 16:42:41 UTC 2016 x86'64 GNU/Linux [root@localhost ~] #

(1) modify the selinux configuration file:

[root@localhost ~] # vim / etc/sysconfig/selinux SELINUX=enforcing changed to SELINUX=disabled

(2) turn off the firewall:

[root@localhost] # systemctl disable firewalld [root@localhost ~] # systemctl stop firewalld [root@localhost ~] # iptables-F [root@localhost ~] # iptables-L

The IP allocation is as follows:

Master 192.168.112.140

Minion 192.168.112.141

Minion 192.168.112.142

(3) deployment and installation of master and Minion

The master side executes:

[root@localhost ~] # yum install epel-release [root@localhost ~] # yum install-y salt-master

The minion side executes:

[root@localhost ~] # yum install epel-release [root@localhost ~] # yum install salt-minion

(4) modify the configuration file:

[root@localhost ~] # vim / etc/salt/minion master: 192.168.112.140id: server02 [root@localhost ~] # [root@localhost ~] # systemctl start salt-minion [root@localhost ~] # ps-ef | grep salt-minionroot 2505 12 23:06? 00:00:00 / usr/bin/python / usr/bin/salt-minionroot 2508 2505 8 23:06? 00:00:00 / usr/bin/python / usr/bin / salt-minionroot 2536 2318 0 23:06 pts/0 00:00:00 grep-- color=auto salt-minion [root@localhost ~] # netstat-lnupt | grep 4505tcp 00 0.0.0.0grep 4505 0.0.0.0grep * LISTEN 2304/python [root@localhost ~] # [root@localhost ~] # vim / etc/salt/minionmaster: 192.168 .112.140id: server03 [root@localhost ~] # [root@localhost ~] # systemctl start salt-minion [root@localhost ~] # ps-ef | grep salt-minionroot 2487 11 23:05 / usr/bin/python / usr/bin/salt-minionroot 2490 2487 4 23:06? 00:00:00 / usr/bin/python / usr/bin/salt-minionroot 2521 2320 0 23:06 pts/0 00:00 : 00 grep-- color=auto salt-minion [root@localhost] # [root@localhost ~] # [root@localhost ~] #

(5) set salt-master and salt-minion to boot

[root@localhost] # systemctl enable salt-masterCreated symlink from / etc/systemd/system/multi-user.target.wants/salt-master.service to / usr/lib/systemd/system/salt-master.service. [root@localhost ~] # [root@localhost ~] # systemctl enable salt-minionCreated symlink from / etc/systemd/system/multi-user.target.wants/salt-minion.service to / usr/lib/systemd/system/salt-minion.service. [root@localhost ~] #

2. Configure saltstack authentication

Salt-key / / View signed clients

Salt-key-a / / signature specified host

Salt-key-A / / sign all hosts

Salt-key-d / / Delete the signature of the specified host

Salt-key-- help / / View the usage of each command

[root@localhost] # salt-key Accepted Keys:Denied Keys:Unaccepted Keys:server02server03Rejected Keys: [root@localhost ~] # [root@localhost ~] # salt-key-a server02The following keys are going to be accepted:Unaccepted Keys:server02Proceed? [root@localhost ~] # [root@localhost ~] # salt-key Accepted Keys:server02server03Denied Keys:Unaccepted Keys:Rejected Keys: [root@localhost ~] #

3. Daily usage

Test.ping users check the network connectivity from master to minion. If True is returned, it is normal, and False is abnormal.

[root@localhost ~] # salt'* 'test.pingserver02: Trueserver03: True [root@localhost ~] #

Cmd.run executes shell commands on the minion side, remembering that this module can only execute short connection commands, such as df commands; long connections cannot return results, such as top commands

[root@localhost ~] # salt'* 'cmd.run' hostname'server03: localhost.localdomainserver02: localhost.localdomain [root@localhost ~] # salt'* 'cmd.run' df-Th'server02: Filesystem Type Size Used Avail Use% Mounted on / dev/sda3 xfs 90G 1.8G 89G 2% / devtmpfs devtmpfs 231M 0231m 0% / devtmpfs tmpfs 241m 12K 241m 1% / dev/shm tmpfs tmpfs 241M 4.6M 236m 2% / run tmpfs tmpfs 241M 0 241M 0% / sys/fs/cgroup / dev/sda1 xfs 1014M 131M 884M 13% / boot tmpfs tmpfs 49M 049M 0% / run/user/0server03: Filesystem Type Size Used Avail Use% Mounted on / dev/sda3 Xfs 90G 1.8G 89G 2% / devtmpfs devtmpfs 231M 0 231M 0% / devtmpfs tmpfs 241M 12K 241M 1% / dev/shm tmpfs tmpfs 241M 4.6M 236M 2% / run tmpfs tmpfs 241M 0241M 0% / sys/fs/cgroup / dev/sda1 xfs 1014M 131M 884M 13% / boot tmpfs Tmpfs 49m 049m 0% / run/user/0 [root@localhost ~] #

Displays the operating system type of the controlled host

[root@localhost ~] # salt'* 'grains.item osserver02:-os: CentOSserver03:-os: CentOS [root@localhost ~] #

Remote code execution test

(1) (wildcard * match)

[root@localhost] # salt'* 'cmd.exec_code python' import sys;print sys.version'server02: 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] server03: 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] [root@localhost ~] #

(2) regular matching

[root@localhost] # salt-E 'server (02 | 03)' test.pingserver03: Trueserver02: True [root@localhost ~] #

(3) list matching

[root@localhost ~] # salt-L 'server02,server03' test.pingserver02: Trueserver03: True [root@localhost ~] #

(4) grains match, its command salt grains.items

[root@localhost] # salt 'server02' grains.itemsserver02:-SSDs: biosreleasedate: 07 fpu 31 fpu cpu_flags:-fpu-vme-de-pse-tsc-msr-pae-mce-cx8-apic -sep-mtrr-pge-mca-cmov-pat-pse36-clflush-dts-mmx-fxsr-sse-sse2-ss-ht-syscall-nx-rdtscp-lm-constant _ tsc-arch_perfmon-pebs-bts-nopl-xtopology-tsc_reliable-nonstop_tsc-aperfmperf-eagerfpu-pni-pclmulqdq-ssse3-cx16-pcid-sse4_1-sse4_2-x2apic-popcnt -xsave-avx-f16c-hypervisor-lahf_lm-arat-epb-pln-pts-dtherm-fsgsbase-smep-xsaveopt cpu_model: Intel (R) Core (TM) i3-3220 CPU @ 3.30GHz cpuarch: x86 / 64 domain: Fqdn: server02 fqdn_ip4:-192.168.112.141 fqdn_ip6: -:: 1 gpus: | _-model: SVGA II Adapter vendor: unknown host: server02 hwaddr_interfaces:- Eth0: eth0: server02 init: systemd ip4_interfaces:-eth0:-192.168.112.141 lo:-127.0.0.1 Ip6_interfaces:-eth0: lo: ip_interfaces:-eth0:-192.168.112.141 lo:-127.0.0.1 ipv4:-127.0.0.1-192.168.112.141 ipv6: Kernel: Linux kernelrelease: 3.10.0-514.el7.x86_64 locale_info:-defaultencoding: UTF-8 defaultlanguage: en_US detectedencoding: UTF-8 localhost: server02 lsb_distrib_id: CentOS Linux machine_id: 09e12c5f3a7948af9747ee938feee87f manufacturer: VMware Inc. Master: 192.168.112.140 mdadm: mem_total: 480 nodename: server02 num_cpus: 4 num_gpus: 1 os: CentOS os_family: RedHat osarch: x86_64 oscodename: Core osfinger: CentOS Linux-7 osfullname: CentOS Linux osmajorrelease: 7 osrelease: 7.3.1611 osrelease_info:-7-3-1611 path: / usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin productname: VMware Virtual Platform ps: ps-efH pythonexecutable: / usr/bin/python pythonpath:-/ usr/bin- / usr/lib64/python27.zip-/ usr/lib64/python2.7-/ usr/lib64/python2.7/plat-linux2-/ usr/lib64/python2.7/lib-tk-/ usr/lib64/python2.7/lib-old-/ usr/lib64/python2.7/lib-dynload-/ usr/lib64/python2.7/site-packages-/ usr / lib64/python2.7/site-packages/gtk-2.0-/ usr/lib/python2.7/site-packages pythonversion:-2-7-5-final-0 saltpath: / usr/lib/python2.7/site-packages/salt saltversion: May 10, 2015 saltversioninfo:-2015-5- 10-0 selinux:-enabled: False enforced: Disabled serialnumber: VMware-56 4d 19 57 3D 1d 44 0d-99 bf 1a ff c4 0b 28 95 server_id: 1264512667 shell: / bin/sh systemd:-features: + PAM + AUDIT + SELINUX + IMA-APPARMOR + SMACK + SYSVINIT + UTMP + LIBCRYPTSETUP + GCRYPT + ACL + XZ-LZ4-SECCOMP + BLKID + ELFUTILS + KMOD + IDN version: 219 virtual: VMware zmqversion: 3.2.5 [root@localhost] #

If you want to get a specific item, you can add the item name directly after the command, such as the operating system, then:

[root@localhost] # salt-L 'server02,server03' grains.item osserver03:-os: CentOSserver02:-os: CentOS [root@localhost ~] #

You can also get the corresponding values of host, ip_interfaces, fqdn_ipv4 and cpu_model:

[root@localhost ~] # salt 'server02' grains.item hostserver02:-host: server02 [root@localhost ~] # [root@localhost ~] # salt' server02' grains.item ip_interfacesserver02:-ip_interfaces:-eth0:-192.168.112.141 lo :-127.0.0.1 [root@localhost ~] # [root@localhost ~] # salt 'server02' grains.item fqdn_ip4server02:-fqdn_ip4:-192.168.112.141 [root@localhost ~] # [root@localhost ~] # salt' server02' grains.item cpu_modelserver02:-cpu_model: Intel (r) Core (TM) i3-3220 CPU @ 3.30GHz [root@localhost ~] #

4. Introduction of common modules

(1), cp module (to copy remote files and directories, and download URL files, etc.)

# copy the directory under the location specified by the master server file_roots to the controlled host

Open the

# file_roots:

Base:

-/ srv/salt

Change to:

File_roots:

Base:

-/ srv/salt

# salt'* 'cp.get_dir salt://test_dir / data

Salt://-> indicates the path specified by file_root, where / srv/salt,salt://test_dir represents / srv/salt/test_dir

/ data-> indicates the data directory under the root directory on the target host

[root@localhost ~] # ll / srv/salt/test_dir/total 672 root@localhost-1 root root 686011 May 7 22:37 nginx-1.0.10.tar.gz [root@localhost ~] # salt'* 'cp.get_dir salt://test_dir / dataserver02:-/ data/test_dir/nginx-1.0.10.tar.gzserver03:-/ data/test_dir/nginx-1.0.10.tar.gz [ Root@localhost ~] # salt'* 'cmd.run' ls-l / data'server03: total 0 drwxr-xr-x 2 root root 33 Jun 1 02:12 test_dirserver02: total 0 drwxr-xr-x 2 root root 33 Jun 1 02:12 test_ dirt [root @ localhost ~] #

# copy the files under the location specified by the master server file_roots to the controlled host

# salt'* 'cp.get_file salt://nginx-1.0.10.tar.gz / root/nginx-1.0.10.tar.gz

[root@localhost salt] # salt'* 'cp.get_file salt://nginx-1.0.10.tar.gz / root/nginx-1.0.10.tar.gzserver02: / root/nginx-1.0.10.tar.gzserver03: / root/nginx-1.0.10.tar.gz [root@localhost salt] # salt' * 'cmd.run' ls-l / root/'server02: total 676-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gzserver03: total 1496-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz [root@localhost salt] #

For large files, cp_get_file supports gzip compression. Specify the compression level of gzip in the parameters, as follows:

[root@server01 salt] # pwd/srv/salt [root@server01 salt] # ll-th test-rw-r--r-- 1 root root 1.0G Jun 13 22:04 test [root@server01 salt] # salt'* 'cp.get_file salt://test / root/test gzip=5server02: / root/testserver03: / root/test [root@server01 salt] # [root@server01 salt] # salt' * cmd.run'ls-htl / root/test'server02:-rw -root root Murray-1 root root 1.0G Jun 13 22:06 / root/testserver03:-rw-r--r-- 1 root root 1.0G Jun 13 22:06 / root/test [root@server01 salt] #

Where 1 represents minimum compression, 9 represents maximum compression, and the gzip parameter compresses the file during transfer.

Cp.get_file does not establish a directory on the client by default. If there is no such directory on the client, the file copy will fail, so there is another parameter makedirs. When the target directory on the client does not exist, set the value of this parameter to True, that is, makedirs=True.

[root@server01 salt] # salt'* 'cmd.run' ls-l / root/'server02: total 1049372-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 260 Jun 5 22:08 connect.py-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz-rw-r--r-- 1 root root 1073741824 Jun 13 22:06 test drwxr-xr-x 2 root root 33 Jun 13 22:54 webserver03 Total 1049368-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz-rw-r--r-- 1 root root 1073741824 Jun 13 22:06 test drwxr-xr-x 2 root root 33 Jun 13 22:54 web [root@server01 salt] # [root@server01 salt] # salt'* cp.get_file salt:// Nginx-1.0.10.tar.gz / root/web/nginx-1.0.10.tar.gz makedirs=Trueserver02: / root/web/nginx-1.0.10.tar.gzserver03: / root/web/nginx-1.0.10.tar.gz [root@server01 salt] # [root@server01 salt] # salt'* 'cmd.run' ls-l / root/'server02: total 1049372-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 260 Jun 5 22:08 connect.py-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz-rw-r--r-- 1 root root 1073741824 Jun 13 22:06 test drwxr-xr-x 2 root root 33 Jun 13 22:54 webserver03 Total 1049368-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz-rw-r--r-- 1 root root 1073741824 Jun 13 22:06 test drwxr-xr-x 2 root root 33 Jun 13 22:54 web [root@server01 salt] #

Note: cp.get_file can literally see that the operation object is a file, that is, it is useful to use the makedirs parameter only if the corresponding directory on the target host does not exist when copying the file, otherwise the parameter is invalid.

# download the specified URL content to the specified location of the controlled host

Salt'* 'cp.get_url http://dl.fedoraproject.org/pub/epel/6/x86_64/GeoIP-1.6.5-1.el6.x86_64.rpm / root/GeoIP-1.6.5.-1.e16.x86_64.rpm

Cp.get_url downloads the file according to the specified url address to the corresponding directory of the host of the controlled side, here under the directory / root/ of the controlled side

[root@localhost salt] # salt'* 'cmd.run' ls-l / root/'server02: total 676-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gzserver03: total 1496-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz [root@localhost salt] # salt'* 'cp.get_url http://dl.fedoraproject.org/pub/epel/6/x86_64/GeoIP-1.6.5-1.el6.x86_64.rpm / root/GeoIP-1.6.5.-1.e16.x86_64 .rpmserver03: / root/GeoIP-1.6.5.-1.e16.x86_64.rpmserver02: / root/GeoIP-1.6.5.-1.e16.x86_ 64.rpm [root @ localhost salt] # salt'* 'cmd.run' ls-l / root/'server02: total 792-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gzserver03: total 1496-rw-r--r-- 1 root root 115316 Jun 1 02:26 GeoIP-1.6.5.-1.e16.x86_64.rpm-rw-. 1 root root 1496 Jan 17 09:03 anaconda-ks.cfg-rw-r--r-- 1 root root 686011 Jun 1 02:15 nginx-1.0.10.tar.gz [root@localhost salt] #

Of course, URL can also be a path on master (salt://)

[root@server01 salt] # salt'* 'cp.get_url salt://nginx-1.0.10.tar.gz / opt/nginx-1.0.10.tar.gzserver02: / opt/nginx-1.0.10.tar.gzserver03: / opt/nginx-1.0.10.tar.gz [root@server01 salt] # salt' * 'cmd.run' ls-l / opt'server02: total 672-rw-r--r-- 1 root root 686011 Jun 13 23:05 nginx-1.0.10.tar.gzserver03: total 672-rw-r--r-- 1 root root 686011 Jun 13 23:05 nginx-1.0.10.tar.gz [root@server01 salt] #

# salt'* 'cp.hash_file salt://test-file

Cp.hash_file acquires the hash value of a file sent from the main control terminal to the controlled terminal, which is generally used to compare the hash value of a file on a controlled terminal.

[root@localhost ~] # salt'* 'cp.hash_file salt://nginx-1.0.10.tar.gzserver02:-hash_type: md5 hsum: 930b297b00fa1018fb0a1dd3e6b7e17eserver03:-hash_type: md5 hsum: 930b297b00fa1018fb0a1dd3e6b7e17e [root@localhost ~] #

(2), cmd module (to implement remote command line call execution)

# salt'* 'cmd.run' netstat-ntlp'

[root@localhost salt] # salt'* 'cmd.run' netstat-lnupt'server02: Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0 cmd.run 22 0.0.0 * LISTEN 1184/sshd tcp 0 0 127.0.0.1 LISTEN 2013/master tcp6 25 0.0.0.0 LISTEN 2013/master tcp6 0: 22:: * LISTEN 1184/sshd tcp6 0 0:: 1:25:: * LISTEN 2013/master udp 0 0 0.0.0.0 672/chronyd 32525 0.0.0.0 672/chronyd * 737/dhclient udp 0 0 127.0.1 Udp 0 0 0.0.0.0 737/dhclient udp6 68 0.0.0:: 1 672/chronyd udp6 0 0: 14472:: * 737/dhclientserver03: Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0 only servers 22 0.0.0.0 LISTEN 1191/sshd Tcp 0 0 127.0.0.1 LISTEN 1191/sshd tcp6 25 0.0.0.0 * LISTEN 1835/master tcp6 0 0: 22:: * LISTEN 1191/sshd tcp6 0 0:: 1:25 : * LISTEN 1835/master udp 0 0 0.0.0. 0 LISTEN 1835/master udp 32525 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1 661/chronyd udp 0 0 0.0.0.0 661/chronyd 68 0.0.0.0 661/chronyd * 729/dhclient udp6 0 0:: 1 Udp6 0 0: 14472: * 729/dhclient [root@localhost salt] #

(3) cron module (to realize the crontab operation of the controlled host)

# # add crontab information for specified controlled hosts and root users

# salt'* 'cron.set_job root' * / 5' *''date > / dev/null 2 > & 1'

# salt'* 'cron.raw_cron root

[root@localhost salt] # salt'* 'cron.set_job root' * / 60'*'/ usr/local/nginx/sbin/nginx-s reload > / dev/null 2 > & 1'server02: newserver03: new [root@localhost salt] # [root@localhost salt] # salt'* 'cmd.run' crontab-l'server03: # Lines below here are managed by Salt Do not edit * / 60 * / usr/local/nginx/sbin/nginx-s reload > / dev/null 2 > & 1server02: # Lines below here are managed by Salt, do not edit * / 60 * / usr/local/nginx/sbin/nginx-s reload > / dev/null 2 > & 1 [root@localhost salt] #

# # deleting crontab information of specified controlled hosts and root users

[root@localhost salt] # salt'* 'cron.rm_job root' / usr/local/nginx/sbin/nginx-s reload > / dev/null 2 > & 1'server02: removedserver03: removed [root@localhost salt] # salt'* 'cmd.run' crontab-l'server03: # Lines below here are managed by Salt, do not editserver02: # Lines below here are managed by Salt, do not edit [root@localhost salt] #

(4), dnsutil module (to realize the general DNS operation of the controlled host)

Add the specified hosts configuration item, that is, host host record, to the controlled side

# salt'* 'dnsutil.hosts_append / etc/hosts 192.168.112.140 server01

# salt'* 'dnsutil.hosts_append / etc/hosts 192.168.112.141 server02

# salt'* 'dnsutil.hosts_append / etc/hosts 192.168.112.142 server03

[root@localhost salt] # salt'* 'dnsutil.hosts_append / etc/hosts 192.168.112.140 server01server02: The following line was added to / etc/hosts: 192.168.112.140 server01server03: The following line was added to / etc/hosts: 192.168.112.140 server01 [root@localhost salt] # salt' * 'dnsutil.hosts_append / etc/hosts 192.168.112.141 server02server03: The following line was added to / etc/hosts: 192.168.112.141 server02server02: The following line was added to / etc/hosts: 192.168.112.141 server02 [root@localhost salt] # salt'* 'dnsutil.hosts_append / etc/hosts 192.168.112.142 server03server03: The following line was added to / etc/hosts: 192.168.112.142 server03server02: The following line was added to / etc/hosts: 192.168.112.142 server03 [root@localhost salt] # salt' * 'cmd .run 'grep 192.168.112.140 server01 192.168.112.141 server02 192.168.112.142 server03server02: 192.168.112.140 server01 192.168.112.141 server02 192.168.112.142 server03 [root@localhost salt] #

(5), file module (common operations of the controlled host files, including file reading and writing, permissions, search, verification, etc.)

# salt'* 'file.get_sum / etc/hosts md5

# salt'* 'file.stats / etc/hosts

[root@localhost salt] # salt'* 'file.get_sum / etc/hosts md5server03: 7895e4dd8df907aa29d026a75f2a035aserver02: 7895e4dd8df907aa29d026a75f2a035a [root@localhost salt] # salt' * 'file.stats / etc/hostsserver02:-atime: 1496299480.63 ctime: 1496299455.14 gid: 0 group: root inode: 67128992 mode: 0644 mtime: 1496299455.14 size: 234 target: / etc/hosts type: file uid: 0 user: rootserver03:-atime: 1496299480.62 ctime: 1496299455.14 gid: 0 group: root inode: 67109270 mode: 0644 mtime: 1496299455 . 14 size: 234 target: / etc/hosts type: file uid: 0 user: root [root@localhost salt] #

(6) network module (returns the network information of the controlled host)

# salt'* 'network.ip_addrs

# salt'* 'network.interfaces

[root@localhost salt] # salt'* 'network.ip_addrsserver03:-192.168.112.142server02:-192.168.112.141 [root@localhost salt] # salt' * 'network.interfacesserver02:-eth0:-hwaddr: 00:0c:29:0b:28:95 inet: | _ -address: 192.168.112.141 broadcast: 192.168.112.255 label: eth0 netmask: 255.255.255.0 inet6: | _ -address: fe80::bf36:72fd:ae66:3183 prefixlen: 64 scope: link up: True lo:-hwaddr: Inet: _-address: 127.0.0.1 broadcast: None label: lo netmask: 255.0.0.0 inet6: | _-address: 1 prefixlen: 128 scope: host up: Trueserver03:- Eth0:-hwaddr: 00:0c:29:63:9d:12 inet: _-address: 192.168.112.142 broadcast: 192.168.112.255 Label: eth0 netmask: 255.255.255.0 inet6: | _-address: fe80::7f27:a270:df5d:d68 prefixlen: 64 Scope: link up: True lo:-hwaddr: 00 inet: _-address: 127.0 0.1 broadcast: None label: lo netmask: 255.0.0.0 inet6: | _-address: 1 Prefixlen: 128 scope: host up: True [root@localhost salt] #

(7), pkg package management module (controlled host package management, such as yum, apt-get, etc.)

# salt'* 'pkg.install httpd-> install Apache service

# salt'* 'pkg.file_list httpd---- > View the installation path and files of the Apache service

[root@localhost] # salt'* 'pkg.install httpdserver03:-httpd:-new: 2.4.6-45.el7.centos.4 old: httpd-tools:-new: 2.4.6-45.el7.centos. 4 old: mailcap:-new: 2.1.41-2.el7 old:server02:-httpd:-new: 2.4.6-45.el7.centos.4 old: httpd-tools: -new: 2.4.6-45.el7.centos.4 old: mailcap:-new: 2.1.41-2.el7 old: [root@localhost ~] #

(8), service service module (package service management of the controlled host)

# salt'* 'service.enable httpd

# salt'* 'service.disable httpd

# salt'* 'service.status httpd

# salt'* 'service.stop httpd

# salt'* 'service.start httpd

# salt'* 'service.restart httpd

# salt'* 'service.reload httpd

[root@localhost ~] # salt'* 'service.enable httpdserver02: Trueserver03: True [root@localhost ~] # salt' * 'service.disable httpdserver02: Trueserver03: True [root@localhost ~] # salt' * 'service.status httpdserver02: Falseserver03: False [root@localhost ~] # salt' * service.stop httpdserver02: Trueserver03: True [root@localhost ~] # salt'* 'service.start httpdserver03: Trueserver02: True [root@localhost ~ ] # salt'* 'service.reload httpdserver03: Trueserver02: True [root@localhost ~] # salt' * 'cmd.run' netstat-lnupt | grep httpd'server03: tcp6 00: 80: * LISTEN 17294/httpdserver02: tcp6 00: 80:: * LISTEN 3231/httpd [root@localhost ~] #

(9), more versatile

More functions, such as grains, pillar, states, modules, returner, runners, reactor, etc., as well as the use of the following advanced commands, as well as the rendering of template configuration, the secondary development of the extension module, etc., can be studied deeply by yourself, to be continued.

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

Servers

Wechat

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

12
Report