配置
daemonize no #从 Redis 5.0+ 开始(尤其是 6.0+),官方强烈建议以“前台模式”运行 Redis
bind 127.0.0.1 #默认只能本机访问,远程访问需要注释掉
requirepass 123456 #设置密码
port 6379 #端口
#RDB持久化
save 900 1
save 300 10
save 60 1000
appendonly yes #AOF持久化(用这个,及时,windows no,不稳定)
appendfilename "appendonly.aof" (文件名)
auto-aof-rewrite-min-size 64mb (表示运行AOF重写时文件最小体积)
auto-aof-rewrite-percentage 100 (auto-aof-rewrite-percentage)
linux离线安装
make
make install PREFIX=/usr/local/redis
自建service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
# 如果进程异常退出(非 0 退出码),自动重启
Restart=on-failure
# 重启前等待 10 秒,避免频繁崩溃导致系统负载过高
RestartSec=10
# 标准输出和错误输出都交给journal记录,null不启用
StandardOutput=null
StandardError=null
[Install]
WantedBy=multi-user.target
windows安装
redis-server --service-install redis.windows.conf
docker运行
docker run -d -p 16380:16380 \
-v /home/tool/redis/redis.conf:/usr/local/etc/redis/redis.conf \
-v /home/tool/redis/data:/usr/local/etc/redis/data \
--restart=always --name=redis 0fdc3e401cf3