安装环境

CentOS 6.5 、CentOS 7.4

主Redis:10.159.44.175

从Redis: 10.159.44.176、10.159.44.177

Redis下载和安装

在3台机器上分别安装redis

#添加yum仓库

yum install epel-release -y

#安装redis

yum install redis -y

程序文件说明

安装完毕后有以下几个文件位于/usr/bin目录:

redis-server:Redis服务器的daemon启动程序

redis-cli:Redis命令行操作工具,也可以用telnet根据其纯文本协议来操作

redis-benchmark:Redis性能测试工具,测试Redis在当前系统及配置下的读写性能

redis-check-aof:更新日志检查

redis-check-dump:用于本地数据库检查

iptables策略配置

如果iptable处于启用状态,且INPUT链默认规则为drop,则需要配置开放端口

firewall-cmd --zone=public --add-port=4100/tcp --permanent

firewall-cmd --zone=public --add-port=4200/tcp --permanent

firewall-cmd --reload     #重新加载生效

**以上为端口根据实际情况添加,默认端口为:6370、26379

Redis主从配置

主redis的配置

在主Redis上编辑配置文件

# cat /etc/redis.conf

daemonize yes
pidfile "/var/run/redis/redis.pid"
port 4100
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
maxmemory 10g
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/var/lib/redis"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
masterauth "LQi#czFe$!"
requirepass "LQi#czFe$!"
# Generated by CONFIG REWRITE
protected-mode no

从redis配置

在2台从服务器上编辑Redis的配置文件

以上面主redis的配置文件为基准,添加一行

slaveof  <主redis服务器IP>  <端口>

即完成 从redis的配置。

如:slaveof 10.159.44.175 4100  # 指向10.159.44.175:4100作为master服务器

Sentinel的配置

在3台服务器上分别编辑redis-sentinel的配置文件

vi /etc/redis-sentinel.conf

port 4200       # 默认使用4200端口
daemonize yes
protected-mode no
logfile "/var/log/redis/sentinel.log"
pidfile "/var/run/redis/sentinel.pid"
dir "/tmp

sentinel monitor mymaster 10.159.44.175 4100 1      # 监视一个名为 mymaster 的主服务器, 这个主服务器的 IP 地址为 127.0.0.1 , 端口号为 4100 , 而将这个主服务器判断为失效至少需要 2 个 Sentinel 同意 (只要同意 Sentinel 的数量不达标,自动故障迁移就不会执行)。
sentinel down-after-milliseconds mymaster 5000       # 指定了 Sentinel 认为服务器已经断线所需的毫秒数。
sentinel config-epoch mymaster 10                            # 配置纪元,可以理解为配置的版本号,因为Sentinel会主动自动修改redis.conf和自己的redis-sentinel.conf来保持主从同步,此项数值可随意设置,但当Sentinel做过自动的主从切换以后,数值会加1。

sentinel parallel-syncs mymaster 1                             # 在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长,但越大就意味着越多的从服务器因为复制而不可用。可以通过将这个值设为 1 来保证每次只有一个从服务器处于不能处理命令请求的状态。

注意:/etc/redis-sentinel.conf 必须要有写入权限。

常用命令

Redis的启动,停止,重启:

systemctl start redis.service

systemctl stop redis.service

systemctl restart redis.service

Redis Sentinel的启动,停止,重启:

systemctl start redis-sentinel.service

systemctl stop redis-sentinel.service

systemctl restart redis-sentinel.service

使用redis客户端连接服务初始化已经确认状态

redis-cli -p 4100 -h 127.0.0.1  # 使用参数指定:-p 端口 -h 服务器地址

127.0.0.1:6379> auth passwd                                #使用密码登录

OK

127.0.0.1:6379> config set protected-mode "no"   #修改redis的保护模式为no,不启用。

OK

127.0.0.1:6379> info                                              #查看状态

centos部署redis主从的更多相关文章

  1. SaltStack部署redis主从

    需求: 一,部署redis主从,一台主一台从 二,redis监听自己的IP地址,而不是0.0.0.0 主:安装,配置,启动 从:安装,配置,启动,主从

  2. SaltStack入门篇(六)之部署Redis主从实现和Job管理

    一.部署Redis主从 需求: 192.168.56.11是主,192.168.56.12是从 redis监听自己的ip地址,而不是0.0.0.0 分析: linux-node1 安装 配置 启动 l ...

  3. docker部署redis主从和哨兵

    docker部署redis主从和哨兵 原文地址:https://www.jianshu.com/p/72ee9568c8ea 1主2从3哨兵 一.前期准备工作 1.电脑装有docker 2.假设本地i ...

  4. puppet工作原理及部署redis主从篇

    一.简介 1.国际惯例什么是puppet puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统 ...

  5. kubernetes部署redis主从高可用集群

    1.redis主从高可用集群结构 2.k8s部署有状态的服务选择 对于K8S集群有状态的服务,我们可以选择deployment和statefulset statefulset service& ...

  6. 单机部署redis主从备份

    redis为了避免单点故障,也支持主从备份.个人在做主从备份的实验时,因为机器数量有限,一般非常少有多台机器做支撑. 本文就将叙述怎样在一台电脑上实现redis的主从备份. 同一台机器上部署多个red ...

  7. OpenShift上部署Redis主从集群

    客户有部署有状态服务的需求,单机部署模式相对简单,尝试一下集群部署. 关于Redis的master,slave 以及sentinal的架构和作用不提,有兴趣可以参考之前的博客 https://www. ...

  8. 在docker中部署redis主从配置

    环境说明: 阿里云服务器 Ubuntu 16.04 docker 1.拉取Redis镜像 docker pull redis 2.配置Redis启动配置文件,此处我创建一个专用目录,存放Redis相关 ...

  9. 5 LAMP配置管理:模块(state、file、pkg、service)、jinja模板、job管理、redis主从

    1. 配置管理:state和file https://docs.saltstack.com/en/latest/topics/states/index.html Full list of states ...

随机推荐

  1. Centos7 安装nginx1.14

    一丶官网 http://nginx.org/en/download.html 至于安装那个版本首先要看清楚版本代表什么意思 Nginx官网提供了三个类型的版本Mainline version:Main ...

  2. javascript将浮点数转换成整数

    Summary 临时我就想到3个方法而已.假设读者想到其它好用方法,也能够交流一下 parseInt 位运算符 Math.floor Math.ceil Description 一.parseInt ...

  3. 集合总结五(Hashtable的实现原理)

    一.概述 上一篇介绍了Java8的HashMap,接下来准备介绍一下Hashtable. Hashtable可以说已经具有一定的历史了,现在也很少使用到Hashtable了,更多的是使用HashMap ...

  4. httpd基础知识

    apache简介   Apache取自"a patchy server"的读音,意思是充满补丁的服务器.Apache起初由伊利诺伊大学香槟分校的国家超级电脑应用中心(NCSA)开发 ...

  5. MVC 中Scripts.Render、Styles.Render

    在ASP.NET MVC项目中,可以在视图中利用Scripts.Render.Styles.Render统一加载js.css文件,需要利用BundleConfig类来Add 各种Bundle,例如:b ...

  6. MySQL:System.Data.Entity ,MySqlCommand, MySqlParameter and "LIKE" %

    Introduction Using GetSqlStringCommand with a text comparative, with LIKE, in ADO.NET and the MySQLP ...

  7. 如何增加黑客通过ssh入侵的难度--保护ssh的三把锁

    源文档:https://blog.csdn.net/cnbird2008/article/details/6130696 简介 如果需要远程访问计算机并启用了 Secure Shell (SSH) 连 ...

  8. kafka consumer防止数据丢失(转)

    http://kane-xie.iteye.com/blog/2225085 kafka最初是被LinkedIn设计用来处理log的分布式消息系统,因此它的着眼点不在数据的安全性(log偶尔丢几条无所 ...

  9. note 1 对象和数据类型

    /#行注释 print "Hello World" 对象 五种基本类型 字符串 (string),简记为str 使用 ' ' 或 " " 括起来的一系列字符 整 ...

  10. mysql 拒绝登录解决

    一大早打开Navicat Lite for MySQL客户端,提示1045 access denied for user ’root’@’localhost’ using password yes,太 ...