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.mzph.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除了生孩子什么都…