实验环境

node1  192.168.56.11   角色  salt-master

node2  192.168.56.12   角色  salt-minon

完成内容

Salt远程安装Redis服务

步骤

在前面的文章中已经搭建好了salt-master和saltminion环境

一,在prod目录下创建redis相关的目录,存放状态文件
[root@linux-node1 ~]# cd /srv/salt/prod/
[root@linux-node1 prod]# mkdir modules/redis -p
[root@linux-node1 prod]# tree
.
└── modules
└── redis
二,进入redis目录创建redis基础状态文件,这里我们用简单的rpm包按照为例
[root@linux-node1 redis]# cat redis-install.sls
redis-install:
pkg.installed:
- name: redis
三,有时候我们修改redis的配置文件或创建集群
[root@linux-node1 prod]# pwd
/srv/salt/prod
[root@linux-node1 prod]# mkdir redis-cluster
[root@linux-node1 prod]# cd redis-cluster/
[root@linux-node1 redis-cluster]# vi redis-master.sls
[root@linux-node1 redis-cluster]# cat redis-master.sls
include:
- modules.redis.redis-install redis-master-config:
file.managed:
- name: /etc/redis.conf
- source: salt://redis-cluster/files/redis-master.conf
- user: root
- group: root
- mode: 644
- template: jinja
- defaults:
REDIS_MEM: 1G redis-master-service:
service.running:
- name: redis
- enable: True
- watch:
- file: redis-master-config
四,按照redis取配置文件作为salt模板
[root@linux-node1 redis-cluster]# yum install redis
[root@linux-node1 redis-cluster]# cp /etc/redis.conf /srv/salt/prod/redis-cluster/files/
[root@linux-node1 redis-cluster]# tree
.
├── files
│   └── redis.conf
└── redis-master.sls
五,重命名redis模板文件名
[root@linux-node1 files]# mv redis.conf redis-master.conf
[root@linux-node1 files]# pwd
/srv/salt/prod/redis-cluster/files
六,更改redis配置文件模板,bind也可以只监听内网端口
[root@linux-node1 files]# grep -E  'bind|daemonize|maxmemory' redis-master.conf  |grep -v ^#
bind 0.0.0.0
daemonize yes
maxmemory {{ REDIS_MEM }}
七,测试,因为是在prod目录下 需要添加 saltenv=prod环境变量
[root@linux-node1 redis-cluster]# salt 'linux-node2*' state.sls redis-cluster.redis-master test=True saltenv=prod
linux-node2.example.com:
----------
ID: redis-install
Function: pkg.installed
Name: redis
Result: None
Comment: The following packages are set to be installed/updated: redis
Started: ::55.034779
Duration: 2514.889 ms
Changes:
----------
ID: redis-master-config
Function: file.managed
Name: /etc/redis.conf
Result: None
Comment: The file /etc/redis.conf is set to be changed
Started: ::57.551713
Duration: 27.659 ms
Changes:
----------
newfile:
/etc/redis.conf
----------
ID: redis-master-service
Function: service.running
Name: redis
Result: None
Comment: Service is set to be started
Started: ::57.637546
Duration: 71.324 ms
Changes: Summary
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
八,执行redis状态模块
[root@linux-node1 redis-cluster]# salt 'linux-node2*' state.sls redis-cluster.redis-master  saltenv=prod
linux-node2.example.com:
----------
ID: redis-install
Function: pkg.installed
Name: redis
Result: True
Comment: The following packages were installed/updated: redis
Started: ::16.616612
Duration: 15732.74 ms
Changes:
----------
jemalloc:
----------
new:
3.6.-.el7
old:
redis:
----------
new:
3.2.-.el7
old:
----------
ID: redis-master-config
Function: file.managed
Name: /etc/redis.conf
Result: True
Comment: File /etc/redis.conf updated
Started: ::32.351877
Duration: 45.19 ms
Changes:
----------
diff:
---
+++
@@ -, +, @@
#
# Examples:
#
-# bind 192.168.1.100 10.0.0.1
+#bind 0.0.0.0
# bind 127.0.0.1 ::
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
@@ -, +, @@
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-bind 127.0.0.1
+bind 0.0.0.0 # Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
@@ -, +, @@ # By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes # If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
@@ -, +, @@
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
-# maxmemory <bytes>
+maxmemory 1G # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
mode: user:
root
----------
ID: redis-master-service
Function: service.running
Name: redis
Result: True
Comment: Service redis has been enabled, and is running
Started: ::32.412154
Duration: 453.972 ms
Changes:
----------
redis:
True Summary
------------
Succeeded: (changed=)
Failed:
------------
Total states run:

salt 'linux-node2*' state.sls redis-cluster.redis-master saltenv=prod

九,登陆node2节点查看redis服务已经成功启动
[root@linux-node2 ~]# ps aux |grep redis
redis 0.3 0.3 ? Ssl : : /usr/bin/redis-server 0.0.0.0:
root 0.0 0.0 pts/ S+ : : grep --color=auto redis
[root@linux-node2 ~]#

总结

1.生产环境我们的状态模块可以在prod下面,在执行的时候需要设置环境saltenv=prod(使用top.sls不需要设置环境变量)

2.记得使用test=True先测试

3.提前查清楚软件包和相关配置文件

4.当使用jinja模板管理时,可以不用登陆redis服务器就可以查看redis设置的最大内存


附 赵班长的 GitHub saltbook-code网址

https://github.com/unixhot/saltbook-code/tree/master

SaltStack安装Redis-第十篇的更多相关文章

  1. SaltStack安装Redis模块

    安装redis Python Client 下载地址: https://pypi.python.org/simple/redis/ tar -xvf redis-2.8.0.tar.gz cd red ...

  2. 15天玩转redis —— 第十篇 对快照模式的深入分析

    我们知道redis是带有持久化这个能力了,那到底持久化成到哪里,持久化成啥样呢???这篇我们一起来寻求答案. 一:快照模式 或许在用Redis之初的时候,就听说过redis有两种持久化模式,第一种是S ...

  3. python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法

    python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法window安装redis,下载Redis的压缩包https://git ...

  4. SaltStack入门到精通第一篇:安装SaltStack

    SaltStack入门到精通第一篇:安装SaltStack 作者:纳米龙  发布日期:2014-06-09 17:50:36   实际环境的设定: 系统环境: centos6 或centos5 实验机 ...

  5. LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Redis篇

    文章来源:http://www.cnblogs.com/hello-tl/p/7569108.html 更新时间:2017-09-21 16:09 简介 LAMP+R指Linux+Apache+Mys ...

  6. SaltStack安装篇

    一.基础介绍1.简介 salt 是一个基础平台管理工具 salt是一个配置管理系统,能够维护预定于状态的远程节点 salt是一个分布式远程执行系统,用来在远程节点上执行命令和查询数据 2.salt的核 ...

  7. Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy、

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  8. Python开发【第十篇】:Redis

    缓存数据库介绍 NoSQL(Not Only SQL),即"不仅仅是SQL",泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应对web2.0网站,特别是 ...

  9. Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

随机推荐

  1. 修改mysql root的秘密

    修改mysql root的秘密 ');

  2. Spoken English Practice(Don't get me wrong, that explanation makes no difference, I'm still mad at you. Come on, be reasonable!)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/11) ...

  3. elasticsearch的store属性 vs _source字段

    众所周知_source字段存储的是索引的原始内容,那store属性的设置是为何呢?es为什么要把store的默认取值设置为no?设置为yes是否是重复的存储呢? 我们将一个field的值写入es中,要 ...

  4. 小程序 Page is not constructed because it is not found.

    如下错误一般发生在点击事件切换页面的时候 解决方式: 在需要切换到的那个页面的js文件中添加Page({ })方法即可解决此问题. Tis:在js文件中输入Page回车,可自动添加Page方法,包括里 ...

  5. Linux下安装谷歌访问助手,解压缩时出现中文乱码

    1.sudo apt-get install unar 安装unar 2.unar 谷歌访问助手chrome版本.zip   注意:使用 lsar 命令可以查看压缩文件内有那些文件: 例:lsar 谷 ...

  6. 使用 Apache Commons CLI 解析命令行参数示例

    很好的输入参数解析方法 ,转载记录下 转载在: https://www.cnblogs.com/onmyway20xx/p/7346709.html Apache Commons CLI 简介 Apa ...

  7. Google发布机器学习术语表 (包括简体中文)

    Google 工程教育团队已经发布了多语种的 Google 机器学习术语表,该术语表中列出了一般的机器学习术语和 TensorFlow 专用术语的定义.语言版本包括西班牙语,法语,韩语和简体中文. 查 ...

  8. ssh登录服务器

    ssh -i /home/zhangsuosheng/mykey.pub myusername@111.111.111.111

  9. Supervisor快速上手指南(转)

    原文:http://maemual.me/index.php/archives/8/ Supervisor是一个进程控制程序.用于监控管理你需要的程序. 当你有一个程序,需要长期在后台运行,并且希望能 ...

  10. git查看某一个文件的修改历史

    git blame filename:显示整个文件的每一行的详细修改信息:包括SHA串,日期和作者. 其显示格式为: commit ID | 代码提交作者 | 提交时间 | 代码位于文件中的行数 | ...