When executing a command, forget the syntax, you can use the Sys.doc module to query the Salt module related usage.
# salt ' * ' Sys.doc disk
1, when executing the command, find Minion Target (targeting) commonly used in three ways:
Salt ' shell regular ' command example: # Salt ' host* ' cmd.run ' df-h ' #我们主机ID是host加数字的salt –E ' perl regular ' command #--pcre, no Perl language, no example of SA Lt–n Group Command #--nodegroup, the premise is already good group example: # salt-n Web cmd.run ' df-h ' salt–l ' host1,host2 ' command #--list Example: # salt-l ' host1,host2 ' cmd.run ' df-h ' salt–g ' os.ubuntu ' command #--grains
What is grains?
Grains is the minion when the server System Information acquisition, such as hard disk, CPU, memory, network card and other static data.
Grains Related commands:
List Grains related modules
# salt ' * ' grains.ls
List grains static data collected by Minion
# salt ' * ' Grains.items
List A grains information
# salt ' * ' Grains.item OS
Have a preliminary understanding of grains, now will use SALT–G command!
# salt-g ' OS. Ubuntu ' test.ping
2, Nodegroup (Minion Group)
# Vi/etc/salt/master #不用重启salt服务, modified to take effect nodegroups:web: ' host1 ' db: ' Host2 ' #测试分组后效果 # salt-n DB test.pinghost2:t Rue # Salt-n Web Test.pinghost1:True
3. State (status Management)
To enable the configuration management feature, first set up the managed side to allow Minion to accept the primary null management command as root:
# Vi/etc/salt/minionuser:root Open the main terminal configuration management function: # vi/etc/salt/masterfile_roots:base:-/srv/salt/#默认存放管理指令 and file location
Manually creating directories and default portal profiles (TOP.SLS)
# mkdir /srv/salt# vi /srv/salt/top.sls #使用YAML语言格式定义base: #默认的起点配置 ' * ': #匹配所有在线minion, specify group directly write group name- web.httpd #web是默认/srv/salt under Directory, HTTP is the state file name, with SLS end # vi /srv/salt/web/httpd.sls #创建目录或文件名根据自己情况定义httpd: #说明 pkg: #包管理 -name: apache2 #包名称- installed #包的状态, uninstall is removed
Note: Indentation is 2 spaces, a colon back door a space
# salt ' * ' state.highstate # Execute state command host1:---------- ID: httpd Function: pkg.installed Name: apache2 result: true comment: the following packages were installed/updated: apache2. Started: 11:30:40.994840 Duration: 103211.119 ms Changes: omitted ..... Summary------------succeeded: 1 (changed=1) failed: 0------------total states run: 1host2:---------- id: httpd function: pkg.installed Name: apache2 result: true comment: the following packages were installed/updated: apache2. started: 11:30:41.458100 Duration: 122426.802 ms Changes: omitted ..... Summary------------succeeded: 1 (changed=1) failed: 0------------total states run: 1
apache is installed and started, then pushes the modified profile to Minion (Apache server), config file modified, location in/srv/salt/web/ httpd.conf, modify the content to add a virtual host and add the file distribution information to the HTTPD.SLS.
# vi httpd.sls httpd: pkg: -name: apache2 -installed service: - name: apache2 #服务脚本名 -running #运行状态 -reload: true #如watch监控项发生变化, reload the configuration -watch: #监控文件变化 - file: /etc/apache2/httpd.conf/etc/apache2/httpd.conf: # Distribute to minion locations file.managed: #文件管理操作 -source: salt://web/httpd.conf #修改好的配置文件位置 -user: root -group: root -mode: 644 -backup: minion
At this point, check the Minion server Apache configuration file for updates:
# salt ' * ' cmd.run ' cat/etc/apache2/httpd.conf '
This article is from the "Penguin" blog, please be sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1638581
Further understanding of Saltstack (Basic use)