基于Centos 7.X 单机源码部署Redis6.2.6
1.目录规划
# 配置文件、日志、pid目录
mkdir -p /app/redis/{conf,logs,pid}
# redis数据目录
mkdir -p /data/redis
2.安装Redis
1)版本选择,习惯选择双数的小版本
2)5.0版本以后,要更新gcc版本
# 获取redis源码包
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
# 解压
tar xf redis-6.2.6.tar.gz -C /app/redis
# 安装
cd /app/redis/redis-6.2.6
# 安装gcc依赖
yum install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils devtoolset-9
# 使用高版本gcc进行编译
scl enable devtoolset-9 make
scl enable devtoolset-9 make install
3.自定义redis配置文件
# 备份redis.conf
mv /app/redis/redis-6.2.6/redis.conf{,_bak}
# 创建新的redis.conf
vim /app/redis/conf/redis_6379.conf
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /app/redis/pid/redis_6379.pid
loglevel notice
logfile /app/redis/logs/redis_6379.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.rdb
dir /data/redis
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
maxmemory 4GB
maxmemory-policy volatile-lru
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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 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-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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
4.systemd管理redis
cat >/etc/systemd/system/redis_6379.service <<EOF
[Unit]
Description=Redis Server
After=network.target
After=syslog.target
[Service]
Type=forking
PIDFile=/app/redis/pid/redis_6379.pid
ExecStart=/app/redis/redis-6.2.6/src/redis-server /app/redis/conf/redis_6379.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
LimitNOFILE = 5000
[Install]
WantedBy=multi-user.target
EOF
5.启动
systemctl start redis_6379.service && systemctl enable redis_6379.service
systemctl status redis_6379.service
6.报错处理
6.1.报错1
报错信息
fatal error: jemalloc/jemalloc.h: No such file or directory
解决方法
# 清理上次编译残留文件,重新编译
make distclean
scl enable devtoolset-9 make
scl enable devtoolset-9 make install
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构