1、下载 redis
bash
docker pull redis:6.2.6
2、提前创建挂载目录
bash
mkdir -p /mydata/redis/conf
mkdir -p /mydata/redis/data
mkdir -p /mydata/redis/log
touch /mydata/redis/conf/redis.conf
touch /mydata/redis/log/redis.log
chmod 777 /mydata/redis/log/redis.log
3、启动 redis
bash
docker run -p 6379:6379 --name redis \
-v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /mydata/redis/log/redis.log:/log/redis.log \
-d redis:6.2.6 redis-server /etc/redis/redis.conf
4、查看 redis 版本
bash
[root@xxx etc]# docker exec -it redis /bin/bash
root@fb1adf5de3c7:/data# redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=1170f97abfd818d
root@fb1adf5de3c7:/data# redis-cli --version
redis-cli 6.2.6
5、docker 进入 redis
bash
docker exec -it redis redis-cli
# 可以指定端口
docker exec -it redis redis-cli -p 6380
6、编写 redis 配置文件
bash
vim /mydata/redis/conf/redis.conf
更新配置内容
bash
appendonly no
requirepass distance
save 900 1
save 300 10
save 60 10000
port 6379
timeout 0
loglevel notice
logfile "/log/redis.log"
databases 16
dbfilename dump.rdb
maxclients 128
protected-mode no
# bind 127.0.0.1
# daemonize yes
7、重启 redis
bash
docker restart redis
8、设置 redis 自动启动
bash
sudo docker update redis --restart=always
9、查看 redis 日志
bash
tail -f /mydata/redis/log/redis.log
# docker 查看
docker logs -f redis
10、查看 redis 主从复制相关信息,需要进入 redis 查看
bash
info replication