部署规划
IP地址 | IP地址/主机名 | Redis服务 | 哨兵sentinel |
---|---|---|---|
Master | 172.31.65.129 | 安装redis服务,6378 | 安装sentinel服务,端口26379 |
Slave1 | 172.31.65.142 | 安装redis服务,6378 | 安装sentinel服务,端口26379 |
Slave2 | 172.31.65.118 | 安装redis服务,6378 | 安装sentinel服务,端口26379 |
主节点部署
安装路径
/usr/local/redis
安装过程
#下载redis-5.0.14安装包
cd /usr/local && wget https://download.redis.io/releases/redis-5.0.14.tar.gz
#解压
tar zxvf redis-5.0.14.tar.gz
#编译安装
cd redis-5.0.14 && make
make PREFIX=/usr/local/redis install
更改配置文件
mkdir -p /etc/redis
cd /etc/redis/redis.conf
################################ GENERAL #####################################
daemonize yes
pidfile "/var/run/redis.pid"
port 6378
tcp-backlog 511
timeout 0
tcp-keepalive 60
loglevel notice
logfile "/data/redis/redis_log"
databases 16
################################ SNAPSHOTTING ################################
save 600 5000
stop-writes-on-bgsave-error no
rdbcompression no
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/redis/dump"
################################# REPLICATION #################################
# slaveof
masterauth "passwrd"
slave-serve-stale-data yes
slave-read-only no
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-ping-slave-period 10
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
# min-slaves-max-lag is set to 10.
################################## SECURITY ###################################
requirepass "passwd"
################################### LIMITS ####################################
# maxclients 10000
maxmemory 5859375kb
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 150
aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE
编辑系统启动文件
vim /etc/profile
添加:
export PATH="$PATH:/usr/local/redis/bin"
vim /etc/init.d/redis
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the proc filesystem.
PASSWD=6JwvuCkz
REDISPORT=6378
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis/redis.conf"
case "$1" in
start)
if [ -f