利用saltstack的salt-ssh进行集群管理【无客户端下】

十一回来,很是懒散呀~

今天在群里看到 itnihao兄在聊 salt-ssh ,这是个好东西,就群里一直就跟进着。。。翻了下聊天记录,就把salt-ssh实现了下。

原本前些日子就想写一个salt ssh的文章,正好是快十一了,自己也没心思写了。。。

今天就把过程写一下,后期丰富下。。。。【嘿,又是这一套。。。。】

听兆松的意思,saltstack的epel源有问题,但是github里面的代码是无问题的。

salt-ssh 可以独立运行的,不用minion的~ 要是需要用salt-ssh的特殊参数,,比如grains获取数据的话,还是需要安装minion的,不然他是不好判断你是redhat,debian的 ~ 说句废话 要是能安装minion,谁还用salt-ssh呀。。。。

提示这样出名的工具还是不少的,我这边简单分析下优缺点!

pdsh、pssh 这东西是要建立在你做好了key关联之后,他的优点才能看出来

vi server1.txt192.168.1.11192.168.1.12192.168.1.13192.168.1.14pssh -h server1.txt -l root -P dir

expect 最大的有点就是交互,但是要成高性能的话,需要自己写多线程的。

#!/usr/bin/expect -fset toip [lindex $argv 0 ]set ip 10.2.20.14set password 123123set timeout 10spawn ssh root@$ipexpect {“*yes/no” { send “yes\r”; exp_continue}”*password:” { send “$password\r” }}

fabric、paramiko python之利器,用过一段时间,该有的都有的,很是强大

from fabric import envenv.hosts = [‘user1@host1:port1’, ‘user2@host2.port2’]env.passwords = {‘user1@host1:port1’: ‘password1’, ‘user2@host2.port2’: ‘password2’}

git clone https://github.com/saltstack/salt.gitcd salt./setup.py install

我们可以把要执行的信息,也就是ip,帐号,密码等 都放到一个文件里面。当然

文件路径是可以随便定义的,官方是指定到了 /etc/salt/roster

我们刚才执行的结果:

我们测试下他的性能 ~ 结果让人很爽 ~

详细的参数:

指定信息文件

配置一个默认的密码,然后帮你推送下 ~~~ 这个功能有点怪,规范点的公司,大家的密码都是随机生成的,但是适合自己的实验环境和小公司。。。。

参数不少,大家自己看吧 ~

salt-sshSynopsissalt-ssh ‘*’ [ options ] sys.docsalt-ssh -E ‘.*’ [ options ] sys.doc cmdDescriptionSalt ssh allows for salt routines to be executed using only ssh for transportOptions-r, –raw, –raw-shellExecute a raw shell command.要执行的命令,支持管道和常用的特殊符号–roster-fileDefine 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-cacheForce 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-procsSet 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.–passwdSet te default password to attempt to use when authenticating.–key-deploySet 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.–versionPrint the version of Salt that is running.–versions-reportShow program’s dependencies and version number, and then exit-h, –helpShow the help message and exit-c CONFIG_DIR, –config-dir=CONFIG_dirThe 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, –pcreThe target expression will be interpreted as a PCRE regular expression rather than a shell glob.-L, –listThe target expression will be interpreted as a comma-delimited list; example: server1.foo.bar,server2.foo.bar,example7.quo.qux-G, –grainThe 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-pcreThe 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, –nodegroupUse a predefined compound target defined in the Salt master configuration file.-R, –rangeInstead 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 OptionsLogging options which override any settings defined on the configuration files.-l LOG_LEVEL, –log-level=LOG_LEVELConsole logging log level. One of all, garbage, trace, debug, info, warning, error, quiet. Default: warning.–log-file=LOG_FILELog file path. Default: /var/log/salt/ssh.–log-file-level=LOG_LEVEL_LOGFILELogfile logging log level. One of all, garbage, trace, debug, info, warning, error, quiet. Default: warning.Output Options–outPass 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, yamlSome 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.NoteIf 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_INDENTPrint 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_FILEWrite the output to the specified file.–no-colorDisable all colored output–force-colorForce colored output

我们来总结下哈:

会得到最大的满足,因为它填补了你的空虚。

利用saltstack的salt-ssh进行集群管理【无客户端下】

相关文章:

你感兴趣的文章:

标签云: