博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搭建Redis Sentinel集群
阅读量:6293 次
发布时间:2019-06-22

本文共 6066 字,大约阅读时间需要 20 分钟。

hot3.png

下载Redis

当前最新版本为3.2.1

cd /optwget http://download.redis.io/releases/redis-3.2.1.tar.gztar zxf redis-3.2.1.tar.gzln -s redis-3.2.1 rediscd redismakeyum install tclmake 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 yes protected-mode no
daemonize no daemonize yes
logfile "" logfile "/var/log/redis-100.31-6379.log"
dir ./ dir "/usr/local/redis-data"
appendonly no appendonly 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 2 sentinel monitor mymaster ${master ip} 6379 2
sentinel down-after-milliseconds mymaster 30000 sentinel 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.logtail -100f /var/log/redis-100.32-6379.logtail -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.logtail -100f /var/log/redis-sentinel-100.32-26379.logtail -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=6379EXEC=/usr/local/redis-3.2.1/src/redis-serverCLIEXEC=/usr/local/redis-3.2.1/src/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/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 onchkconfig --add redischkconfig --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 scriptREDISPORT=26379EXEC=/usr/local/redis-3.2.1/src/redis-sentinelCLIEXEC=/usr/local/redis-3.2.1/src/redis-cliPIDFILE=/var/run/redis.pidCONF="/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 onchkconfig --add redis-sentinelchkconfig --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.localAdd this:sysctl -w net.core.somaxconn=65535When 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/enabledGo to /etc/rc.local$~: sudo nano /etc/rc.localAdd this:echo never > /sys/kernel/mm/transparent_hugepage/enabledNow this will be persistent upon reboot as well.

参考

转载于:https://my.oschina.net/shelltea/blog/698105

你可能感兴趣的文章
Flex&Bison手册
查看>>
solrCloud+tomcat+zookeeper集群配置
查看>>
/etc/fstab,/etc/mtab,和 /proc/mounts
查看>>
Apache kafka 简介
查看>>
socket通信Demo
查看>>
技术人员的焦虑
查看>>
js 判断整数
查看>>
mongodb $exists
查看>>
js实现页面跳转的几种方式
查看>>
sbt笔记一 hello-sbt
查看>>
常用链接
查看>>
pitfall override private method
查看>>
!important 和 * ----hack
查看>>
聊天界面图文混排
查看>>
控件的拖动
查看>>
svn eclipse unable to load default svn client的解决办法
查看>>
Android.mk 文件语法详解
查看>>
QT liunx 工具下载
查看>>
内核源码树
查看>>
Java 5 特性 Instrumentation 实践
查看>>