在 CentOS 上,Redis 的配置文件位置和修改方式取决于你是怎么安装的 Redis(yum 安装 / 源码安装 / 容器)。下面是最常见的几种情况:
/etc/redis.conf
vi /etc/redis.conf
bind 0.0.0.0 # 允许远程连接(默认是 127.0.0.1)
protected-mode no # 关闭保护模式(测试环境)
requirepass yourpass # 设置密码
port 6379 # 端口
daemonize yes # 后台运行
systemctl restart redis
systemctl status redis
一般在你解压或安装目录中,例如:
/usr/local/redis/redis.conf
或
/opt/redis/redis.conf
vi /usr/local/redis/redis.conf
启动时需要指定配置文件:
redis-server /usr/local/redis/redis.conf
修改配置需要挂载配置文件:
docker run -d \
-p 6379:6379 \
-v /data/redis/redis.conf:/usr/local/etc/redis/redis.conf \
redis redis-server /usr/local/etc/redis/redis.conf
在 redis.conf 中修改后重启:
docker-compose restart redis
redis-cli info server
或
ps -ef | grep redis
bind 0.0.0.0
protected-mode no
requirepass 123456
maxmemory 512mb
maxmemory-policy allkeys-lru
如果你能告诉我:
我可以给你更精确的路径和命令。