原创首发
Docker-comose部署redis,如何配置密码,端口号,keep-alive时长
redis,如何配置密码,端口号,keep-alive时长
如果不配置keep-alive,有可能会掉线,用着用着,就会有那个远程主机关闭链接的提示。
创建一个redis的目录
在里面创建redis.conf
,docker-compose.yaml
文件
配置文件redis.conf
tcp-keepalive 0
requirepass 123456
port 6389
- tcp-keepalive 为0表示不限制
- requirepass 为密码
- port 为端口
保存为redos.conf
文件
docker-compse.yaml文件
version: '3.3'
services:
redis:
restart: always
image: redis:6.0.5
container_name: redis-container
ports:
- "16379:6389"
volumes:
- ./data:/data
- /etc/timezone:/etc/timezone
- /etc/localtime:/etc/localtime
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
保存为docker-compose.yaml
文件
创建容器
docker-compose up -d
查看日志
docker-compose logs
如果日志里的端口号和你的一样,那么就是配置生效了。
警告处理
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis-master | 1:M 19 Apr 2024 14:17:34.336 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
- add 'vm.overcommit_memory = 1' to /etc/sysctl.conf
- echo never > /sys/kernel/mm/transparent_hugepage/enabled
- add it to your /etc/rc.local