centos使用docker安装redis

8 篇文章 0 订阅
1 篇文章 0 订阅
  1. 拉取最新redis镜像

docker pull redis
  1. 创建宿主机上的映射文件目录,并授权

[root@1-0001 ~]# mkdir -p /opt/redis/data
[root@1-0001 ~]# touch /opt/redis/redis.conf
[root@1-0001 ~]# chmod -R +777 /opt/redis
  1. 运行redis,生成相应容器

-d 后台启动

-v 宿主机目录挂在到容器的地址,映射(挂载数据、日志、配置

--appendonly yes 在Redis容器启动redis-server服务器并打开Redis持久化配置

[root@1-0001 ~]# docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 8300:8300 --name redis -v /opt/redis/redis.conf:/etc/redis/redis.conf -v /opt/redis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 123456
  1. 修改配置,/opt/redis/redis.conf/redis.conf

appendonly yes 启动Redis持久化功能

protected-mode no 关闭protected-mode模式,此时外部网络可以直接访问 (docker默认开启)

bind 0.0.0.0 设置所有IP都可以访问 (docker默认开启)

[root@1-0002 redis]# vim /opt/redis/redis.conf/redis.conf 

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 8300

# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
# redis密码
requirepass 123456
  1. 测试redis服务

[root@1-0001 ~]# docker exec -it redis /bin/bash
root@a40d46499c3a:/# redis-cli -p 8300 -a 123456
127.0.0.1:8300> 

[root@1-0001 ~]# docker exec -it redis redis-cli -p 8300 -a 123456
127.0.0.1:8300> 

# 查看当前redis有没有设置密码
127.0.0.1:8300> config get requirepass

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫雪群飘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值