Redis的Docker搭建

1.拉取Redis镜像,等待拉取完成

docker pull redis

#查看镜像
docker image ls

2.创建本地文件夹

#自行选择数据卷挂载目录,我选择/usr/local/software下创建
cd /usr/local/software
#创建三个目录分别存放.conf .log .aof或.rdb文件
 mkdir -p redis/6379/conf redis/6379/data redis/6379/log

3.官网下载redis.conf配置文件

Redis configuration | Docs

4.上传conf文件到刚刚创建的目录下,直接拖进去,刷新

5.创建日志redis.log文件

#在刚刚创建的log目录下创建文件
cd redis/6379/log
touch redis.log
#修改可写入权限
chmod 777 redis.log

6.根据需要配置redis.conf

cd ../conf
vim redis.conf
#输入:set number 查看行数
#第75行:bind 0.0.0.0 允许远程连接
#第98行:port 6379 端口号
#第304行: logfile "/var/log/redis.log" 容器内的日志位置

7.创建运行容器,完成数据卷挂载

docker run -it \
--name myredis \
-p 6379:6379 \
-v /usr/local/software/redis/6379/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-v /usr/local/software/redis/6379/data/:/data \
-v /usr/local/software/redis/6379/log/redis.log:/var/log/redis.log \
-d redis \
/usr/local/etc/redis/redis.conf

8.查看是否启动

docker ps

9.检查日志

docker logs myredis
#进入本地log目录
cd log
less redis.log
#看到如下内容
1:C 10 Jul 2024 02:23:48.369 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 10 Jul 2024 02:23:48.369 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 10 Jul 2024 02:23:48.369 # Configuration loaded
1:M 10 Jul 2024 02:23:48.370 * monotonic clock: POSIX clock_gettime
1:M 10 Jul 2024 02:23:48.370 * Running mode=standalone, port=6379.
1:M 10 Jul 2024 02:23:48.370 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 10 Jul 2024 02:23:48.370 # Server initialized
1:M 10 Jul 2024 02:23:48.370 # 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.
1:M 10 Jul 2024 02:23:48.371 * Ready to accept connections
redis.log (END)

10.测试

#以bash进入容器
docker exec -it myredis bash 
#连接
redis-cli
ping

11.打开防火墙

firewall-cmd --zone=public --add-port=6379/tcp --permanent
 
firewall-cmd --reload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值