文档章节

搭建Redis Sentinel集群

shelltea
 shelltea
发布于 2016/06/20 19:50
字数 1043
阅读 594
收藏 20

下载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
朝阳
程序员
基于Docker的Redis高可用集群搭建(redis-sentinel)

前言   之前介绍了用docker来搭建redis主从环境,但这只是对数据添加了从库备份(主从复制),当主库down掉的时候,从库是不会自动升级为主库的,也就是说,该redis主从集群并非是高可用的。...

mario阿东
07/06
0
0
打不死的redis集群

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

linuxprobe
2016/10/11
27
0
日志收集系统之redis高可用集群搭建

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

萧十一郎君
2014/10/29
0
0
Redis Sentinel集群搭建

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

IamOkay
2016/05/03
111
0
如何搭建高可用redis架构?

1 题记 Redis 是一个开源的使用 ANSI C 语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value 数据库,并提供多种语言的 API。 如今,互联网业务的数据正以更快的速度在增长,数据类...

Java填坑之路
08/31
0
0

没有更多内容

加载失败,请刷新页面

加载更多

你为什么在Redis里读到了本应过期的数据

一个事故的故事 晚上睡的正香突然被电话吵醒,对面是开发焦急的声音:我们的程序在访问redis的时候读到了本应过期的key导致整个业务逻辑出了问题,需要马上解决。 看到这里你可能会想:这是不...

IT--小哥
今天
2
0
祝大家节日快乐,阖家幸福! centos GnuTLS 漏洞

yum update -y gnutls 修复了GnuTLS 漏洞。更新到最新 gnutls.x86_64 0:2.12.23-22.el6 版本

yizhichao
昨天
5
0
Scrapy 1.5.0之选择器

构造选择器 Scrapy选择器是通过文本(Text)或 TextResponse 对象构造的 Selector 类的实例。 它根据输入类型自动选择最佳的解析规则(XML vs HTML): >>> from scrapy.selector import Sele...

Eappo_Geng
昨天
4
0
Windows下Git多账号配置,同一电脑多个ssh-key的管理

Windows下Git多账号配置,同一电脑多个ssh-key的管理   这一篇文章是对上一篇文章《Git-TortoiseGit完整配置流程》的拓展,所以需要对上一篇文章有所了解,当然直接往下看也可以,其中也有...

morpheusWB
昨天
5
0
中秋快乐!!!

HiBlock
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部