从官网获取redis.conf?wget?http://download.redis.io/redis-stable/redis.conf
# 宿主机中创建redis配置和数据目录(为了方便修改redis的配置和数据持久化)
mkdir -p /data/wwwroot/web/work/software/redis/data
cd /data/wwwroot/web/work/software/redis
# 从官网下载redis.conf
wget http://download.redis.io/redis-stable/redis.conf
# ls命令查看redis.conf已下载成功
命令执行效果截图:
# 执行docker运行容器命令
docker run --name redis-new --privileged=true --restart=always -p 6482:6379 --log-opt max-size=200m --log-opt max-file=3 -v /data/wwwroot/web/work/software/redis/redis.conf:/etc/redis/redis.conf -v /data/wwwroot/web/work/software/redis/data:/data -d redis redis-server /etc/redis/redis.conf --requirepass 123456
容器命令参数说明请参考博客:只需九步教你用docker安装、登录远程redis以及使用pipe批量导入缓存数据
命令执行效果截图:
# 执行docker logs命令查看容器运行日志
docker logs -f redis-new
# 日志结果
*** FATAL CONFIG FILE ERROR (Redis 7.0.6) ***
Reading the configuration file, at line 416
>>> 'locale-collate ""'
Bad directive or wrong number of arguments
*** FATAL CONFIG FILE ERROR (Redis 7.0.6) ***
Reading the configuration file, at line 416
>>> 'locale-collate ""'
Bad directive or wrong number of arguments
*** FATAL CONFIG FILE ERROR (Redis 7.0.6) ***
Reading the configuration file, at line 416
>>> 'locale-collate ""'
Bad directive or wrong number of arguments
*** FATAL CONFIG FILE ERROR (Redis 7.0.6) ***
Reading the configuration file, at line 416
>>> 'locale-collate ""'
Bad directive or wrong number of arguments
*** FATAL CONFIG FILE ERROR (Redis 7.0.6) ***
Reading the configuration file, at line 416
>>> 'locale-collate ""'
Bad directive or wrong number of arguments
命令执行效果截图:
报错信息提示很明显是redis.conf配置有问题,去官网发现不同的redis版本需要不同的配置文件,在官网配置文件页面找到对应的文件下载地址,根据报错信息显示redis版本是7.0.6,在网页中找到Redis?7.0版本的配置并下载下来
# 打开网页
https://redis.io/docs/management/config/
# 找到Redis 7.0版本的配置下载链接,鼠标放在标题可查看链接地址
The self documented redis.conf for Redis 7.2.
The self documented redis.conf for Redis 7.0.
The self documented redis.conf for Redis 6.2.
The self documented redis.conf for Redis 6.0.
The self documented redis.conf for Redis 5.0.
The self documented redis.conf for Redis 4.0.
The self documented redis.conf for Redis 3.2.
The self documented redis.conf for Redis 3.0.
The self documented redis.conf for Redis 2.8.
The self documented redis.conf for Redis 2.6.
The self documented redis.conf for Redis 2.4.
截图:
# 重新进入宿主机redis配置目录
cd /data/wwwroot/web/work/software/redis
# rm命令删除旧的redis.conf,rm命令很危险,使用时需注意
rm -rf redis.conf
# 从官网下载redis.conf
wget https://raw.githubusercontent.com/redis/redis/7.0/redis.conf
# ls命令查看redis.conf已下载成功
命令执行效果截图:
# 删除报错的容器
docker rm redis-new
# 检查容器redis-new是否删除
docker ps -a | grep redis-new
# 执行docker运行容器命令
docker run --name redis-new --privileged=true --restart=always -p 6482:6379 --log-opt max-size=200m --log-opt max-file=3 -v /data/wwwroot/web/work/software/redis/redis.conf:/etc/redis/redis.conf -v /data/wwwroot/web/work/software/redis/data:/data -d redis redis-server /etc/redis/redis.conf --requirepass 123456
# 执行docker 查看容器日志命令,无报错信息redis运行正常
docker logs -f redis-new