运维笔记--Docker环境Redis容器重启后,连接异常处理
场景描述:
1. 远程telnet不通
macMacBook-Pro:3 mac$ telnet 192.168.xx.xxx 6379 Trying 192.168.xx.xxx... telnet: connect to address 192.168.xx.xxx: Connection refused telnet: Unable to connect to remote host
2. 后台程序报错:
redis连接异常
3. 原因分析:
redis容器重启后,原先的密码验证配置可能失效了(应该是没有持久化),需重新配置。
处理过程:
(1)连接服务器 (2)进入redis docker容器: docker exec -u root -it redis容器名 /bin/bash (3)查看redis服务进程,确保./redis-server *:6379重启 root@4b7105d18abe:/usr/local/bin# ps -ef | grep redis redis 1 0 0 06:32 ? 00:00:00 redis-server *:6379 root 29 18 0 06:35 pts/0 00:00:00 ./redis-server *:6379 root 34 18 0 06:35 pts/0 00:00:00 grep redis ---没有进程的时候,手动启动: root@4b7105d18abe:/usr/local/bin# pwd /usr/local/bin root@4b7105d18abe:/usr/local/bin# nohup ./redis-server & (4)设置远程验证登录: root@4b7105d18abe:/usr/local/bin# ./redis-cli 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "" ---设置密码: 127.0.0.1:6379> config set requirepass 自定义的密码 OK ---接着执行: 127.0.0.1:6379> auth 自定义的密码 OK ---查看是否生效 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "自定义的密码"
(5)重启调用redis的前端程序服务 (6)功能验证
补充参考:
redis容器当时的启动命令:
docker run --name redis -p 6379:6379 -v /home/docker_map_data/redis/data:/data -v /home/docker_map_data/redis/redis.conf:/etc/redis/redis.conf -d redis:5.0.7 redis-server /etc/redis/redis.conf --appendonly yes