redis-3.2.11哨兵模式的配置

设置内核参数:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo > /proc/sys/vm/overcommit_memory
echo > /proc/sys/net/core/somaxconn 、下载安装包redis-3.2..tar.gz # cd /usr/local/src
# wget http://download.redis.io/releases/redis-3.2.11.tar.gz 、解压及安装 [root@node1 src]# tar zxf redis-3.2..tar.gz
[root@node1 src]# cd redis-3.2./src/
[root@node1 redis-3.2.]# make PREFIX=/usr/local/redis3 install #指定安装路径 [root@node1 src]# mkdir /etc/redis
[root@node1 src]# cp ../redis.conf /etc/redis/redis_6379.conf # 设置启动脚本
[root@node1 redis-3.2.]# vim /etc/init.d/redis3
#!/bin/sh
# chkconfig:
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem. REDISPORT=
EXEC=/usr/local/redis3/bin/redis-server
CLIEXEC=/usr/local/redis3/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis_${REDISPORT}.conf" usage(){
echo "usage: $0 [start|stop|status|restart]"
} redis_start(){
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
} redis_stop(){
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -h 10.11.0.210 -p $REDISPORT -a redispass shutdown # 需要修改为各自主机的内网IP地址
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep
done
echo "Redis stopped"
fi
} redis_restart(){
redis_stop
sleep
redis_start
}
redis_status(){
ps -ef|grep redis|grep -v grep|grep -v status
} main(){
case "$1" in
start)
redis_start;;
stop)
redis_stop;;
status)
redis_status;;
restart)
redis_restart;;
*)
usage;
esac
} main $ 、修改redis配置
master redis_6379.conf配置:
[root@node1 redis-3.2.]# egrep -v '^$|^#' /etc/redis/redis_6379.conf
# 绑定的地址
bind 0.0.0.0
# 关闭保护模式
protected-mode no
port
daemonize yes
pidfile "/var/run/redis_6379.pid"
logfile "/var/log/redis/redis.log"
# 默认为yes,设置为no为主从复制
slave-read-only no
# redis密码
requirepass "redispass"
# 从服务器配置连接主服务器的密码,都需要配置,最好主从redis密码一样
masterauth "redispass" slave01 redis_6379.conf配置:
[root@node02 redis-3.2.]# egrep -v '^$|^#' /etc/redis/redis_6379.conf
bind 0.0.0.0
protected-mode no
port
daemonize yes
pidfile "/var/run/redis_6379.pid"
dir "/usr/local/src/redis-3.2.11"
slave-read-only no
requirepass "redispass"
masterauth "redispass"
slaveof 10.11.0.210 slave01 redis_6379.conf配置:
[root@node5 ~]# egrep -v '^$|^#' /etc/redis/redis_6379.conf
bind 0.0.0.0
protected-mode no
port
daemonize yes
pidfile "/var/run/redis_6379.pid"
dir "/usr/local/src/redis-3.2.11"
slave-read-only no
slave-priority
requirepass "redispass"
slaveof 10.11.0.210
masterauth "redispass" 、修改sentinel.conf文件 # 三台都一致,直接清除原来的配置,变更为如下内容即可: # vim sentinel.conf daemonize yes
logfile /var/log/sentine.log
protected-mode no
port
dir /tmp
sentinel monitor mymaster 10.11.0.210
sentinel down-after-milliseconds mymaster
sentinel parallel-syncs mymaster
sentinel failover-timeout mymaster
sentinel auth-pass mymaster redispass 配置注释:
#保护模式
protected-mode no #端口
port #守护进程
daemonize yes
#设置日志文件路径
logfile /var/log/sentine.log
#工作路径,不用改
dir /tmp # 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
# (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
# slaves是自动发现,不用指定slaves。
sentinel monitor mymaster 10.11.0.210 # master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster #选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
sentinel parallel-syncs mymaster #若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster #设置master和slaves的密码
sentinel auth-pass mymaster redispass 、三台机器都启动哨兵sentinel程序
[root@node1 redis-3.2.]# src/redis-sentinel sentinel.conf # 测试
.关闭主服务器可以自动将另外的slave其中一台提升为master,关闭另外的一台slave,master也可以正常运行
.将原来的master启动,此时会变成slave 查看主从复制信息:
[root@node1 redis-3.2.]# redis-cli -a redispass info replication
# Replication
role:master
connected_slaves:
slave0:ip=10.11.0.215,port=,state=online,offset=,lag=
slave1:ip=10.11.0.212,port=,state=online,offset=,lag=
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen: # 关闭redis服务命令
[root@node1 redis-3.2.]# redis-cli -a redispass shutdown 观察日志:
# tail -f /var/log/sentine.log
上一篇:跟着我一步一步的搭建一个基于springcloud的微服务实例


下一篇:JAVA 往jar包添加class文件