利用saltstack的salt-ssh進行叢集管理【無客戶端下】
更多saltstack的文章總結在:
http://rfyiamcool.blog.51cto.com/1030776/1357677
我的個人獨立部落格地址是,blog.xiaorui.cc
十一回來,很是懶散呀~
今天在群裡看到 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關聯之後,他的優點才能看出來
viserver1.txt 192.168.1.11 192.168.1.12 192.168.1.13 192.168.1.14 pssh-hserver1.txt-lroot-Pdir
expect 最大的有點就是互動,但是要成高效能的話,需要自己寫多執行緒的。
#!/usr/bin/expect-f settoip[lindex$argv0] setip10.2.20.14 setpassword123123 settimeout10 spawnssh[email protected]$ip expect{ "*yes/no"{send"yes\r";exp_continue} "*password:"{send"$password\r"} }
fabric、paramiko python之利器,用過一段時間,該有的都有的,很是強大
fromfabricimportenv env.hosts=['[email protected]:port1','[email protected]'] env.passwords={'[email protected]:port1':'password1','[email protected]':'password2'}
但是我還是很看好 salt-ssh ,關於理由,你猜 ~
以後配置salt-api 會更好用的~
salt-ssh 可以代替expect之類的密碼推送指令碼,看起來功能不比expect差 。 salt-ssh 用的是sshpass進行密碼互動的。
源地址:http://rfyiamcool.blog.51cto.com/1030776/1305710
我們先開始安裝 salt-ssh ~
gitclonehttps://github.com/saltstack/salt.git cdsalt ./setup.pyinstall
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.doccmd Description Saltsshallowsforsaltroutinestobeexecutedusingonlysshfortransport Options -r,--raw,--raw-shell Executearawshellcommand. 要執行的命令,支援管道和常用的特殊符號 --roster-file Definewhichrostersystemtouse,thisdefinesifadatabasebackend,scanner,orcustomrostersystemisused.Defaultistheflatfileroster. 指定一個資訊檔案 --refresh,--refresh-cache Forcearefreshofthemastersidedatacacheofthetarget'sdata.Thisisneededifatarget'sgrainshavebeenchangedandtheautorefreshtimeframehasnotbeenreached. --max-procs Setthenumberofconcurrentminionstocommunicatewith.Thisvaluedefineshowmanyprocessesareopenedupatatimetomanageconnections,themorerunningprocessthefastercommunicationshouldbe,defaultis25. --passwd Settedefaultpasswordtoattempttousewhenauthenticating. --key-deploy Setthisflagtoattempttodeploytheauthorizedsshkeywithallminions.Thiscombinedwith--passwdcanmakeinitialdeploymentofkeysveryfastandeasy. --version PrinttheversionofSaltthatisrunning. --versions-report Showprogram'sdependenciesandversionnumber,andthenexit -h,--help Showthehelpmessageandexit -cCONFIG_DIR,--config-dir=CONFIG_dir ThelocationoftheSaltconfigurationdirectory.ThisdirectorycontainstheconfigurationfilesforSaltmasterandminions.Thedefaultlocationonmostsystemsis/etc/salt. TargetSelection -E,--pcre ThetargetexpressionwillbeinterpretedasaPCREregularexpressionratherthanashellglob. -L,--list Thetargetexpressionwillbeinterpretedasacomma-delimitedlist;example:server1.foo.bar,server2.foo.bar,example7.quo.qux -G,--grain ThetargetexpressionmatchesvaluesreturnedbytheSaltgrainssystemontheminions.Thetargetexpressionisintheformatof'<grainvalue>:<globexpression>';example:'os:Arch*' Thiswaschangedinversion0.9.8toacceptglobexpressionsinsteadofregularexpression.Touseregularexpressionmatchingwithgrains,usethe--grain-pcreoption. --grain-pcre ThetargetexpressionmatchesvaluesreturnedbytheSaltgrainssystemontheminions.Thetargetexpressionisintheformatof'<grainvalue>:<regularexpression>';example:'os:Arch.*' -N,--nodegroup UseapredefinedcompoundtargetdefinedintheSaltmasterconfigurationfile. -R,--range Insteadofusingshellglobstoevaluatethetarget,usearangeexpressiontoidentifytargets.Rangeexpressionslooklike%cluster. UsingtheRangeoptionrequiresthatarangeserverissetupandthelocationoftherangeserverisreferencedinthemasterconfigurationfile. LoggingOptions Loggingoptionswhichoverrideanysettingsdefinedontheconfigurationfiles. -lLOG_LEVEL,--log-level=LOG_LEVEL Consoleloggingloglevel.Oneofall,garbage,trace,debug,info,warning,error,quiet.Default:warning. --log-file=LOG_FILE Logfilepath.Default:/var/log/salt/ssh. --log-file-level=LOG_LEVEL_LOGFILE Logfileloggingloglevel.Oneofall,garbage,trace,debug,info,warning,error,quiet.Default:warning. OutputOptions --out Passinanalternativeoutputtertodisplaythereturnofdata.Thisoutputtercanbeanyoftheavailableoutputters: grains,highstate,json,key,overstatestage,pprint,raw,txt,yaml Someoutputtersareformattedonlyfordatareturnedfromspecificfunctions;forinstance,thegrainsoutputterwillnotworkfornon-grainsdata. Ifanoutputterisusedthatdoesnotsupportthedatapassedintoit,thenSaltwillfallbackonthepprintoutputteranddisplaythereturndatausingthePythonpprintstandardlibrarymodule. Note Ifusing--out=json,youwillprobablywant--staticaswell.Withoutthestaticoption,youwillgetaJSONstringforeachminion.Thisisduetousinganiterativeoutputter.SoifyouwanttofeedittoaJSONparser,use--staticaswell. --out-indentOUTPUT_INDENT,--output-indentOUTPUT_INDENT Printtheoutputindentedbytheprovidedvalueinspaces.Negativevaluesdisableindentation.Onlyapplicableinoutputtersthatsupportindentation. --out-file=OUTPUT_FILE,--output-file=OUTPUT_FILE Writetheoutputtothespecifiedfile. --no-color Disableallcoloredoutput --force-color Forcecoloredoutput
要是有好用的功能,我會再補上的~
新增 引數的方法
源地址:http://rfyiamcool.blog.51cto.com/1030776/1305710
我們來總結下哈:
好東西,saltstack是個神器,但是有些伺服器你死活裝不上saltstack客戶端,或者是有些業務線已經有puppet chef之類的,不太適合再裝saltsatck minion ,再或者是 我們可以時髦的用saltstack salt-ssh 直接代替簡單的expect寫的指令碼。。。。
轉載於:https://blog.51cto.com/rfyiamcool/1305710