redis哨兵模式部署
1.安装所需环境和工具
yum -y install wget vim tcl gcc make
2.下载redis
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
3.解压
tar xvf redis-5.0.7.tar.gz
4.编译
cd redis-5.0.7/
make install PREFIX=/usr/local/redis/
5.拷贝配置文件
mkdir /usr/local/redis/conf
mkdir /usr/local/redis/run
mkdir /usr/local/redis/data
mkdir /usr/local/redis/log
cp redis.conf /usr/local/redis/conf
cp sentinel.conf /usr/local/redis/conf
redis.conf
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 300
daemonize no
supervised no
pidfile "/usr/local/redis/run/redis_6379.pid"
loglevel notice
logfile "/usr/local/redis/log/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/usr/local/redis/data"
masterauth "Ictsoft@123"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass "Ictsoft@123"
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# Generated by CONFIG REWRITE
replicaof 173.82.196.241 6379 #slave才添加这个参数,添加的是master的IP
sentinel.conf
# 保护模式默认关闭
protected-mode no
# 绑定监听IP
bind 0.0.0.0
# 哨兵端口
port 26379
# 后台运行
daemonize yes
# pid
pidfile "/usr/local/redis/run/redis-sentinel.pid"
# log
logfile "/usr/local/redis/log/redis-sentinel.log"
# 工作目录
dir "/tmp"
# 配置认证密码
sentinel deny-scripts-reconfig yes
# 设置初始master以及法定认为下线人数:
sentinel monitor mymaster 173.82.196.241 6379 2
# 指定在故障转移期间,多少个slave向新的master同步得数量,如果slave是提供查询服务,则应该设置小一点更好
sentinel auth-pass mymaster Ictsoft@123
# 指定故障转移超时时间,默认为3分钟
sentinel config-epoch mymaster 1
# 禁止修改脚本,避免脚本重置
sentinel leader-epoch mymaster 1
# Generated by CONFIG REWRITE
6.设置systemctl启动
cat /lib/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf --daemonize no
ExecStop=/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start redis
systemctl enable redis
7.登录redis验证
[root@cc13 redis]# ./bin/redis-cli
127.0.0.1:6379> auth Ictsoft@123
OK
127.0.0.1:6379> info Replication
# Replication
role:master
connected_slaves:2
slave0:ip=173.82.196.242,port=6379,state=online,offset=68940701,lag=1
slave1:ip=173.82.196.240,port=6379,state=online,offset=68940701,lag=1
master_replid:7882d89cf8d0285c9b0e29959c4d4dd20729da4e
master_replid2:c0e41c83079eac6edabeefb37db9a26bf939e851
master_repl_offset:68940844
second_repl_offset:16774
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:67892269
repl_backlog_histlen:1048576
127.0.0.1:6379>
8.启动哨兵程序
cat /lib/systemd/system/redis-sentinel.service
[Unit]
Description=redis-sentinel
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-sentinel /usr/local/redis/conf/sentinel.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动程序
systemctl daemon-reload
systemctl enable redis-sentinel
systemctl start redis-sentinel
9.验证哨兵
[root@cc14 redis]# ./bin/redis-cli -p 26379 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=173.82.196.241:6379,slaves=2,sentinels=3
[root@cc14 redis]#