常见问题

gcc 版本问题

centos7 默认安装版本 4.8.5,redis 6.0只支持 5.3以上

You need tcl 8.5 or newer in order to run the Redis test”

`wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
tar xzvf tcl8.6.1-src.tar.gz     
cd  ./tcl8.6.1/unix/  
./configure  
make  
make install`

安装

1
2
3
4
5
6
7
tar zxvf ./bak/redis-5.0.8 -C ./
cd redis-5.0.8
make MALLOC=libc

cd redis-3.2.0/src
make test
make install

cd src

./redis-server /home/mor/redis-5.0.8/redis.conf

查看 redis 进程

ps -aux | grep redis

配置 redis 服务并自动启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cd /etc/rc.d/init.d/
vim redis

#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis

PROGDIR=/usr/local/bin #安装路径
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/etc/redis.conf
PIDFILE=/var/run/redis.pid
DESC="redis daemon"
SCRIPTNAME=/etc/rc.d/init.d/redis

start()
{
if test -x $DAEMON
then
echo -e "Starting $DESC: $PROGNAME"
if $DAEMON $CONFIG
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "Couldn't find Redis Server ($DAEMON)"
fi
}

stop()
{
if test -e $PIDFILE
then
echo -e "Stopping $DESC: $PROGNAME"
if kill `cat $PIDFILE`
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "No Redis Server ($DAEMON) running"
fi
}

restart()
{
echo -e "Restarting $DESC: $PROGNAME"
stop
start
}

list()
{
ps aux | grep $PROGNAME
}

case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
list)
list
;;

*)
echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
exit 1
;;
esac
exit 0

# 设置权限
chmod 755 redis
chkconfig --add redis
chkconfig redis on
chkconfig --list redis

需要拷贝配置文件:cp /home/mor/redis-5.0.8/redis.conf /etc/redis.conf

配置文件说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 指定redis只接收来自该IP的请求,如果不设置,将处理所有请求,在生产环节中最好设置该项
bind 0.0.0.0

# 远程连接,No表示可以访问,yes表示禁止
protected-mode no

# 监听端口
port 6379
tcp-backlog 511

# 设置客户端连接时的超时时间,单位为秒
timeout 0

tcp-keepalive 300

# 后台启动
daemonize yes
supervised no

# pid文件放置位置
pidfile /var/run/redis_6379.pid

# 配置log文件地址,默认使用标准输出,即打印在命令行终端的端口上
loglevel notice

logfile "/data/redis/redis_6379.log"

# 设置数据库的个数,默认使用的数据库是0
databases 16

# 设置redis进行数据库镜像的频率
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes

# 在进行镜像备份时,是否进行压缩
rdbcompression yes
rdbchecksum yes

# 数据库镜像备份
dbfilename dump.rdb
dir /data/redis/data

slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

# 限制同时连接客户端数量
maxclients 50000

# 开启appendonly模式后,redis会把每一次写操作都追加到appendonly.aof文件中,
#当redis重新启动时,会从该文件恢复出之前的状态
appendonly yes
appendfilename "appendonly.aof"

# 设置appendonly.aof文件进行同步的频率
appendfsync everysec

no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated 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
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 10
aof-rewrite-incremental-fsync yes
maxmemory-policy volatile-ttl

# 集群配置
# cluster-enabled yes
# cluster-config-file "/opt/nodes.conf"
# cluster-node-timeout 5000

详细配置说明

服务测试

1
2
3
4
5
6
7
service redis start
service redis list

redis-cli -h -p

service redis stop
service redis restart