1. 环境准备
-
下载安装包
$ wget https://download.redis.io/releases/redis-4.0.11.tar.gz
-
安装编译环境
如果有 gcc 编译环境跳过
$ sudo yum install gcc $ sudo yum install gcc-c++
2. Redis 安装
-
解压
$ tar -zvxf redis-4.0.11.tar.gz
-
make 编译
$ make MALLOC=libc
-
安装到指定目录
$ make PREFIX=/opt/module/redis install
-
在 redis 目录下创建以下几个目录
$ mkdir data logs pid conf
3. Redis 配置
在 conf 目录编写 redis.conf
配置
bind 0.0.0.0
port 6379
tcp-backlog 1024
timeout 60
tcp-keepalive 60
daemonize yes
pidfile "/opt/module/redis/pid/6379.pid"
#debug、verbose、notice、warning
#loglevel warning
logfile "/opt/module/redis/logs/redis.log"
databases 16
maxclients 800
requirepass "123456"
#maxmemory
maxmemory 104857600
maxmemory-samples 5
maxmemory-policy volatile-lru
#rdb
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/opt/module/redis/data/"
#aof
appendonly yes
appendfilename "appendonly.aof"
#always everysec no
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-rewrite-incremental-fsync yes
# slaveof 192.168.1.1 7001
# masterauth qianKUN1jian
slave-serve-stale-data yes
slave-read-only yes
repl-ping-slave-period 10
repl-timeout 60
repl-disable-tcp-nodelay no
repl-backlog-size 1mb
#slave yes: hui dai lai yan ci ; no: jiang di yan ci, xiao hao kuang dai
repl-disable-tcp-nodelay no
repl-backlog-size 20mb
repl-backlog-ttl 3600
slave-priority 100
#default 0 10
min-slaves-to-write 0
min-slaves-max-lag 10
repl-diskless-sync no
repl-diskless-sync-delay 5
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
#hash
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
#list
list-max-ziplist-size -2
list-compress-depth 0
#set
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
#HyperLogLog
hll-sparse-max-bytes 3000
activerehashing yes
hz 10
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# lazy delete
lazyfree-lazy-eviction no
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yes
slave-lazy-flush yes
rename-command keys ""
rename-command flushall ""
4. 启动 Redis
$ bin/redis-server conf/redis.conf