更多saltstack的文章總結在:node
http://rfyiamcool.blog.51cto.com/1030776/1357677python
個人我的獨立博客地址是,blog.xiaorui.ccgit
十一回來,非常懶散呀~ github
今天在羣裏看到 itnihao兄在聊 salt-ssh ,這是個好東西,就羣裏一直就跟進着。。。翻了下聊天記錄,就把salt-ssh實現了下。shell
本來前些日子就想寫一個salt ssh的文章,正好是快十一了,本身也沒心思寫了。。。express
今天就把過程寫一下,後期豐富下。。。。【嘿,又是這一套。。。。】json
聽兆鬆的意思,saltstack的epel源有問題,可是github裏面的代碼是無問題的。api
salt-ssh 能夠獨立運行的,不用minion的~ 要是須要用salt-ssh的特殊參數,好比grains獲取數據的話,仍是須要安裝minion的,否則他是很差判斷你是redhat,debian的 ~ 說句廢話 要是能安裝minion,誰還用salt-ssh呀。。。。 服務器
提示這樣出名的工具仍是很多的,我這邊簡單分析下優缺點!多線程
pdsh、pssh 這東西是要創建在你作好了key關聯以後,他的優勢才能看出來
vi server1.txt 192.168.1.11 192.168.1.12 192.168.1.13 192.168.1.14 pssh -h server1.txt -l root -P dir
expect 最大的有點就是交互,可是要成高性能的話,須要本身寫多線程的。
#!/usr/bin/expect -f set toip [lindex $argv 0 ] set ip 10.2.20.14 set password 123123 set timeout 10 spawn ssh root@$ip expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" { send "$password\r" } }
fabric、paramiko python之利器,用過一段時間,該有的都有的,非常強大
from fabric import env env.hosts = ['user1@host1:port1', 'user2@host2.port2'] env.passwords = {'user1@host1:port1': 'password1', 'user2@host2.port2': 'password2'}
可是我仍是很看好 salt-ssh ,關於理由,你猜 ~
之後配置salt-api 會更好用的~
salt-ssh 能夠代替expect之類的密碼推送腳本,看起來功能不比expect差 。 salt-ssh 用的是sshpass進行密碼交互的。
源地址:http://rfyiamcool.blog.51cto.com/1030776/1305710
咱們先開始安裝 salt-ssh ~
git clone https://github.com/saltstack/salt.git cd salt ./setup.py install
salt-ssh
咱們能夠把要執行的信息,也就是ip,賬號,密碼等 都放到一個文件裏面。固然
文件路徑是能夠隨便定義的,官方是指定到了 /etc/salt/roster
咱們剛纔執行的結果:
咱們測試下他的性能 ~ 結果讓人很爽 ~
詳細的參數:
指定信息文件
配置一個默認的密碼,而後幫你推送下 ~~~ 這個功能有點怪,規範點的公司,你們的密碼都是隨機生成的,可是適合本身的實驗環境和小公司。。。。
重大發現: 我在這裏補充下~
salt-ssh 第一次執行是根據roster的帳號密碼推送密碼,來實現自動交互的。
執行完了後 會在目標的服務器裏面,追加master端的key
而後你就能夠刪除roster裏面的passwd 密碼條目了。
我給你們測試下,我把passwd刪除了,仍是能夠運行,這裏就不是用sshpass推送密碼了,而是直接經過key了 !!!
參數很多,你們本身看吧 ~
salt-ssh Synopsis salt-ssh '*' [ options ] sys.doc salt-ssh -E '.*' [ options ] sys.doc cmd Description Salt ssh allows for salt routines to be executed using only ssh for transport Options -r, --raw, --raw-shell Execute a raw shell command. 要執行的命令,支持管道和經常使用的特殊符號 --roster-file Define which roster system to use, this defines if a database backend, scanner, or custom roster system is used. Default is the flat file roster. 指定一個信息文件 --refresh, --refresh-cache Force a refresh of the master side data cache of the target's data. This is needed if a target's grains have been changed and the auto refresh timeframe has not been reached. --max-procs Set the number of concurrent minions to communicate with. This value defines how many processes are opened up at a time to manage connections, the more running process the faster communication should be, default is 25. --passwd Set te default password to attempt to use when authenticating. --key-deploy Set this flag to attempt to deploy the authorized ssh key with all minions. This combined with --passwd can make initial deployment of keys very fast and easy. --version Print the version of Salt that is running. --versions-report Show program's dependencies and version number, and then exit -h, --help Show the help message and exit -c CONFIG_DIR, --config-dir=CONFIG_dir The location of the Salt configuration directory. This directory contains the configuration files for Salt master and minions. The default location on most systems is /etc/salt. Target Selection -E, --pcre The target expression will be interpreted as a PCRE regular expression rather than a shell glob. -L, --list The target expression will be interpreted as a comma-delimited list; example: server1.foo.bar,server2.foo.bar,example7.quo.qux -G, --grain The target expression matches values returned by the Salt grains system on the minions. The target expression is in the format of '<grain value>:<glob expression>'; example: 'os:Arch*' This was changed in version 0.9.8 to accept glob expressions instead of regular expression. To use regular expression matching with grains, use the --grain-pcre option. --grain-pcre The target expression matches values returned by the Salt grains system on the minions. The target expression is in the format of '<grain value>:< regular expression>'; example: 'os:Arch.*' -N, --nodegroup Use a predefined compound target defined in the Salt master configuration file. -R, --range Instead of using shell globs to evaluate the target, use a range expression to identify targets. Range expressions look like %cluster. Using the Range option requires that a range server is set up and the location of the range server is referenced in the master configuration file. 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, quiet. Default: warning. --log-file=LOG_FILE Log file path. Default: /var/log/salt/ssh. --log-file-level=LOG_LEVEL_LOGFILE Logfile logging log level. One of all, garbage, trace, debug, info, warning, error, quiet. Default: warning. Output Options --out Pass in an alternative outputter to display the return of data. This outputter can be any of the available outputters: grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml Some outputters are formatted only for data returned from specific functions; for instance, the grains outputter will not work for non-grains data. If an outputter is used that does not support the data passed into it, then Salt will fall back on the pprint outputter and display the return data using the Python pprint standard library module. Note If using --out=json, you will probably want --static as well. Without the static option, you will get a JSON string for each minion. This is due to using an iterative outputter. So if you want to feed it to a JSON parser, use --static as well. --out-indent OUTPUT_INDENT, --output-indent OUTPUT_INDENT Print the output indented by the provided value in spaces. Negative values disable indentation. Only applicable in outputters that support indentation. --out-file=OUTPUT_FILE, --output-file=OUTPUT_FILE Write the output to the specified file. --no-color Disable all colored output --force-color Force colored output
要是有好用的功能,我會再補上的~
添加 參數的方法
源地址:http://rfyiamcool.blog.51cto.com/1030776/1305710
咱們來總結下哈:
好東西,saltstack是個神器,可是有些服務器你死活裝不上saltstack客戶端,或者是有些業務線已經有puppet chef之類的,不太適合再裝saltsatck minion ,再或者是 咱們能夠時髦的用saltstack salt-ssh 直接代替簡單的expect寫的腳本。。。。