saltstack学习-9:批量安装nginx服务并定时更新配置(pillar)
环境介绍:
slatmaster:10.80.0.162
minion01:10.80.0.163
minion02:10.80.0.164
目标:在两台minion上安装nginx服务,并定时同步master的nginx配置文件。
第一步,编写sls文件
[root@study02 salt]# tree . ├── etc │ ├── file │ │ └── passwd │ ├── nginx │ │ ├── conf.d │ │ │ └── default.conf │ │ └── nginx.conf │ └── script │ └── test.sh ├── sls │ ├── init.sls │ ├── nginx.sls │ └── test.sls ├── test.sls └── top.sls6 directories, 9 files
cat sls/nginx.sls nginx:pkg:- installedservice:- running- enable: True- reload: True- watch:- pkg: nginx- file: nginx.conf- file: default.conf nginx.conf:file.managed:- source: salt://etc/nginx/nginx.conf- user: root- group: root- mode: 644- name: /etc/nginx/nginx.confdefault.conf:file.managed:- source: salt://etc/nginx/conf.d/default.conf- user: root- group: root- mode: 644- name: /etc/nginx/conf.d/default.con
第二步,创建配置文件源目录,并将nginx的配置文件拷贝到对应路径下
[root@study02 salt]# cd /srv/salt/ [root@study02 salt]# mkdir etc/nginx/conf.d -p [root@study02 salt]# cp /etc/nginx/nginx.conf etc/nginx/ [root@study02 salt]# cp /etc/nginx/conf.d/default.conf etc/nginx/conf.d/
第三步:使用salt批量安装和并同步配置文件
[root@study02 salt]# salt 'study0[34]' state.sls sls.nginx study03: . . .Summary ------------ Succeeded: 4 Failed: 0 ------------ Total states run: 4study04: ---------- . . .Summary ------------ Succeeded: 4 (changed=3) Failed: 0 ------------ Total states run: 4
第四步在客户端验证nginx是否安装,启动成功
[root@study02 salt]# salt 'study0[34]' cmd.run 'rpm -qa|grep nginx' study04:nginx-mod-mail-1.10.2-1.el6.x86_64nginx-filesystem-1.10.2-1.el6.noarchnginx-mod-http-image-filter-1.10.2-1.el6.x86_64nginx-mod-http-perl-1.10.2-1.el6.x86_64nginx-mod-http-geoip-1.10.2-1.el6.x86_64nginx-mod-stream-1.10.2-1.el6.x86_64nginx-1.10.2-1.el6.x86_64nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64nginx-all-modules-1.10.2-1.el6.noarch study03:nginx-filesystem-1.10.2-1.el6.noarchnginx-mod-http-image-filter-1.10.2-1.el6.x86_64nginx-mod-http-geoip-1.10.2-1.el6.x86_64nginx-mod-stream-1.10.2-1.el6.x86_64nginx-1.10.2-1.el6.x86_64nginx-mod-mail-1.10.2-1.el6.x86_64nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64nginx-all-modules-1.10.2-1.el6.noarchnginx-mod-http-perl-1.10.2-1.el6.x86_64 [root@study02 salt]# salt 'study0[34]' cmd.run 'netstat -nltup|grep "8080"' study04:tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31246/nginx tcp 0 0 :::80 :::* LISTEN 31246/nginx study03:tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 32487/nginx tcp 0 0 :::80 :::* LISTEN 32487/nginx
第五步:修改配置文件,测试配置文件同步,minion同步成功后,重启nginx(reload)
- 修改配置文件,将端口改为8080
[root@study02 salt]# cat etc/nginx/conf.d/default.conf # # The default server server {listen default_server;listen [::]: default_server; . . .
- 使用salt同步配置文件,并重启nginx
[root@study02 salt]# salt 'study0[34]' state.sls sls.nginx
- 验证minion的nginx配置文件是否同步成功,端口是否更改
[root@study02 salt]# salt 'study0[34]' cmd.run 'netstat -nltup|grep "8080"' study04:tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 31246/nginx tcp 0 0 :::8080 :::* LISTEN 31246/nginx study03:tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 32487/nginx tcp 0 0 :::8080 :::* LISTEN 32487/nginx
扩展:在minion端执行sls
- 修改配置文件,将端口改回 80
- 在minion01执行文件同步sls,并验证端口是否修改成功
[root@study03 nginx]# salt-call state.sls sls.nginx [root@study03 nginx]# netstat -lntup |grep "80" tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 594/nginx
- minion02没有执行,端口任然为8080
[root@study04 ~]# netstat -lntup |grep -E ":8080|:80" tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 31246/nginx tcp 0 0 :::8080 :::* LISTEN 31246/nginx
定时同步方法一:在minion端将salt-call state.sls sls.nginx 写入到定时任务中去。
Pillar
Pillar是salt非常重要的一个组件,它用于给特定的minion定义任何你需要的数据,这些数据可以被salt的其它组件使用。Salt在0.98版本中引入了Pillar。
Pillar在解析完成后,是一个嵌套的字典结构;最上层的key是minion ID,其value是改minion所拥有的Pillar数据;每一个value也都是key:value。
这里可以看出一个特点,Pillar数据是与特定minion关联的,也就是说每一个minion都只能看到自己的Pillar数据,所以可以用Pillar传递敏感数据(在salt的设计中,Pillar使用独立的加密session,也是为了保证敏感数据的安全性)
Pillar使用场景
- 敏感数据:例如ssh-key,加密证书,由于Pillar使用独立的加密session,可以确保这些敏感数据不给其它minion看到;
- 变量:可以在Pillar中处理平台差异性,比如针对不同的操作系统设置软件包的名字,然后在State中使用;
- 其它任何数据:可以在Pillar中添加任何需要用到的数据。比如定义用户和UID的对应关系,minion的角色等等;
- target中:Pillar可以用来选择minion,使用-l选项。默认情况下,master的配置文件中的所有数据都添加到Pillar中,且对所有minion可用。如果要禁用这一默认值,可以在master配置文件中添加如下数据,重启服务后生效;
Pillar示例
官网地址:http://docs.saltstack.cn/topics/jobs/index.html
第一步:修改master配置文件
[root@study02 srv]# vim /etc/salt/master ##### Pillar settings ##### ########################################## # Salt Pillars allow for the building of global data that can be made selectively # available to different minions based on minion grain filtering. The Salt # Pillar is laid out in the same fashion as the file server, with environments, # a top file and sls files. However, pillar data does not need to be in the # highstate format, and is generally just key/value pairs. pillar_roots:base:- /srv/pillar
第二步:创建top.sls和nginx.sls
[root@study02 srv]# tree pillar/ pillar/ ├── nginx │ └── nginx.sls └── top.sls
[root@study02 pillar]# cat top.sls base:'*':- 'nginx.nginx'
[root@study02 pillar]# cat nginx/nginx.sls schedule:test:function: state.slsminutes: 3600args:- 'nginx.nginx'
第三步:下发pillar数据,查看是否生效
[root@study02 srv]# salt 'study0[34]' pillar.data study04:----------schedule:----------test:----------args:- nginx.nginxfunction:state.slsminutes:1 study03:----------schedule:----------test:----------args:- nginx.nginxfunction:state.slsminutes:1
第四步:pillar数据虽然已经下发给minion但是还没有生效,需要刷新pillar数据,执行如下命令:
[root@study02 srv]# salt 'study0[34]' saltutil.refresh_pillar study03:True study04:True
第五步:验证端口,是否更新
[root@study02 pillar]# salt 'study0[34]' cmd.run 'netstat -lntup|grep -E ":80|:8080"' study04:tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 711/nginx study03:tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2196/nginx
转载于:https://www.cnblogs.com/snailshadow/p/8228022.html
saltstack学习-9:批量安装nginx服务并定时更新配置(pillar)相关推荐
- Linux state 方式 安装nginx 服务
第3章 Linux state 方式安装nginx 服务 3.1 State 方式安装nginx 1,创建相应的目录 a)Mkdir –p /srv/nginx 2,生成nginx.sls 文件 a) ...
- linux 系统 安装 nginx 服务
nginx安装位置: /usr/local/nginx 注意:该目录(/usr/local/nginx/html)下存在部署的服务,升级时注意备份,升级后须确保项目迁移并存在: nginx 安装所需依 ...
- centos nginx不是命令_Linux使用yum安装nginx服务教程
概述 一般我们测试环境的话如果需要安装nginx服务,肯定是越快越好,这时候就可以用yum这个方式来安装了,时间短,见效快,下面简单记录一下. 1.添加yum源 默认情况Centos7中无Nginx的 ...
- 【CNMP系列】CentOS7.0下安装Nginx服务
[CNMP系列]CentOS7.0下安装Nginx服务 话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下 ...
- windows 安装Nginx服务
1.下载windows版的Nginx安装包,进入类似下图页面,选择合适版本下载. 下载后解压,如下图 在C:\Program Files路径下创建Nginx文件夹,把解压后的内容放在Nginx文件下 ...
- Centos安装Nginx并使用acme脚本配置SSL证书
仅做记录供以后查看,所有代码来自互联网查找整理 1. 更新yum源 yum update 2. 查看防火墙并开放所需端口 firewall-cmd --zone=public --list-ports ...
- AirSim学习和踩坑记录(不定时更新)
版权声明:本文为博主原创文章,遵循Creative Commons - Attribution-ShareAlike 4.0 International - CC BY-SA 4.0版权协议,转载请附 ...
- saltstack自动化运维部署--安装apache\原码安装nginx服务
对saltstack自动化运维部署的认识 原理 SaltStack 是一种基于 C/S 架构的服务器基础架构集中化管理平台,管理端称为 Master,客户端称为 Minion.SaltStack 具备 ...
- Docker学习(七)-----Docker安装nginx
基本安装 1. 拉取Nginx镜像 docker pull nginx:latest 2. 查看本地镜像列表(即可看到nginx) docker images 3. 运行容器 docker run - ...
最新文章
- ruby生成C++头文件引用关系图
- (旧)走遍美国——(三、文化4)
- 机器学习面试题(part3)
- Jenkins 使用 maven 出现C:\Windows\system32\config\systemprofile的解决
- ListView滑动删除效果实现
- js年会抽奖_嘿!这真的是一个正经的抽奖程序!
- 现在的计算机电源都要经过,电脑待机后必须关闭电源才能开启
- 汇编语言-学习笔记(一)
- python3.6.5 安装第三方库
- Android studio profiler中的Shallow size和retained sizes是什么意思
- MySQL数据库性能优化--数据分库分表
- R语言用quantstrat包获取股票、债券、基金、黄金、原油、指数、外汇和全球经济数据
- mysql默认编码改为gbk_查看改mysql编码方式让它支持中文(gbk或者utf8)
- MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
- 48 《自私的基因》 -豆瓣评分8.6
- 计算机网络实验2--简单企业网络搭建
- Skeletal Animation(骨骼动画)
- Python应用开发——制作bin文件
- PWM调光5V脉冲信号转模拟量信号隔离转换器,PWM控制芯片
- 阅读《C++之父Bjarne谈C++在2005年》