一、版本说明:
系统:centos 7
docker:18
redis:6.0.3
二、单机服务搭建
1、下载redis
[root@VM_0_6_centos conf]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 987b78fc9e38 3 weeks ago 104MB
2、新建配置文件redis.conf
[root@VM_0_6_centos standalone]# ls
conf data
[root@VM_0_6_centos standalone]# pwd
/opt/redis/standalone
[root@VM_0_6_centos standalone]# cd conf/
[root@VM_0_6_centos conf]# ls
redis.conf
redis.conf
#绑定网卡IP
bind 0.0.0.0
#是否禁止公网访问redis cache 开启条件 没有bind IP 没有设置requirepass访问密码
protected-mode no
#是否开启守护模式
daemonize no
#aof日志 每次写操作都记录一条日志
appendonly yes
#是否开启集群
cluster-enabled no
#密码
requirepass 123456
3、启动命令
docker run -d -p 6378:6379 --restart always --name redisStandalone -v /opt/redis/standalone/conf/redis.conf:/etc/redis/redis.conf -v /opt/redis/standalone/data:/etc/redis/data redis
4、查看镜像
[root@VM_0_6_centos conf]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba0728d45348 redis "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:6378->6379/tcp redisStandalone
5、测试是否成功
[root@VM_0_6_centos conf]# docker exec -it ba0728d45348 /bin/bash
root@ba0728d45348:/data# redis-cli -p 6379 -c
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> exit
root@ba0728d45348:/data# exit
exit
[root@VM_0_6_centos conf]#
或者使用RedisDesktopManager 连接查看。
6、遇到的问题。
6.1、ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
docker重启后,原设置的密码会失效,需要重新设置。(刚发现)
root@ba0728d45348:/data# redis-cli -h localhost
localhost:6379> auth 123456
(error) ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
localhost:6379> config get requirepass
1) "requirepass"
2) ""
localhost:6379> config set requirepass 123456
OK
localhost:6379> auth 123456
OK
localhost:6379>