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实时操作系统是在上学的时候,导师科研项目中.那时候就是网上找到操作系统移植教程以及应用教程依葫芦画瓢,功能实现也就罢了,没有很深入的去研究过这个东西.后来工作了,闲来无聊就研究了一下这个只 ...
随机推荐
- 老生常谈系列之Aop--前言
老生常谈系列之Aop--前言 前言 既然是前言,那么这一篇就不会写具体的技术问题.这篇文章主要记录我一些个人的思考以及为什么要写文章的缘由.前不久在跟朋友的交流中偶然聊到了Aop,Aop全称为 Asp ...
- 89. Gray Code - LeetCode
Question 89. Gray Code Solution 思路: n = 0 0 n = 1 0 1 n = 2 00 01 10 11 n = 3 000 001 010 011 100 10 ...
- linux篇-linux修改网卡名(亲测有效)
1查看网卡ip addr 2cd /etc/sysconfig/network-scripts Ls查看 3mv ifcfg-eno16777736 ifcfg-eth0重命名,然后编辑 最后一行加入 ...
- linxu篇-centos搭建ftp服务器
1安装vsftpd 2备份配置文件 3修改配置文件 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO #允许匿名用户访问为了安全选择关闭 local_ena ...
- 用Repo管理自己的本地仓库
AOSP使用Repo工具管理项目源码.而Repo工具则依赖一个名叫manifest的git仓库来记录Android源码中都包含哪些子仓库. 进入Android源码根目录下的.repo目录,可以看到ma ...
- 博弈论(nim游戏,SG函数)
说到自己,就是个笑话.思考问题从不清晰,sg函数的问题证明方法就在眼前可却要弃掉.不过自己理解的也并不透彻,做题也不太行.耳边时不时会想起alf的:"行不行!" 基本的小概念 这里 ...
- AT32F415 修改时钟和晶振方法(原创)
1. 简介 我们几乎是国内第一批使用AT32F415芯片的客户,那个时候芯片还没涨价,岁月一切静好.使用AT32F415 做了几个小产品,也在持续出货.后来大家都知道,涨价缺货愈演愈烈.好在我们提前囤 ...
- c++ 辗转相除(动图)
#include<iostream> #include<cstdio> #include<iomanip> #include<cstring> usin ...
- 【抬杠C#】如何实现接口的base调用
背景 在三年前发布的C#8.0中有一项重要的改进叫做接口默认实现,从此以后,接口中定义的方法可以包含方法体了,即默认实现.不过对于接口的默认实现,其实现类或者子接口在重写这个方法的时候不能对其进行ba ...
- Docker容器安装RabbitMQ
Docker容器安装RabbitMQ 准备资料 erlang的rpm安装包 https://github.com/rabbitmq/erlang-rpm/releases rabbitmq的rpm安装 ...