部署环境
- CPU 架构: loongarch64
- 系统版本: Kylin Linux Advanced Server V10 (Tercel)
- Nacos 版本: 5.0.7
注意: 由于 redis 5.0.7 版本自带的 jemalloc 版本为 5.1.0,该版本不兼容 loongarch64 平台,所以编译 redis 之前需要填更新 redis 源码中自带的 jemalloc 版本
源码编译 redis
从 releases page 下载指定版本的 redis 源码
1
wget https://download.redis.io/releases/redis-5.0.7.tar.gz
解压源码
1
tar xf redis-5.0.7.tar.gz -C /usr/local
升级 jemalloc,因为原生自带的 jemalloc 不支持 loongarch64 架构,从 jemalloc 5.3.0 开始支持 loongarch。
1
2
3
4
5
6
7
8
9
10cd /usr/local/redis-5.0.7/deps
# 删除旧版本的 jemalloc
rm -rf jemalloc
# 下载新版本的 jemalloc
wget https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2
# 解压新版本的 jemalloc
tar xvjf jemalloc-5.3.0.tar.bz2 && mv jemalloc-5.3.0 jemalloc修改 deps/Makefile 文件的 jemalloc 选项,修改
--with-version
的值,修改后内容如下:1
2
3
4
5
6jemalloc: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd jemalloc && ./configure --with-version=5.3.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)"
cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a
.PHONY: jemalloc将 –with-version=5.1.0-0-g0 改成 –with-version=5.3.0-0-g0
编译 Redis
1
2
3
4
5
6
7
8# 回到 redis 源码根目录
cd /usr/local/redis-5.0.7
# 执行 make
make
# 执行安装 make install
make install
配置 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
63mkdir /usr/local/redis-5.0.7/{conf,logs}
cat > /usr/local/redis-5.0.7/conf/redis.conf <<EOF
bind 0.0.0.0
protected-mode yes
port 7381
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /usr/local/redis-5.0.7/redis_7381.pid
loglevel notice
logfile "/usr/local/redis-5.0.7/logs/redis_7381.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump_7381.rdb
dir /usr/local/redis-5.0.7/
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 7381_123!QAZ
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
appendfilename "7381appendonly.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配置 systemd 管理 redis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23cat > /usr/lib/systemd/system/redis.service <<EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=redis-server /usr/local/redis-5.0.7/conf/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[Service]
LimitNOFILE=10240
EOF创建 redis 用户,并修改 redis 程序目录权限
1
2
3useradd -s /sbin/nologin -M redis
chown -R redis:redis /usr/local/redis-5.0.7修改系统配置
1
2echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local启动 redis
1
systemctl enable --now redis.service