文档章节

搭建Redis Sentinel集群

shelltea
 shelltea
发布于 2016/06/20 19:50
字数 1043
阅读 561
收藏 19
点赞 0
评论 0

下载Redis

当前最新版本为3.2.1

cd /opt
wget http://download.redis.io/releases/redis-3.2.1.tar.gz
tar zxf redis-3.2.1.tar.gz
ln -s redis-3.2.1 redis
cd redis
make
yum install tcl
make test

服务器

  • 100.31 master
  • 100.32 slave0
  • 100.33 slave1

配置

redis.conf

复制一份配置:cp redis.conf redis-100.31-6379.conf 修改以下配置:

修改前修改后
bind 127.0.0.1#bind 127.0.0.1
protected-mode yesprotected-mode no
daemonize nodaemonize yes
logfile ""logfile "/var/log/redis-100.31-6379.log"
dir ./dir "/usr/local/redis-data"
appendonly noappendonly yes

100.32和100.33的配置需要增加以下配置:

修改前修改后
slaveof 192.168.100.31 6379

并注意修改日志文件名

sentinel.conf

复制一份配置:cp sentinel.conf sentinel-100.31-26379.conf 修改或增加以下配置:

修改前修改后
sentinel monitor mymaster 127.0.0.1 6379 2sentinel monitor mymaster ${master ip} 6379 2
sentinel down-after-milliseconds mymaster 30000sentinel down-after-milliseconds mymaster 3000
protected-mode no
daemonize yes
logfile "/var/log/redis-sentinel-100.31-26379.log"

100.32和100.33的配置同上,但需要注意修改日志文件名

启动

启动Redis

在三台服务器上分别启动Redis

/usr/local/redis-3.2.1/src/redis-server /usr/local/redis-3.2.1/redis-100.31-6379.conf
/usr/local/redis-3.2.1/src/redis-server /usr/local/redis-3.2.1/redis-100.32-6379.conf
/usr/local/redis-3.2.1/src/redis-server /usr/local/redis-3.2.1/redis-100.33-6379.conf

查看日志:

tail -100f /var/log/redis-100.31-6379.log
tail -100f /var/log/redis-100.32-6379.log
tail -100f /var/log/redis-100.33-6379.log

启动Redis Sentinel

在三台服务器上分别启动Redis Sentinel

/usr/local/redis-3.2.1/src/redis-sentinel /usr/local/redis-3.2.1/sentinel-100.31-26379.conf
/usr/local/redis-3.2.1/src/redis-sentinel /usr/local/redis-3.2.1/sentinel-100.32-26379.conf
/usr/local/redis-3.2.1/src/redis-sentinel /usr/local/redis-3.2.1/sentinel-100.33-26379.conf

查看日志:

tail -100f /var/log/redis-sentinel-100.31-26379.log
tail -100f /var/log/redis-sentinel-100.32-26379.log
tail -100f /var/log/redis-sentinel-100.33-26379.log

自启动

Redis自启动

将下面的脚步写入/etc/rc.d/init.d/redis并执行chmod +x /etc/rc.d/init.d/redis

#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis-3.2.1/src/redis-server
CLIEXEC=/usr/local/redis-3.2.1/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis-3.2.1/redis-100.31-${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

注意脚本中的配置文件路径

然后执行

chkconfig redis on
chkconfig --add redis
chkconfig --list redis

之后就可以用service redis start/stop对Redis进行控制

Redis Sentinel自启动

将下面的脚步写入/etc/rc.d/init.d/redis-sentinel并执行chmod +x /etc/rc.d/init.d/redis-sentinel

#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
# Redis Sentinel startup script

REDISPORT=26379
EXEC=/usr/local/redis-3.2.1/src/redis-sentinel
CLIEXEC=/usr/local/redis-3.2.1/src/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis-3.2.1/sentinel-100.31-${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis Sentinel server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis Sentinel stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

注意脚本中的配置文件路径

然后执行

chkconfig redis-sentinel on
chkconfig --add redis-sentinel
chkconfig --list redis-sentinel

之后就可以用service redis-sentinel start/stop对Redis Sentinel进行控制

问题汇总

The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

To fix this warning you have to set a new config to /etc/rc.local so that the setting will persist upon reboot

$~: sudo nano /etc/rc.local
Add this:

sysctl -w net.core.somaxconn=65535
When you reboot the next time, the new setting will be to allow 65535 connections instead of 128 as before.

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

This is also simple to fix by just running the recommended command as stated in the warning.

echo never > /sys/kernel/mm/transparent_hugepage/enabled
Go to /etc/rc.local

$~: sudo nano /etc/rc.local
Add this:

echo never > /sys/kernel/mm/transparent_hugepage/enabled
Now this will be persistent upon reboot as well.

参考

© 著作权归作者所有

共有 人打赏支持
shelltea

shelltea

粉丝 5
博文 4
码字总数 2039
作品 0
朝阳
程序员
打不死的redis集群

最近遇到部分系统因为redis服务挂掉,导致部分服务不可用。所以希望搭建一个redis集群镜像,把原先散落各处的redis服务器统一管理起来,并且保障高可用和故障自动迁移。 一 redis集群分类 大...

linuxprobe ⋅ 2016/10/11 ⋅ 0

日志收集系统之redis高可用集群搭建

为了搭建日志收集系统LEK,需要搭建一套Redis高可用集群,确保日志正常从各个应用服务器流转到ElasticSeach服务器,最终通过Kabana显示出来。Redis高可用集群采用redis自带的sentinel实现,具...

萧十一郎君 ⋅ 2014/10/29 ⋅ 0

Redis Sentinel集群搭建

Redis sentinel主要服务和维护主从复制关系,比如master宕机后管理slave成为升级为matser 主要博客如下 Redis中sentinel集群的搭建和Jedis测试 图文教程[一] Redis中sentinel集群的搭建和Jed...

IamOkay ⋅ 2016/05/03 ⋅ 0

Sentinel实现Redis集群的高可用

Sentinel实现Redis集群的高可用 redis集群中有一主一从两个节点。当主节点down掉的时候需要把从节点提升为主节点继续提供服务,从而实现高可用。结构图如下, redis单机多实例主从的安装和配...

秋风醉了 ⋅ 2016/03/24 ⋅ 0

redis主从及集群搭建

redis主从复制 概述 1、Redis的复制功能是支持多个数据库之间的数据同步。一类是主数据库(master)一类是从数据库(slave),主数据库可以进行读写操作,当发生写操作的时候自动将数据同步到...

sjfbjs ⋅ 2017/03/08 ⋅ 0

Redis主从集群的Sentinel配置

首先对三台机器进行redis的单机安装,然后进行以下步骤 master 192.168.1.102 slaver 192.168.1.104 slaver 192.168.1.105 修改两个slaver的redis.conf配置文件 添加master配置信息 slaveof ...

无心低语 ⋅ 2017/06/11 ⋅ 0

redis集群--单哨兵模式搭建

本文目标 本文记录redis集群单哨兵的搭建和测试。 安装准备 centos版本:6.7 redis版本:3.2.3 安装方式:源码安装 操作步骤 6379为主节点,6479和6579为从节点; 26379为哨兵节点。 1、创建...

码上青天 ⋅ 02/24 ⋅ 0

redis演练聚集

redis演练(1) 搭建redis服务 redis演练(2) 最全redis命令列表 redis演练(3) redis事务管理 redis演练(4) redis基准测试 redis演练(5) redis持久化 redis演练(6) redis主从模式搭建 redis运维...

randy_shandong ⋅ 2016/09/11 ⋅ 0

[喵咪Redis]Redis-Sentinel

[喵咪Redis]Redis-Sentinel 前言 redis-Sentinel 是我们这次来一同学习 redis 的重点,在我们现在的系统已经离不开 redis 的时候 , redis 挂掉了或者是一些其他问题都是致命的 , 那么怎么做到...

喵了_个咪 ⋅ 2016/06/29 ⋅ 0

Redis主从以及哨兵集群搭建(二)

Redis主从以及哨兵集群搭建 一、前言 Redis主从同步原理同MySQL的主从原理十分相似,而解决Redis单点故障的哨兵机制(sentinel)又同解决MySQL单点故障的MHA十分相似。因此我们在学习Redis时...

PowerMichael ⋅ 2017/07/30 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

Jenkins实践3 之脚本

#!/bin/sh# export PROJ_PATH=项目路径# export TOMCAT_PATH=tomcat路径killTomcat(){pid=`ps -ef | grep tomcat | grep java|awk '{print $2}'`echo "tom...

晨猫 ⋅ 今天 ⋅ 0

Spring Bean的生命周期

前言 Spring Bean 的生命周期在整个 Spring 中占有很重要的位置,掌握这些可以加深对 Spring 的理解。 首先看下生命周期图: 再谈生命周期之前有一点需要先明确: Spring 只帮我们管理单例模...

素雷 ⋅ 今天 ⋅ 0

zblog2.3版本的asp系统是否可以超越卢松松博客的流量[图]

最近访问zblog官网,发现zlbog-asp2.3版本已经进入测试阶段了,虽然正式版还没有发布,想必也不久了。那么作为aps纵横江湖十多年的今天,blog2.2版本应该已经成熟了,为什么还要发布这个2.3...

原创小博客 ⋅ 今天 ⋅ 0

聊聊spring cloud的HystrixCircuitBreakerConfiguration

序 本文主要研究一下spring cloud的HystrixCircuitBreakerConfiguration HystrixCircuitBreakerConfiguration spring-cloud-netflix-core-2.0.0.RELEASE-sources.jar!/org/springframework/......

go4it ⋅ 今天 ⋅ 0

二分查找

二分查找,也称折半查找、二分搜索,是一种在有序数组中查找某一特定元素的搜索算法。搜素过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;如果某一特定元素大于...

人觉非常君 ⋅ 今天 ⋅ 0

VS中使用X64汇编

需要注意的是,在X86项目中,可以使用__asm{}来嵌入汇编代码,但是在X64项目中,再也不能使用__asm{}来编写嵌入式汇编程序了,必须使用专门的.asm汇编文件来编写相应的汇编代码,然后在其它地...

simpower ⋅ 今天 ⋅ 0

ThreadPoolExecutor

ThreadPoolExecutor public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, ......

4rnold ⋅ 昨天 ⋅ 0

Java正无穷大、负无穷大以及NaN

问题来源:用Java代码写了一个计算公式,包含除法和对数和取反,在页面上出现了-infinity,不知道这是什么问题,网上找答案才明白意思是负的无穷大。 思考:为什么会出现这种情况呢?这是哪里...

young_chen ⋅ 昨天 ⋅ 0

前台对中文编码,后台解码

前台:encodeURI(sbzt) 后台:String param = URLDecoder.decode(sbzt,"UTF-8");

west_coast ⋅ 昨天 ⋅ 0

实验楼—MySQL基础课程-挑战3实验报告

按照文档要求创建数据库 sudo sercice mysql startwget http://labfile.oss.aliyuncs.com/courses/9/createdb2.sqlvim /home/shiyanlou/createdb2.sql#查看下数据库代码 代码创建了grade......

zhangjin7 ⋅ 昨天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部