1、環境準備
node
slat-master-1:10.0.241.122python
# yum install salt-master -y # systemctl start salt-master.service
salt-minion-1:10.0.241.123web
salt-minion-2:10.0.241.124shell
# yum install salt-minion -y # sed -i 's/#master: salt/master: 10.0.241.122/g' /etc/salt/minion # systemctl start salt-minion.service # echo `hostname` > /etc/salt/minion_id # systemctl restart salt-minion.service
在salt-master上接受salt-minion的keyexpress
[root@salt-master-1 ~]# salt-key -yA The following keys are going to be accepted: Unaccepted Keys: salt-minion-1 salt-minion-2 Key for minion salt-minion-1 accepted. Key for minion salt-minion-2 accepted.
2、平常命令參數json
Master端:centos
[root@salt-master-1 ~]# rpm -ql salt-master /etc/salt/master # salt master 配置文件 /usr/bin/salt # salt master 核心操做命令 /usr/bin/salt-cp # salt 文件傳輸命令 /usr/bin/salt-key # salt 證書管理命令 /usr/bin/salt-master # salt master 服務命令 /usr/bin/salt-run # salt master runner命令 /usr/bin/salt-unity # salt master /usr/lib/systemd/system/salt-master.service # salt master 服務啓動腳本 [root@salt-master-1 ~]# salt -h Usage: salt [options] '<target>' <function> [arguments] Options: --version 查看SaltStack程序的版本號 --versions-report 查看SaltStack程序以及依賴包的版本號 -h, --help 查看幫助信息 --saltfile=SALTFILE Specify the path to a Saltfile. If not passed, one will be searched for in the current working directory -c CONFIG_DIR, --config-dir=CONFIG_DIR 指定配置文件目錄 Default: /etc/salt -t TIMEOUT, --timeout=TIMEOUT 指定Timeout實踐 command; default=5 --hard-crash 捕捉original異常不退出 gracefully Default: False -s, --static 以組的形式返回全部Minion的數據 -p, --progress Display a progress graph. [Requires `progressbar` python package.] --failhard Stop batch execution upon first "bad" return --async 異步執行 --subset=SUBSET Execute the routine on a random subset of the targeted minions. The minions will be verified that they have the named function before executing -v, --verbose Turn on command verbosity, display jid and active job queries --hide-timeout Hide minions that timeout --show-jid 顯示任務jid -b BATCH, --batch=BATCH, --batch-size=BATCH 按照百分比執行任務 -a EAUTH, --auth=EAUTH, --eauth=EAUTH, --external-auth=EAUTH 指定外部認證方式 -T, --make-token 生成Master token --return=RETURNER 指定SaltStack return --return_config=RETURNER_CONF Set an alternative return method. By default salt will send the return data from the command back to the master, but the return data can be redirected into any number of systems, databases or applications. -d, --doc, --documentation 查看指定模塊或全部模塊文檔 --args-separator=ARGS_SEPARATOR 設置多個傳參直接分隔符 --summary Display summary information about a salt command --username=USERNAME Username for external authentication --password=PASSWORD Password for external authentication --metadata=METADATA Pass metadata into Salt, used to search jobs. Logging Options: Logging options which override any settings defined on the configuration files. -l LOG_LEVEL, --log-level=LOG_LEVEL Console logging log level. One of 'all', 'garbage', 'trace', 'debug', 'info', 'warning', 'error', 'critical', 'quiet'. Default: 'warning'. --log-file=LOG_FILE Log file path. Default: /var/log/salt/master. --log-file-level=LOG_LEVEL_LOGFILE Logfile logging log level. One of 'all', 'garbage', 'trace', 'debug', 'info', 'warning', 'error', 'critical', 'quiet'. Default: 'warning'. Target Options: Target Selection Options -E, --pcre 正則匹配 -L, --list 列表匹配 -G, --grain grains 匹配 --grain-pcre grains加正則匹配 expression: "os:Arch.*" -N, --nodegroup 組匹配 -R, --range 範圍匹配 -C, --compound 綜合匹配 matching the specific targets argument type: salt 'G@os:RedHat and webser* or E@database.*' -I, --pillar pillar值匹配 expression: "role:production*" -J, --pillar-pcre Instead of using shell globs to evaluate the target use a pillar value to identify targets, the syntax for the target is the pillar key followed by a pcre regular expression: "role:prod.*" -S, --ipcidr Match based on Subnet (CIDR notation) or IPv4 address. Additional Target Options: Additional Options for Minion Targeting --delimiter=DELIMITER Change the default delimiter for matching in multi- level data structures. default=':' Output Options: Configure your preferred output format --out=OUTPUT, --output=OUTPUT Print the output from the 'salt' command using the specified outputter. The builtins are 'key', 'yaml', 'overstatestage', 'txt', 'newline_values_only', 'no_return', 'raw', 'virt_query', 'compact', 'json', 'highstate', 'nested', 'quiet', 'pprint'. --out-indent=OUTPUT_INDENT, --output-indent=OUTPUT_INDENT Print the output indented by the provided value in spaces. Negative values disables indentation. Only applicable in outputters that support indentation. --out-file=OUTPUT_FILE, --output-file=OUTPUT_FILE Write the output to the specified file --out-file-append, --output-file-append Append the output to the specified file --no-color, --no-colour Disable all colored output --force-color, --force-colour Force colored output --state-output=STATE_OUTPUT, --state_output=STATE_OUTPUT Override the configured state_output value for minion output. One of full, terse, mixed, changes or filter. Default: full. You can find additional help about salt issuing "man salt" or on http://docs.saltstack.org
Minion端:服務器
[root@salt-minion-1 ~]# rpm -ql salt-minion /etc/salt/minion # salt minion 配置文件 /usr/bin/salt-call # salt minion 拉取命令 /usr/bin/salt-minion # salt minion 服務命令 /usr/lib/systemd/system/salt-minion.service # salt minion 服務啓動腳本 [root@salt-minion-1 ~]# salt-call -h Usage: salt-call [options] <function> [arguments] Salt call is used to execute module functions locally on a minion Options: --version 查看SaltStack程序的版本號 --versions-report 查看SaltStack程序以及依賴包的版本號 -h, --help show this help message and exit --saltfile=SALTFILE Specify the path to a Saltfile. If not passed, one will be searched for in the current working directory -c CONFIG_DIR, --config-dir=CONFIG_DIR Pass in an alternative configuration directory. Default: /etc/salt --hard-crash Raise any original exception rather than exiting gracefully Default: False -g, --grains 返回的信息生成grains -m MODULE_DIRS, --module-dirs=MODULE_DIRS 指定自定義模塊目錄 Multiple directories can be provided by passing `-m /--module-dirs` multiple times. -d, --doc, --documentation 查看指定模塊或者全部模塊文檔 --master=MASTER Specify the master to use. The minion must be authenticated with the master. If this option is omitted, the master options from the minion config will be used. If multi masters are set up the first listed master that responds will be used. --return=RETURNER Set salt-call to pass the return data to one or many returner interfaces. --local 運行masterless模式 --file-root=FILE_ROOT 指定file-root目錄 --pillar-root=PILLAR_ROOT Set this directory as the base pillar root. --retcode-passthrough Exit with the salt call retcode and not the salt binary retcode --metadata Print out the execution metadata as well as the return. This will print out the outputter data, the return code, etc. --id=ID Specify the minion id to use. If this option is omitted, the id option from the minion config will be used. --skip-grains Do not load grains. --refresh-grains-cache Force a refresh of the grains cache -t AUTH_TIMEOUT, --timeout=AUTH_TIMEOUT Change the timeout, if applicable, for the running command; default=60
遇到的問題:
app
salt-minion 中 /etc/salt/minion_id 文件裏面的內容取的是服務器的fqdb,我在安裝完salt-minion以後,看到salt-master上接受的minion爲以下:less
[root@salt-master-1 ~]# salt-key -L Accepted Keys: Denied Keys: Unaccepted Keys: VM_241_123_centos VM_241_124_centos Rejected Keys:
執行以下命令:
# echo `hostname` > /etc/salt/minion_id # systemctl restart salt-minion.service
[root@salt-master-1 ~]# salt-key -L Accepted Keys: Denied Keys: Unaccepted Keys: salt-minion-1 salt-minion-2 Rejected Keys: [root@salt-master-1 ~]# salt "salt-minion-*" test.ping salt-minion-2: True salt-minion-1: True