SaltStack安装Redis-第十篇
实验环境
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-第十篇的更多相关文章
- SaltStack安装Redis模块
安装redis Python Client 下载地址: https://pypi.python.org/simple/redis/ tar -xvf redis-2.8.0.tar.gz cd red ...
- 15天玩转redis —— 第十篇 对快照模式的深入分析
我们知道redis是带有持久化这个能力了,那到底持久化成到哪里,持久化成啥样呢???这篇我们一起来寻求答案. 一:快照模式 或许在用Redis之初的时候,就听说过redis有两种持久化模式,第一种是S ...
- python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法
python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法window安装redis,下载Redis的压缩包https://git ...
- SaltStack入门到精通第一篇:安装SaltStack
SaltStack入门到精通第一篇:安装SaltStack 作者:纳米龙 发布日期:2014-06-09 17:50:36 实际环境的设定: 系统环境: centos6 或centos5 实验机 ...
- 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 ...
- SaltStack安装篇
一.基础介绍1.简介 salt 是一个基础平台管理工具 salt是一个配置管理系统,能够维护预定于状态的远程节点 salt是一个分布式远程执行系统,用来在远程节点上执行命令和查询数据 2.salt的核 ...
- Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy、
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
- Python开发【第十篇】:Redis
缓存数据库介绍 NoSQL(Not Only SQL),即"不仅仅是SQL",泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应对web2.0网站,特别是 ...
- Python之路【第十篇】Python操作Memcache、Redis、RabbitMQ、SQLAlchemy
Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
随机推荐
- linux下安装mysql-5.7.25
1.下载对应安装包 https://dev.mysql.com/downloads/mysql/ 2.卸载旧版本mysql 列出旧版本MySql的组件列表 rpm -qa | grep mysql ...
- tomcat------->简单配置
主机名:www.snowing.com 域名:snowing.com http://主机+服务器端口号/path(web应用)/xxx.html 例: http://localhost:8080/it ...
- Java/android 里ClassName.this和this的使用
如果在内部类里面用this就是指这个内部类的实例,而如果用OuterClassName.this就是它外面的那个类的实例 ClassName.this这个用法多用于在nested class(内部类) ...
- util 常用方法
C:\Program Files\Java\jdk1.8.0_171\src.zip!\java\lang\System.java /** * Returns the current time in ...
- content: "\e600"
w图标生成原理. <style> @font-face { font-family: iconfont-sm; src: url(//at.alicdn.com/t/font_143340 ...
- A TCP connection is distinguished by four values
4个值唯一地定义一条TCP连接. HTTP The Definitive Guide A computer might have several TCP connections open at any ...
- hbctf---whatiscanary学习
题目中除了能栈溢出实在找不到其他能泄露信息的地方了.而且也没法修改GOT表,始终绕不过stack_chk_fail函数.感到无从下手.只到官方给WP了,才觉得自己基础太过浅薄了. 如果我们仔细观察崩溃 ...
- neutron ml2
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhoumingbo532/article/details/27964675 在介绍ml2之前,先介绍 ...
- 0602-Zuul构建API Gateway-Zuul Http Client、cookie、header
一.Zuul Http Client zuul使用的默认HTTP客户端现在由Apache HTTP Client支持,而不是已弃用的Ribbon RestClient.要使用RestClient或使用 ...
- 如何制作一款HTML5 RPG游戏引擎——第五篇,人物&人物特效
上一次,我们实现了对话类,今天就来做一个游戏中必不可少的——人物类. 当然,你完全是可以自己写一个人物类,但是为了方便起见,还是决定把人物类封装到这个引擎里. 为了使这个类更有意义,我还给人物类加了几 ...