Summary :Saltstack is a centralized server infrastructure management platform with configuration management, remote execution, monitoring and other functions, can generally be understood as a simplified version of the puppet and enhanced Func. Saltstack is based on the Python language implementation and is built with a lightweight Message Queuing (ZeroMQ) and Python third-party modules (PYZMQ, Pycrypto, Pyjinjia2, Python-msgpack, and Pyyaml, etc.).
By deploying the Saltstack environment, we can execute batch commands on thousands of servers, configure centralized management according to different business characteristics, distribute files, collect server data, operating system base and package management, etc., Saltstack is the operation and maintenance personnel to improve work efficiency, Standardize the business configuration and operation of the sharp weapon.
Module : Saltstack is powerful is to have a lot of modules, these modules greatly improve our efficiency, but also continue to develop new modules, here first to enumerate some of the basic applications of common modules, more modules and use of methods please refer to the official website: https:// docs.saltstack.com/en/latest/ref/modules/all/
Experimental Environment : (To save space, only the Minion end slave this machine to operate)
master:10.0.4.52 CentOS Release 6.5 (final) slave:10.0.4.53 CentOS release 6.5 (final)
Module One: CMD module (Implementation of remote command line invocation execution)
# salt ' slave ' cmd.run ' uptime ' # Linux commands can be called remotely slave: 11:47:36 up 14 days, 3:26, 0 users, load average: 0.00, 0.00, 0.00# salt ' slave ' cmd.run ' Df -h ' slave: filesystem Size used avail use% mounted on /dev/mapper/vg_ localhost-lv_root 18g 3.0g 14g 19% / tmpfs 940m 84k 940m 1% /dev/shm /dev/sda1 485M 39M 421m 9% /boot
Module two: Cron module (to implement the crontab operation of the controlled host)
# salt ' slave ' cron.set_job root ' * ' */2 ' * ' * ' * ' * ' ntpdate time.nist.gov >/dev/null 2>&1 ' #添加计划任务slave: N ew# Salt ' slave ' Cron.raw_cron root #查看minion端root的计划任务. Slave: # Lines below here is managed by Salt, does not edit * */2 * * * ntpdate time.nist.gov >/dev/null 2>& ; # salt ' slave ' cron.rm_job root ' ntpdate time.nist.gov >/dev/null 2>&1 ' #删除root的计划任务slave: Removed
Module three: File module (common operations for host files, including file read and write, permissions, lookups, checksums, and so on)
# salt ' slave ' file.get_sum /etc/resolv.conf md5 #查看md5slave: 025b620e25bbef5b53099ae9cdbb9d16# salt ' slave ' file.stats /etc/resolv.conf #查看文件属性. slave: ---------- atime: 1463387846.48 ctime: 1462759047.49 gid: 0 group: root inode: 135225 mode: 0644 mtime: 1462759047.49 size: 83 .......................# salt ' slave ' file.append /etc/motd \ #给某个文件添加添加内容. > "With all thine offerings thou shalt offer salt." > "SALT IS WHAT MAKES THINGS TASTE BAD WHEN IT ISN" T in them. " slave: wrote 2 lines to "/ETC/MOTD" # salt ' slave ' file.chown /data/1.txt root root #修改文件用户和所属组slave: none # salt ' slave ' file.copy /data/1.txt /tmp/1.txt #将data目录下的1. txt files copied to /tmp directory slave: true# salt ' slave ' file.find / type=f name= \*.bak size=+10m the file that ends #找出大于10M并且以. bak. slave: - /data/1.bak - /data/2.bak# salt ' Slave ' file.find / type=f name=\*.bak size=+10m delete #删除以. Bak ends and is larger than 10M files. # salt ' slave ' file.mkdir /tmp/test #在/tmp directory to create the test folder
module Four: Network module (return to the controlled host networking information)
# salt ' * ' network.ip_addrs #查看IP地址slave: - 10.0.4.53master: - 10.0.4.52# salt ' slave ' network.get_hostname #取主机名slave: slave # salt ' slave ' network.hw_addr eth0 # Take MAC address slave: 00:0c:29:a3:cd:93 # salt ' slave ' network.interface eth0 # View IP-related information for network cards slave: |_ ---------- address: 10.0.4.53 broadcast: 10.0.4.255 label: eth0 netmask: 255.255.255.0 # salt ' slave ' network.ping blog.51cto.com #ping域名slave: PING sq.dns.51cto.com (120.55.239.108) 56 ( bytes of data). 64 bytes from 120.55.239.108: icmp_seq=1 ttl=40 time= 32.8 ms 64 bytes from 120.55.239.108: icmp_seq=2 ttl=40 time=32.7 ms 64 bytes from 120.55.239.108: icmp_seq=3 ttl=40 time=32.8 ms 64 bytes from 120.55.239.108: Icmp_seq=4 ttl=40 time=32.6 ms --- sq.dns.51cto.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3036ms rtt min/avg/max/mdev = 32.652/32.795/32.871/0.155 ms# salt ' slave ' network.connect www.51cto.com 80 #测试连接到主机特定的端口上. slave: ---------- comment: Successfully connected to www.51cto.com (120.55.239.108) on tcp port 80 result: true # salt ' slave ' network.dig www.51cto.com #查询域名DNS包括NS记录, a record, MX records and other related information. Slave: ................................ ;www.51cto.com. IN A ;; ANSWER SECTION: www.51cto.com. 600 IN CNAME web.dns.51cto.com. web.dns.51cto.com. 600 IN A 120.55.239.108       &NBSP, ....... .................
Module Five: PKG Package management module (controlled host package management)
# salt ' * ' Pkg.install nmap #安装nmap工具, pkg.install behind add the software name you want to install. # salt ' * ' pkg.file_list nmap #查看nmap的文件列表
Module Six: Service Service Module (managed host package services)
# salt ' slave ' service.enable NFS #开启某个服务 (NFS). slave:true# Salt ' slave ' service.disable NFS #关闭某个服务 (NFS). slave:true# Salt ' slave ' service.start NFS #启动服务slave: true# salt ' slave ' service.stop NFS #关闭服务slave: true# Salt ' slave ' service.status NFS #查看服务状态slave: True
Module VII: Grain module (grains Data Control)
# salt ' slave ' grains.item os #查看OSslave:----------os:centos# salt ' slave ' grains.item os Osrele ASE oscodename #查看系统版本slave:----------os:centos oscodename:final osrelease:6.5
Module Eight: state module (Management minion State)
# salt ' slave ' state.highstate #对minion执行top. SLS, this command is more important.
Module IX: Status module (returns various status data on the Minion side)
# salt ' slave ' status.cpuinfo #查看CPU信息. slave: ---------- address sizes: 40 bits physical, 48 bits virtual bogomips: 3989.99 cache size: 18432 KB cache_alignment: 64 ..................................... # salt ' slave ' status.cpustats #查看CPU使用情况. slave: ---------- btime: 1462234850 cpu: ---------- idle: 121186157 iowait: 9437 irq: 43 nice: 954 softirq: 175 steal: ...................................# salt ' slave ' status.diskusage #返回磁盘使用情况. # salt ' slave ' status.diskusage / /tmp #返回根分区和/tmp partition usage. slave: ---------- /: ---------- available: 14365966336 total: 18503614464 /tmp: ---------- available: 14365966336 total: 18503614464# salt ' Slave ' status.meminfo #返回内存信息. slave: ---------- Active: ---------- unit: kb value: 507084 active (anon): ------- --- unit: kB value: 88684 active (file): ---------- unit: kB value: 418400 ...................... # salt ' slave ' status.loadavg #返回平均负载值. slave: ---------- 1-min: 0.0 15-min: 0.0 5-min: 0.0
Well, first write here, and then continue to update the basic usage of more modules later.
This article is from the "Share Linux" blog, so be sure to keep this source http://sharelinux.blog.51cto.com/11163444/1774386
Saltstack Common Module Case analysis