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应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...
随机推荐
- Configuring Logging 配置日志
NGINX Docs | Configuring Logging https://docs.nginx.com/nginx/admin-guide/monitoring/logging/[ 在上层设置 ...
- http请求及json发送与解析 post string
golang http请求及json流解析 - 长风v持成的博客 - CSDN博客 https://blog.csdn.net/u011677067/article/details/80852158 ...
- vue下登录页背景图上下空白处自适应等高
遇到需求,登录页面需要顶部和底部上下等高,并且随着浏览器自适应上下高度. 解决方法: vue界面的data中先定义 data() { return { windowHeight: "&quo ...
- 原!linux脚本 expect命令 完成 输入密码交互 进行scp远程文件拷贝
1.安装expect yum install expect expect相关知识--- https://blog.csdn.net/lufeisan/article/details/53488395 ...
- AndroidStudio修改常用快捷键
近期公司开发工具要从eclipse转向Androidstudio,安装好as后当然迫不及待地要将快捷键修改为eclipse中的快捷键啦,下面是个人的一些小的总结. 1.首先当然要打开快捷键的设置界面啦 ...
- Jmeter(九)压力测试
一般我们在做压力测试的时候,分单场景和混合场景,单场景也就是咱们压测单个接口的时候,多场景也就是有业务流程的情况下,比如说一个购物流程,那么这样的场景就是混合场景,就是有多个接口一起来做操作.1.单场 ...
- (转)CentOs7.3 搭建 RabbitMQ 3.6 Cluster 集群服务与使用
RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python.Ruby..NET.Java.JMS.C.PHP.ActionScript.XMPP.STO ...
- python - 常用模块 os, sys
常用模块: os(处理文件和目录), sys(sys 模块包含了与 Python 解释器和它的环境有关的函数.) sys.argv 变量是一个字符串的 列表.特别地,sys.argv 包含了 命令行参 ...
- Element 中表单非必填数据项 必须为数字的验证问题
Element-ui 的el-form组建中,自带基本的验证功能,比如某些项必填的验证,直接加入rules 规则中即可,如下实例: 在页面中书写如下: <el-form-item label=& ...
- 如何下载java的jdk
1.https://www.oracle.com/index.html 2.https://www.oracle.com/downloads/index.html 3.https://www.orac ...