相关文章:

https://www.cnblogs.com/shook/p/12883742.html

https://redis.io/documentation

Window

下载地址

启动

1
redis-server.exe redis.windows.conf

Linux

测试环境:Linux version 3.10.0-1062.7.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Mon Dec 2 17:33:29 UTC 2019

下载地址

准备环境

1
2
3
yum install -y gcc
yum install -y gcc-c++
yum install -y tcl

下载安装

注意:这里选择redis-5.0.8这个版本可以编译成功,如果编译高版本失败则可能需要升级gcc版本重新编译

1
2
3
4
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
tar xzf redis-5.0.8.tar.gz
cd redis-5.0.8
make

编译成功

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
make[2]: 离开目录“/opt/redis-5.0.8/deps”
CC adlist.o
CC quicklist.o
CC ae.o
CC anet.o
CC dict.o
CC server.o
CC sds.o
CC zmalloc.o
CC lzf_c.o
CC lzf_d.o
CC pqsort.o
CC zipmap.o
CC sha1.o
CC ziplist.o
CC release.o
CC networking.o
CC util.o
CC object.o
CC db.o
CC replication.o
CC rdb.o
CC t_string.o
CC t_list.o
CC t_set.o
CC t_zset.o
CC t_hash.o
CC config.o
CC aof.o
CC pubsub.o
CC multi.o
CC debug.o
CC sort.o
CC intset.o
CC syncio.o
CC cluster.o
CC crc16.o
CC endianconv.o
CC slowlog.o
CC scripting.o
CC bio.o
CC rio.o
CC rand.o
CC memtest.o
CC crc64.o
CC bitops.o
CC sentinel.o
CC notify.o
CC setproctitle.o
CC blocked.o
CC hyperloglog.o
CC latency.o
CC sparkline.o
CC redis-check-rdb.o
CC redis-check-aof.o
CC geo.o
CC lazyfree.o
CC module.o
CC evict.o
CC expire.o
CC geohash.o
CC geohash_helper.o
CC childinfo.o
CC defrag.o
CC siphash.o
CC rax.o
CC t_stream.o
CC listpack.o
CC localtime.o
CC lolwut.o
CC lolwut5.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/opt/redis-5.0.8/src”

编译错误

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
erver.c:5152:44: 错误:‘struct redisServer’没有名为‘tlsfd_count’的成员
if (server.ipfd_count > 0 || server.tlsfd_count > 0)
^
server.c:5154:19: 错误:‘struct redisServer’没有名为‘sofd’的成员
if (server.sofd > 0)
^
server.c:5155:94: 错误:‘struct redisServer’没有名为‘unixsocket’的成员
serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
^
server.c:5156:19: 错误:‘struct redisServer’没有名为‘supervised_mode’的成员
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
^
server.c:5157:24: 错误:‘struct redisServer’没有名为‘masterhost’的成员
if (!server.masterhost) {
^
server.c:5170:15: 错误:‘struct redisServer’没有名为‘maxmemory’的成员
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5170:39: 错误:‘struct redisServer’没有名为‘maxmemory’的成员
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5171:176: 错误:‘struct redisServer’没有名为‘maxmemory’的成员
serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
^
server.c:5174:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员
redisSetCpuAffinity(server.server_cpulist);
^
server.c: 在函数‘hasActiveChildProcess’中:
server.c:1476:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
}
^
server.c: 在函数‘allPersistenceDisabled’中:
server.c:1482:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
}
^
server.c: 在函数‘writeCommandsDeniedByDiskError’中:
server.c:3789:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
}
^
server.c: 在函数‘iAmMaster’中:
server.c:4966:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
}
^
make[1]: *** [server.o] 错误 1
make[1]: 离开目录“/opt/redis-6.0.3/src”
make: *** [all] 错误 2

升级gcc版本

1
2
3
4
5
6
7
8
9
# 查看gcc版本
gcc -v
# 升级到9.1版本
yum -y install centos-release-scl
# 临时启用
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
# 如果要长期使用gcc 9.1的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

运行测试

1
make test

正常显示如下:

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
Execution time of different units:
0 seconds - unit/printver
0 seconds - unit/type/incr
1 seconds - unit/auth
1 seconds - unit/keyspace
1 seconds - unit/protocol
1 seconds - unit/quit
3 seconds - unit/multi
4 seconds - unit/type/stream-cgroups
12 seconds - unit/type/hash
13 seconds - unit/other
15 seconds - unit/expire
15 seconds - unit/type/list
17 seconds - unit/type/string
19 seconds - unit/scan
20 seconds - unit/type/set
3 seconds - integration/rdb
3 seconds - integration/convert-zipmap-hash-on-load
1 seconds - integration/logging
7 seconds - integration/aof
1 seconds - unit/pubsub
26 seconds - unit/sort
3 seconds - unit/slowlog
29 seconds - unit/type/zset
1 seconds - unit/introspection
28 seconds - integration/block-repl
1 seconds - unit/limits
11 seconds - unit/scripting
7 seconds - unit/introspection-2
41 seconds - unit/type/list-2
4 seconds - unit/bitfield
33 seconds - integration/replication-2
25 seconds - integration/psync2-reg
13 seconds - unit/bitops
2 seconds - unit/lazyfree
55 seconds - unit/dump
32 seconds - integration/psync2
57 seconds - unit/type/stream
8 seconds - unit/wait
45 seconds - integration/replication-4
11 seconds - unit/pendingquerybuf
23 seconds - unit/geo
71 seconds - integration/replication-3
99 seconds - unit/aofrw
82 seconds - unit/maxmemory
71 seconds - unit/memefficiency
118 seconds - unit/type/list-3
107 seconds - integration/replication-psync
79 seconds - unit/hyperloglog
156 seconds - integration/replication
385 seconds - unit/obuf-limits

\o/ All tests passed without errors!

启动

1
src/redis-server [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
26876:C 26 May 2020 09:56:57.357 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
26876:C 26 May 2020 09:56:57.357 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=26876, just started
26876:C 26 May 2020 09:56:57.357 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
26876:M 26 May 2020 09:56:57.358 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 26876
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

26876:M 26 May 2020 09:56:57.362 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
26876:M 26 May 2020 09:56:57.362 # Server initialized
26876:M 26 May 2020 09:56:57.362 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
26876:M 26 May 2020 09:56:57.362 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
26876:M 26 May 2020 09:56:57.363 * Ready to accept connections

后台启动

1
2
3
4
5
vim redis.conf

daemonize no
# 改成
daemonize yes

启动:

1
2
3
4
[root@zhang redis-5.0.8]# src/redis-server redis.conf
29472:C 26 May 2020 10:01:41.246 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
29472:C 26 May 2020 10:01:41.246 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=29472, just started
29472:C 26 May 2020 10:01:41.246 # Configuration loaded

停止:

1
2
ps axu|grep redis
kill-9 29472

创建服务

1
vim /usr/lib/systemd/system/redis.service
1
2
3
4
5
6
7
8
9
[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/redis-5.0.8/src/redis-server /opt/redis-5.0.8/redis.conf
[Install]
WantedBy=multi-user.target
1
2
systemctl enable redis.service
systemctl start redis.service

Docker

待完善

常见问题

如何远程访问

修改配置文件

1
bind 127.0.0.1