更多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写的脚本。。。。