1、下载Redis

1
2
3
4
sudo wget http://bbs.linuser.com/shares/softs/redis-6.2.5.tar.gz

# 最新版本
sudo wget -P /usr/local/src https://download.redis.io/redis-stable.tar.gz

2、解压Redis到指定目录

1
sudo tar xf /usr/local/src/redis-6.2.5.tar.gz -C /data/redis/ ---strip-components=1

3、创建Redis命令目录

1
sudo mkdir -p /data/redis/{bin,etc,logs}

4、编译Redis

1
2
3
4
5
6
cd /data/redis/src
sudo make

# 报错没有jemlloc的时候

sudo make MALLOC=libc
5、拷贝命令到/data/redis/bin下
1
sudo cp /data/redis/src/redis-{cli,server} /data/redis/bin/

6、修改配置文件

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
cat <<eof | sudo tee /data/redis/etc/redis.conf
pidfile /data/redis/var/redis.pid
logfile /data/redis/var/redis.log
port 6379
bind 0.0.0.0
protected-mode yes
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
loglevel notice
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
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
requirepass kubernets
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
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 no
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
eof

9、添加到系统服务中

1
2
3
4
5
6
7
8
9
10
11
12
13
cat <<eof |sudo tee /lib/systemd/system/redis-server.service
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/etc/redis.conf
Restart=always

[Install]
WantedBy=multi-user.target
eof

10、启动Redis

1
sudo systemctl enable --now redis-server.service