redis哨兵版部署指导

10.1.11.6:6379 -> master
10.1.11.7:6379 -> slave
10.1.11.8:6379 -> slave
10.1.11.6:26379 -> sentinel
10.1.11.7:26379 -> sentinel
10.1.11.8:26379 -> sentinel


1.查看所有用户
 

cat /etc/passwd

2.添加 redis 用户(用户名、密码均为 redis)
 

useradd redis
passwd redis

3.创建 /redis 目录
 

mkdir -p /redis

4.给 /redis 目录添加 redis 用户权限
 

chown -R redis:redis /redis
chown -R 777 /redis

5.解压安装redis

tar -xzvf redis-5.0.8.tar.gz
make distclean
yum list tcl
yum install tcl.x86_64

cd /redis
make
cd src
make test
make install  #make PREFIX=/redis install

6.添加环境变量
 

echo "export PATH=/redis/src:$PATH" >> /etc/profile
source /etc/profile

7.维护启动文件以10.1.11.7为例
 

mkdir -p /redis/6379
mkdir -p /redis/6379/pid
mkdir -p /redis/6379/log
mkdir -p /redis/6379/data
cp /redis/redis.conf /redis/6379/6379.conf
vi /redis/6379/6379.conf

#主配置如下
 

bind 10.1.11.7
protected-mode yes
port 6379
daemonize yes
pidfile /redis/6379/log/redis_6379.pid
logfile /redis/6379/log/log_6379.log
dir /redis/6379/data
replica-serve-stale-data yes
replica-read-only yes
requirepass mima

#从需要增加以下两行配置
 

replicaof 10.1.11.7 6379
masterauth mima


8.启动3台服务器的redis
 

/redis/src/redis-server /redis/6379/6379.conf

 

验证可用性
 

redis-cli -c -h 10.1.11.7 -p 6379
auth mima
info

# Replication
role:master
connected_slaves:2
slave0:ip=10.1.11.6,port=6379,state=online,offset=686,lag=1
slave1:ip=10.1.11.8,port=6379,state=online,offset=686,lag=1
master_replid:071d2c883f90e5f18fb49874a5179ac3f150839b
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:686
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:686

redis-cli -c -h 10.1.11.6 -p 6379
auth mima

set name 123456
get name

9.重启服务
 

/redis/src/redis-cli -h 10.1.11.7 -p 6379 -a mima shutdown

10.配置 sentinel
 

mkdir -p /redis/26379
mkdir -p /redis/26379/pid
mkdir -p /redis/26379/log
mkdir -p /redis/26379/data
cp /redis/sentinel.conf /redis/26379/26379.conf
vi /redis/6379/6379.conf

#主配置如下
 

bind 10.1.11.8
protected-mode no
port 26379
daemonize yes
pidfile /redis/26379/log/redis_26379.pid
logfile /redis/26379/log/log_26379.log
dir /redis/26379/data
sentinel monitor mymaster1 10.1.11.7 6379 2
sentinel down-after-milliseconds mymaster1 30000
sentinel parallel-syncs mymaster1 1
sentinel failover-timeout mymaster1 180000

 

11.启动3台服务器的sentinel

/redis/src/redis-sentinel /redis/26379/26379.conf


验证可用性

/redis/src/redis-cli -p 26379
info Sentinel
/redis/src/redis-cli -h 10.1.11.7 -p 26379 info Sentinel

redis-cli -c -h 10.1.11.7 -p 6379 -a mima info replication


12.关闭 sentinel
 

/redis/src/redis-cli -h 10.1.11.7 -p 26379 -a mima shutdown

 

 

你可能感兴趣的:(redis)