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应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
随机推荐
- 第十一课——codis-server的高可用,对比codis和redis cluster的优缺点
[作业描述] 1.配置codis-ha 2.总结对比codis的集群方式和redis的cluster集群的优缺点 =========================================== ...
- ios开发 更改状态栏
设置statusBar 简单来说,就是设置显示电池电量.时间.网络部分标示的颜色, 这里只能设置两种颜色: 默认的黑色(UIStatusBarStyleDefault) 白色(UIStatusBarS ...
- 新团建立时间 timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
w 不根据当前时间戳更新. `wtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- C#日期处理(转) 太忘记了,备忘
//今天 DateTime.Now.Date.ToShortDateString(); //昨天,就是今天的日期减一 DateTime.Now.AddDays(-1).ToShortDateStrin ...
- 将vi or vim中的内容复制到terminal中
1. 查看 vim 是否支持 clipboard 功能 $ vim --version | grep clipboard 2. 如果有 +clipboard 则跳过这一步; 如果显示的是 -clipb ...
- DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set low_memory=False.
DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set low_ ...
- Oracle 学习笔记 12 -- 序列、索引、同义词
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/Topyuluo/article/details/24232449 数据库的对象包含:表.视图.序列. ...
- SQL事务回滚 写法(转)
以下是SQL 回滚的语句:方案一:SET XACT_ABORT ON--如果产生错误自动回滚GOBEGIN TRANINSERT INTO A VALUES (4)INSE ...
- MySQL 最基本的SQL语法/语句
DDL—数据定义语言(Create,Alter,Drop,DECLARE) DML—数据操纵语言(Select,Delete,Update,Insert) DCL—数据控制语言(GRANT,REVOK ...
- POJ1088:滑雪(简单dp)
题目链接: http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...