saltstack

第一:安裝前準備:

聲明我用的是ubuntu 16.04的系統?

1.修改主機名,并保證兩臺機器可以互相ping同主機名

ip1  master_hostname
ip2  slave_hostname

第二:安裝

服務器安裝 yum install salt-master -y客戶端安裝 yum install salt-minion -y

ubuntu16.04的安裝完會自動啟動

第三:配置:

更改minion端的

master: master的ip地址(注意:  “:后面有一個空格”)

第四:認證:

master創建的key:

minion創建的key:

等待認證的key:

查看等待同意的key:

執行接受操作:

?查看key的位置,原本在pre下面,現在跑到了minion下面了

以上是簡單的查看了key的認證,下面我們看下salt-key的詳細用法:

# salt-key -h
Usage: salt-key [options]Salt key is used to manage Salt authentication keysOptions:--version             show program's version number and exit--versions-report     show program's dependencies version number and exit-h, --help            show this help message and exit--saltfile=SALTFILE   Specify the path to a Saltfile. If not passed, onewill be searched for in the current working directory-c CONFIG_DIR, --config-dir=CONFIG_DIRPass in an alternative configuration directory.Default: /etc/salt-u USER, --user=USER  Specify user to run salt-key--hard-crash          Raise any original exception rather than exitinggracefully Default: False-q, --quiet           Suppress output-y, --yes             Answer Yes to all questions presented, defaults toFalse--rotate-aes-key=ROTATE_AES_KEYSetting this to False prevents the master fromrefreshing the key session when keys are deleted orrejected, this lowers the security of the keydeletion/rejection operation. Default is True.Logging Options:Logging options which override any settings defined on theconfiguration files.--log-file=LOG_FILELog file path. Default: /var/log/salt/key.--log-file-level=LOG_LEVEL_LOGFILELogfile logging log level. One of 'all', 'garbage','trace', 'debug', 'profile', 'info', 'warning','error', 'critical', 'quiet'. Default: 'warning'.Output Options:Configure your preferred output format--out=OUTPUT, --output=OUTPUTPrint the output from the 'salt-key' command using thespecified outputter. The builtins are 'key', 'yaml','overstatestage', 'highstate', 'newline_values_only','pprint', 'txt', 'raw', 'virt_query', 'compact','json', 'nested', 'quiet', 'no_return'.--out-indent=OUTPUT_INDENT, --output-indent=OUTPUT_INDENTPrint the output indented by the provided value inspaces. Negative values disables indentation. Onlyapplicable in outputters that support indentation.--out-file=OUTPUT_FILE, --output-file=OUTPUT_FILEWrite the output to the specified file--out-file-append, --output-file-appendAppend the output to the specified file--no-color, --no-colourDisable all colored output--force-color, --force-colourForce colored output--state-output=STATE_OUTPUT, --state_output=STATE_OUTPUTOverride the configured state_output value for minionoutput. One of full, terse, mixed, changes or filter.Default: full.--state-verbose=STATE_VERBOSE, --state_verbose=STATE_VERBOSEOverride the configured state_verbose value for minionoutput. Set to True or FalseDefault: TrueActions:-l ARG, --list=ARG  List the public keys. The args "pre", "un", and"unaccepted" will list unaccepted/unsigned keys. "acc"or "accepted" will list accepted/signed keys. "rej" or"rejected" will list rejected keys. "den" or "denied"will list denied keys. Finally, "all" will list allkeys.-L, --list-all      List all public keys. (Deprecated: use "--list all") #查看認證信息-a ACCEPT, --accept=ACCEPTAccept the specified public key (use --include-all tomatch rejected keys in addition to pending keys).Globs are supported.-A, --accept-all    Accept all pending keys   #接受全部的pending 狀態的minion-r REJECT, --reject=REJECTReject the specified public key (use --include-all tomatch accepted keys in addition to pending keys).Globs are supported.-R, --reject-all    Reject all pending keys--include-all       Include non-pending keys when accepting/rejecting-p PRINT, --print=PRINTPrint the specified public key-P, --print-all     Print all public keys-d DELETE, --delete=DELETE  Delete the specified key. Globs are supported.-D, --delete-all    Delete all keys  #刪除指定key-f FINGER, --finger=FINGERPrint the specified key's fingerprint-F, --finger-all    Print all keys' fingerprints
Key Generation Options:--gen-keys=GEN_KEYSSet a name to generate a keypair for use with salt--gen-keys-dir=GEN_KEYS_DIRSet the directory to save the generated keypair, onlyworks with "gen_keys_dir" option; default=.--keysize=KEYSIZE   Set the keysize for the generated key, only works withthe "--gen-keys" option, the key size must be 2048 orhigher, otherwise it will be rounded up to 2048; ;default=2048--gen-signature     Create a signature file of the masters public-keynamed master_pubkey_signature. The signature can besend to a minion in the masters auth-reply and enablesthe minion to verify the masters public-keycryptographically. This requires a new signing-key-pair which can be auto-created with the --auto-createparameter--priv=PRIV         The private-key file to create a signature with--signature-path=SIGNATURE_PATHThe path where the signature file should be written--pub=PUB           The public-key file to create a signature for--auto-create       Auto-create a signing key-pair if it does not yetexistYou can find additional help about salt-key issuing "man salt-key" or on
http://docs.saltstack.com #更多查看官網
View Code

第五:saltstack遠程執行命令:

1.測試與minion的通信是否正常

出現如上圖所示的情況,解決辦法:

?/etc/salt/master的配置文件中,將file_ignore_glob組的注釋全部打開,重啟master即可

2.遠程執行命令:

salt '*' cmd.run 'ls -l /etc'

?3.查看磁盤信息:

# salt '*' disk.usage
host-minion:----------/:----------1K-blocks:94326644available:87738788capacity:2%filesystem:/dev/mapper/ubuntu--vg-rootused:1773216/boot:----------1K-blocks:482922available:399773capacity:13%filesystem:/dev/sda1used:58215/dev:----------1K-blocks:4067252available:4067252capacity:0%filesystem:udevused:0/dev/shm:----------1K-blocks:4087280available:4087268capacity:1%filesystem:tmpfsused:12/run:----------1K-blocks:817460available:773752capacity:6%filesystem:tmpfsused:43708/run/lock:----------1K-blocks:5120available:5120capacity:0%filesystem:tmpfsused:0/run/user/1000:----------1K-blocks:817460available:817460capacity:0%filesystem:tmpfsused:0/sys/fs/cgroup:----------1K-blocks:4087280available:4087280capacity:0%filesystem:tmpfsused:0
View Code

4.查看網絡信息?salt '*' network.interfaces

5.查看幫助文檔信息 ?salt '*' sys.doc

6.匹配相關minion:

salt -G 'os:Ubuntu' test.ping

salt -E 'minion[0-9]' test.ping

salt -L 'minion1,minion2' test.ping

更多模塊的用法請查看官網文檔:

https://docs.saltstack.com

第六:列舉幾個常用的模塊:

列出當前版本支持的模塊:

# salt '*' sys.list_modules
host:- acl- aliases- alternatives- archive- artifactory- at- beacons- bigip- blockdev- btrfs- buildout- cloud- cmd- composer- config- consul- container_resource- cp- cpan- cron- data- debconf- defaults- devmap- dig- disk- django- dnsmasq- dnsutil- drbd- elasticsearch- environ- etcd- event- extfs- file- gem- genesis- git- grains- group- grub- hashutil- hg- hipchat- hosts- http- img- incron- ini- introspect- ip- iptables- jboss7- jboss7_cli- key- keyboard- kmod- locale- locate- logrotate- lowpkg- lvm- match- mine- modjk- mount- mysql- nagios_rpc- network- node- nspawn- openstack_config- pagerduty- pagerduty_util- partition- pillar- pip- pkg- pkg_resource- pkgbuild- publish- pushover- pyenv- raid- random- random_org- rbenv- rest_sample_utils- ret- rsync- runit- rvm- s3- saltutil- schedule- scsi- sdb- seed- serverdensity_device- service- shadow- slack- slsutil- smbios- smtp- splay- sqlite3- ssh- state- status- supervisord- sys- sysctl- syslog_ng- system- temp- test- timezone- tls- udev- uptime- user- vbox_guest- virtualenv- xfs- zfs
View Code

test.ping的api調用方式:

import salt.client
client = salt.client.LocalClient()
ret = client.cmd('*','test.ping') 
print(ret)

cmd模塊:遠程執行命令(上面已經列出)

#獲取所欲被控主機的內存使用情況
salt '*' cmd.run 'free -m'
API調用方式:
import salt.client
client = salt.client.LocalClient()
free = client.cmd('*','cmd.run',['free -m'])
print(free)

crontab 模塊

#為指定被控主機、root用戶添加計劃任務/usr/local/weekly任務
salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly #刪除指定被控主機、root用戶crontab的/usr/local/weekly任務
salt '*' cron.rm_job root /usr/local/weekly 

crontab的api調用:

增加crontab方式:
client.cmd('*','cron.set_job',['root','*','*','*','*',1,'/usr/local/weekly'])刪除crontab的方式:
client.cmd('*','cron.rm_job',['root','/usr/local/weekly'])

?

?

file模塊:

#校驗所有被控主機/etc/fstab文件的md5值是否為xxxxxxxxxxxxx,一致則返回True值
salt '*' file.check_hash /etc/fstab md5:a4e398d752713d5f12880a92c7dfd557#校驗所有被控主機文件的加密信息,支持md5、sha1、sha224、shs256、sha384、sha512加密算法
salt '*' file.get_sum /etc/passwd md5#修改所有被控主機/etc/passwd文件的屬組、用戶權限、等價于chown root:root /etc/passwd
salt '*' file.chown /etc/passwd root root#復制所有被控主機/path/to/src文件到本地的/path/to/dst文件
salt '*' file.copy /path/to/src /path/to/dst#檢查所有被控主機/etc目錄是否存在,存在則返回True,檢查文件是否存在使用file.file_exists方法
salt '*' file.directory_exists /etc#獲取所有被控主機/etc/passwd的stats信息
salt '*' file.stats /etc/passwd#獲取所有被控主機/etc/passwd的權限mode,如755,644
salt '*' file.get_mode /etc/passwd#修改所有被控主機/etc/passwd的權限mode為0644
salt '*' file.set_mode /etc/passwd 0644#在所有被控主機創建/opt/test目錄
salt '*' file.mkdir /opt/test#將所有被控主機/etc/httpd/httpd.conf文件的LogLevel參數的warn值修改為info
salt '*' file.sed /etc/httpd/httpd.conf 'LogLevel warn' 'LogLevel info'#給所有被控主機的/tmp/test/test.conf文件追加內容‘maxclient 100’
salt '*' file.append /tmp/test/test.conf 'maxclient 100'#刪除所有被控主機的/tmp/foo文件
salt '*' file.remove /tmp/foo

service服務模塊:

#開啟(enable)、禁用(disable)nginx開機自啟動腳本
salt '*' service.enable nginx
salt '*' service.disable nginx#針對nginx服務的reload、restart、start、stop、status操作
salt '*' service.reload nginx
salt '*' service.restart nginx
salt '*' service.start nginx
salt '*' service.stop nginx
salt '*' service.status nginx

service的API調用:

client.cmd('*','service.stop',['nginx'])

cp模塊:

#  cp /opt/getfile.txt /srv/salt/
# salt '*' cp.get_file salt://getfile.txt /opt/getfile.txt 
salt-client:/opt/getfile.txt

轉載于:https://www.cnblogs.com/ylqh/p/7067709.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/371874.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/371874.shtml
英文地址,請注明出處:http://en.pswp.cn/news/371874.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ios 百度地圖指定區域_獲取百度地圖可視區域范圍的數據

有個業務場景,需要根據獲取到的地圖區域顯示,根據相應的經緯度反查 左側區域的會議室。思路:1.得到百度地圖可視區域--可視區域的中心點2.可視區域的四個角的其中兩個(東北角西南角)http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_refer…

使用WS-Trust / STS采樣器擴展JMeter

JMeter沒有對WS-Security或WS-Trust的任何內置支持,這使我為JMeter開發了此STS Sampler –可以在負載測試STS時使任何人的生活變得更好。 首先,您需要擁有Apache JMeter發行版。 我正在使用v2.7。 然后,您可以從此處下載sts.sampler.zip –解…

分享一個使用閉包對一個對象繼承方式

function Person(name,age){this.name name;this.age age; }//定義一個new函數 繼承了對Person的繼承 function New(obj){return function(){var o {"__proto__":obj.proto};obj.apply(o,arguments);}return obj; }var n new New(Person)("對象繼承了person…

vue怎么改logo_vue全家桶項目構建教程

前言vue是現階段很流行的前端框架,很多人通過vue官方文檔的學習,對vue的使用都有了一定的了解,但再在項目工程化處理的時候,卻發現不知道改怎么更好的管理自己的項目,如何去引入一些框架以及vue全家桶其他框架的使用&a…

EclipseLink MOXy作為JAXB提供者

EclipseLink MOXy是JAXB提供程序,并且是內置在JDK中的默認JAXB提供程序的引人注目的替代品。 首先是一個簡單的測試,將Java對象編組為XML: 這是模型: XmlRootElement(nameMemberDetailsRequest, namespacehttp://bk.org/members…

monkeyrunner多點觸摸

思路是:在屏幕上某個位置按著不放:device.touch(x,y,md.DOWN) 然后再做一個滑動的操作:device.drap((x1,y1),(x2,y2),0.2,10) 然后再松開按鍵:device.touch(x,y,md.UP) #codeing:utf-8 from com.android.monkeyrunner import Monk…

雅虎前端優化的35條軍規

閱讀目錄 內容部分css部分js部分javascript, css 圖片 cookie移動端 服務器摘要:無論是在工作中,還是在面試中,web前端性能的優化都是很重要的,那么我們進行優化需要從哪些方面入手呢?可以遵循雅虎的前端優化34條軍規&…

stm32 內部sram大小_在SRAM、FLASH中調試代碼的配置方法(附詳細步驟)

聊天界面發送嵌入式大雜燴獲取1TB大雜燴資料包STM32的FLASH擦寫次數有限(大概為1萬次),所以為了延長FLASH的使用時間,我們平時調試時可以選擇在SRAM中進行硬件調試。除此之外,SRAM 存儲器的寫入速度比在內部 FLASH 中要快得多,所以…

Spring Profile模式示例

最近,我們介紹了Spring Profiles的概念。 此概念是針對不同部署環境的輕松配置區分符。 直接的用例(已提出)是對相關類進行注釋,以便Spring根據活動的配置文件加載適當的類。 但是,這種方法可能并不總是適用于常見的…

Android 樣式 (style) 和主題(theme)

轉載:https://gold.xitu.io/post/58441c48c59e0d0056a30bc2 樣式和主題 樣式是指為 View 或窗口指定外觀和格式的屬性集合。樣式可以指定高度、填充、字體顏色、字號、背景色等許多屬性。 樣式是在與指定布局的 XML 不同的 XML 資源中進行定義。 Android 中的樣式與…

自定義控件_VIewPager顯示多個Item

一直以來想搞明白這個不完全的VIewPager是怎么做到的&#xff0c;有幸看到這片篇文章 有二種實現方法 1.設置的屬性 1.clipChildren屬性 2.setPageMargin 3.更新Item外界面 2.重寫getPageWidth public class MultiplePagerAdapter extends PagerAdapter { private List<I…

華為怎么改輸入法皮膚_微信和QQ個性鍵盤皮膚

hello大家好&#xff0c;今天是2019年1月1號&#xff0c;祝大家新年快樂今天是新年的第一天&#xff0c;所以說給大家介紹一個好玩的&#xff0c;微信和QQ都能設置的個性的鍵盤皮膚&#xff0c;看下圖&#xff0c;這樣的個性的鍵盤主題怎么設置呢&#xff1f;其實很簡單&#x…

EasyMock教程–入門

在本文中&#xff0c;我將向您展示EasyMock是什么&#xff0c;以及如何使用它來測試Java應用程序。 為此&#xff0c;我將創建一個簡單的Portfolio應用程序&#xff0c;并使用JUnit&#xff06;EasyMock庫對其進行測試。 在開始之前&#xff0c;讓我們首先了解使用EasyMock的需…

synchronized內置鎖

synchronized內置鎖&#xff0c;如果發生阻塞&#xff0c;無法被中斷&#xff0c;除非關閉jvm.因此不能從死鎖中恢復。轉載于:https://www.cnblogs.com/paulbai/p/6163250.html

如何加快Json 序列化?有哪些方法?

1、使用阿里的fastjson 2、可以通過去除不必要屬性加快序列化。如person對象&#xff0c;有id&#xff0c;name&#xff0c;address&#xff0c;我json需要用戶姓名&#xff0c;此時序列化的時候就只序列化name&#xff0c;id和address不序列化。轉載于:https://www.cnblogs.co…

用金萬維怎么設置路由器_家用路由器怎么設置 家庭路由器設置方法【圖文】...

這里以TP-link的無線路由器為例&#xff0c;教一下怎么調試路由器上網。準備工具:網線兩條&#xff0c;電腦或者手機&#xff0c;用手機的話就不需要用網線了1、用網線連接光纖貓與路由器&#xff0c;光貓的LAN1口與路由器的WAN相連。路由器的LAN任意一個口用網線連接電腦。2、…

Liferay –簡單主題開發

實際上&#xff0c;Liferay的6.1版本已經走了很長一段路&#xff0c;該版本完全支持JSF和IceFaces。 我的目標是使它成為我們團隊中的標準協作工具&#xff0c;因此我仍在嘗試學習它的精髓。 好的軟件應用程序可以解決問題&#xff0c;但是好的軟件應用程序不僅可以解決問題&am…

springmvc初步配置

導包/添加依賴&#xff1a;<dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.springfram…

獲取用戶地理位置

1、利用h5 屬性獲取用戶地理位置 h5的新增屬性是支持用戶獲取地理位置的特別是手機&#xff0c;支持的情況會更好。具體寫法如下 // 定位功能getLocation () {if (navigator.geolocation) {navigator.geolocation.getCurrentPosition(showPosition, showError);} else {alert(瀏…

行號 設置vim_在VSCode里面配置Vim正確姿勢(細節解析)

一、導論對于不用vim的人來說&#xff0c;vim簡直是個噩夢&#xff0c;復雜的指令、丑陋的界面、令人頭痛的配置文件&#xff0c;任何一項都足以勸退一大波人&#xff0c;但是對于已經習慣了使用vim的人來說&#xff0c;vim簡直就是馬良神筆&#xff0c;似乎vim除了生孩子什么都…