salt stack学习笔记
saltstack运行模式:
local
master/minion
salt ssh
saltstack三大功能
远程执行命令
配置管理(状态管理)
云管理
安装:
master salt-master
agent salt-minion
salt-key命令
accepted keys: 接受的key
denied keys: 拒绝的key
unaccepted keys: 没有接受的key
rejected keys: 拒绝的key
agent的minion_id保存路径:/etc/salt/minion_id
全部接受使用:salt-key -A -y
查看结果:salt-key -L
salt执行单条命令
salt 被执行主机 模块 命令
salt '*' test.ping 对所有主机执行ping命令;
cmd.run 'hostname' 执行命令
state.highstate master状态同步
state.highstate test=True 同步之前测试语法
-E 对被执行主机可以用正则;
-L 指定执行列表
salt -L 'minion1,minion2' com.run 'hostname'
-S 指定子网段
-S '192.168.1.0/24'
配置管理
1、定义环境
/etc/salt/master
p.p1 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 163, 1) }
p.p2 { margin: 0; font: 14px Menlo; color: rgba(64, 11, 217, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures; color: rgba(64, 11, 217, 1) }
span.s2 { font-variant-ligatures: no-common-ligatures; background-color: rgba(224, 228, 9, 1) }
span.s3 { font-variant-ligatures: no-common-ligatures }
file_roots:
base: 基础环境 2个空格
- /srv/salt/ 4个空格
dev: 开发环境
- /srv/salt/dev/services
- /srv/salt/dev/states
prod: 生产环境
- /srv/salt/prod/services
- /srv/salt/prod/states
2、定义入口
所有salt的配置文件都是以sls结尾;
路径:/srv/salt/
vim top.sls
p.p1 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 0, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures }
定义top示例:
base:
'*':
- apache
应用内容示例:
apache-pkg:
pkg.installed:
- names:
- httpd
- mod_ssl
apache-service:
service.running:
- name: httpd
- enable: True
数据系统Grains
grains里面收集了minion启动时候的所有系统信息,存储在minion端;
salt 'host' grains.ls 所有的grains信息
grains.item os os的值
osrelease 系统版本
示例:
salt -G 'osrelease:7.3.1611' test.ping
自定义Grains
方法
p.p1 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 0, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures }
/etc/salt/minion
p.p1 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 163, 1) }
p.p2 { margin: 0; font: 14px Menlo; color: rgba(64, 11, 217, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures; color: rgba(64, 11, 217, 1) }
span.s2 { font-variant-ligatures: no-common-ligatures; background-color: rgba(224, 228, 9, 1) }
span.s3 { font-variant-ligatures: no-common-ligatures }
#grains:
# roles:
# - webserver
# - memcache
# deployment: datacenter4
# cabinet: 13
# cab_u: 14-15
数据系统Pillar
master端设置,提供给minion端;
pillar在saltstack中主要作用是存储和定义配置管理中需要的一些数据,比如软件版本好,用户名密码信息,它的存储格式跟Grains类似,都是yaml格式;
/etc/salt/master
p.p1 { margin: 0; font: 14px Menlo; color: rgba(64, 11, 217, 1) }
p.p2 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 163, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures }
span.s2 { font-variant-ligatures: no-common-ligatures; color: rgba(0, 0, 163, 1); background-color: rgba(224, 228, 9, 1) }
span.s3 { font-variant-ligatures: no-common-ligatures; color: rgba(64, 11, 217, 1) }
span.s4 { font-variant-ligatures: no-common-ligatures; background-color: rgba(224, 228, 9, 1) }
#pillar_roots:
# base:
# - /srv/pillar
#
#ext_pillar:
# - hiera: /etc/hiera.yaml
# - cmd_yaml: cat /etc/salt/yaml
定义pillar的入口
vim /srv/pillar/top.sls
p.p1 { margin: 0; font: 14px Menlo; color: rgba(46, 174, 187, 1) }
p.p2 { margin: 0; font: 14px Menlo; color: rgba(180, 36, 25, 1) }
p.p3 { margin: 0; font: 14px Menlo; color: rgba(0, 0, 0, 1) }
span.s1 { font-variant-ligatures: no-common-ligatures }
span.s2 { font-variant-ligatures: no-common-ligatures; color: rgba(200, 20, 201, 1) }
span.s3 { font-variant-ligatures: no-common-ligatures; color: rgba(0, 0, 0, 1) }
span.s4 { font-variant-ligatures: no-common-ligatures; color: rgba(193, 101, 28, 1) }
base:
"*":
- packages
- services
- command
- isp
刷新pillar
salt '*' saltutil.refresh_pillar
master端验证
salt -I 'roles:ftpserver' cmd.run 'uptime'
远程执行Targeting
与minion_id相关
Globbing(通配符)
* ? []都支持;
Regex(正则)
List(列表)
与Minion_id无关:
Subnet/IP (子网)
Grains
Pillar
Compound matchers(复合匹配)
-C 指定
salt -C 'I@roles:deserver and I@deployment:datacenter4' test.ping
Node Groups(节点组)
-N 指定
当在sls文件中使用正则时:
base:
'slatstack0[^23].test.com':
- match: pcre #必须引入salt的pcre库;
- apache
当在ssl文件中使用Grains时:
base:
'os:CentOS':
- match: grain #引入grain库
- apache
salt modules
https://docs.saltstack.com/en/latest/
salt '*' sys.list_modules 列出所有模块
salt '*' sys.list_functions grains 列出grains模块的用法
sys.doc grains 查看grains帮助
sys.doc grains.item 查看item帮助
sys.doc pkg
service.available 服务是否可用
.missing 包是否缺失
state.show_top 应用了哪些模块
state.show_highstate 更详细的状态
state.sls httpd 只同步某一个任务
salt 'test04' state.sls apache env=base 将base环境中的apache环境应用给test04主机;
salt远程执行returners
return组件可以理解为saltstack系统对执行minion返回后的数据存储和返回给其他程序;支持多种存储方式,例如mysql;mongodb;memcache等;通过return可以对saltstack每次的操作进行记录,对以后的日志审计提供数据;
mysql_secure_installation 设置mysql密码;
配置管理states
states是saltstack系统的配置语言,在日常韵味中需要编写大量的states文件,例如创建用户,安装软件包,管理相应配置文件;则需要编写一些states sls文件,即状态配置文件去描述和实现相应的功能;states sls 主要使用yaml语言;也可以支持使用python语言;
配置管理状态关系
unless 主要用于cmd状态模块,仅当unless选项指向的命令;
返回false时才执行name指向的命令,test -d /usr/local/nginx
require 我依赖某个状态,我依赖谁
示例:
lamp-pkg-install:
pkg.installed:
- names:
- httpd
- php
-php-mysql
httpd-files:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://files/httpd.conf
- require:
- pkg: lamp-pkg-install
httpd-service:
server.running:
- name : httpd
- enable: True
- reload: True (如果不写则是restart)
- require:
- file: httpd-files
- watch:
- file: httpd-files 只要配置文件发生改变即reload服务
require_in 我被某个状态依赖 谁依赖我
watch 我关注某个状态,当状态发生改变,则restart
watch_in 我被某个状态关注;
配置管理jinja模版
{{ 变量 }}与变量列表defaults必须一一对应;
vim httpd.conf
Listen {{ IP }}:{{ PORT }}
httpd-files:
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://files/httpd.conf
- template: jinja #必须要告诉它是jinja模版
- require:
- pkg: lamp-pkg-install
- defaults:
IP: {{ grains['fqdn_ip4'][0] }}
PORT: 7777
salt stack学习笔记的更多相关文章
- Docker Stack 学习笔记
该文为<深入浅出Docker>的学习笔记,感谢查看,如有错误,欢迎指正 一.简介 Docker Stack 是为了解决大规模场景下的多服务部署和管理,提供了期望状态,滚动升级,简单易用,扩 ...
- Core Data Stack学习笔记
Entity Entities 实体->数据表一个实体可以表示一个数据模型 1> 通过图形化界面可以建立一个模型关系图,可以指定一对多,多对一,多对多的数据关系 -在数据库开发中,少用多对 ...
- Salt Document学习笔记2
配置文件需修改的内容及注意点: Edit the master config file: 1. Uncomment and change the user: root value to your ow ...
- Salt Document学习笔记1
原文来自Salt Documentation,作者是 Thomas Hatch),我摘抄部分可能今后会用到或适合入门到精通的一些原文段落,简单翻译后发上来,便于查阅和研究 一.原理方面:The net ...
- Flutter学习笔记(23)--多个子元素的布局Widget(Rwo、Column、Stack、IndexedStack、Table、Wrap)
如需转载,请注明出处:Flutter学习笔记(23)--多个子元素的布局Widget(Rwo.Column.Stack.IndexedStack.Table.Wrap) 上一篇梳理了拥有单个子元素布局 ...
- stl源码剖析 详细学习笔记stack queue
// // stack.cpp // 笔记 // // Created by fam on 15/3/15. // // //---------------------------15/03/1 ...
- 七天学会 SALT STACK 自动化运维 (1)
七天学会 SALT STACK 自动化运维 (1) 简单理解 SALTSTACK 安装与配置 基本的使用方法 结束语 引用资源 简单理解 SALT STACK 笔者是初次接触 自动化运维 这一技术领域 ...
- 基于.net的分布式系统限流组件 C# DataGridView绑定List对象时,利用BindingList来实现增删查改 .net中ThreadPool与Task的认识总结 C# 排序技术研究与对比 基于.net的通用内存缓存模型组件 Scala学习笔记:重要语法特性
基于.net的分布式系统限流组件 在互联网应用中,流量洪峰是常有的事情.在应对流量洪峰时,通用的处理模式一般有排队.限流,这样可以非常直接有效的保护系统,防止系统被打爆.另外,通过限流技术手段,可 ...
- ucos实时操作系统学习笔记——操作系统在STM32的移植
使用ucos实时操作系统是在上学的时候,导师科研项目中.那时候就是网上找到操作系统移植教程以及应用教程依葫芦画瓢,功能实现也就罢了,没有很深入的去研究过这个东西.后来工作了,闲来无聊就研究了一下这个只 ...
随机推荐
- selenium模块使用详解、打码平台使用、xpath使用、使用selenium爬取京东商品信息、scrapy框架介绍与安装
今日内容概要 selenium的使用 打码平台使用 xpath使用 爬取京东商品信息 scrapy 介绍和安装 内容详细 1.selenium模块的使用 # 之前咱们学requests,可以发送htt ...
- 大陆出境海缆TPE APCN NCP APG简介
目前我国的登陆站主要设立在三个城市 山东 山东青岛登陆站(隶属中国联通) EAC-C2C TPE(美国方向) 上海 上海崇明登陆站(隶属中国电信) APCN2(亚太) NCP(长线--美国,新建,亚太 ...
- ubuntu 20.04 source mirror(aliyun)
x64 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://m ...
- 个人冲刺(六)——体温上报app(二阶段)
冲刺任务:完成主页面功能 MainActivity.java package com.example.helloworld; import android.app.AlertDialog; impor ...
- Servlet表单数据
1.GET 方法 GET 方法向页面请求发送已编码的用户信息.页面和已编码的信息中间用 ? 字符分隔,如下所示: http://www.test.com/hello?key1=value1&k ...
- bare Git 仓库是什么?
背景 今天,坐我旁边的同事问我一些关于服务器上命令的问题.其中有一个用了特殊参数的 git init 的命令,我也不认识,遂去 Google... bare Git 仓库 定义 A bare Git ...
- 入坑KeePass(三)安全设置完后后留存
1.文件> 数据库设置 > 安全 迭代次数改成500000 2.工具 > 选项 2.1.安全 2.2.策略 2.3.集成 2.4高级
- 浅析DispatchProxy动态代理AOP
浅析DispatchProxy动态代理AOP(代码源码) 最近学习了一段时间Java,了解到Java实现动态代理AOP主要分为两种方式JDK.CGLIB,我之前使用NET实现AOP切面编程,会用Fil ...
- SAP BPC 开发日记
1.获取维度模型的方法1 DATA:i_appset_id TYPE uj_appset_id, i_appl_id TYPE uj_appl_id.i_appset_id = 'SINO ...
- 搭建uipath
我对windows也不太熟,也是第一次安装Uipath Orchestrator,希望有问题指出一起交流,可以留言,Uipath中文qq交流群:4656303241. 下载镜像 windows ser ...