Docker安装Redis

安装redis

docker pull redis

安装好之后使用查看镜像

docker images
truedei@truedei:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              987b78fc9e38        10 days ago         104MB
httpd               latest              a8a9cbaadb0c        2 weeks ago         166MB
fjudith/draw.io     latest              7b136fc80d31        3 weeks ago         683MB
mysql               5.7.29              f5829c0eee9e        5 weeks ago         455MB
新建挂载文件

因为 redis 默认配置你会发现只能够本地连接,不能进行远程访问,使用 Redis Desktop Manager连接都会报错,因此需要手动挂载 redis 配置文件

  1. 新建配置文件

    因为需要redis的配置文件,这里最好还是去redis的官方去下载一个redis使用里面的配置文件即可
    redis中文官方网站:http://www.redis.cn/download.html

147352021ddf3f3c176decfb.webp

下载后解压出来

14735202d4605e4a41d40503.webp

  1. 配置redis.conf配置文件

    bind 127.0.0.1 #注释掉这部分,使redis可以外部访问

    daemonize no#用守护线程的方式启动

    requirepass 你的密码#给redis设置密码

    appendonly yes#redis持久化  默认是no

    tcp-keepalive 300 #防止出现远程主机强迫关闭了一个现有的连接的错误 默认是300

  2. 创建本地与docker映射的目录,即本地存放的位置

    truedei@truedei:redis-5.0.5$ sudo mkdir /usr/local/docker/
    

把配置文件拷贝到刚才创建好的文件夹里

启动redis

sudo docker run -p 6379:6379 --name redis --restart always -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes

参数解释:

-p 6379:6379:把容器内的6379端口映射到宿主机6379端口

-v /usr/local/docker/redis.conf:/etc/redis/redis.conf:把宿主机配置好的redis.conf放到容器内的这个位置中

-v /usr/local/docker/data:/data:把redis持久化的数据在宿主机内显示,做数据备份

redis-server /etc/redis/redis.conf:这个是关键配置,让redis不是无配置启动,而是按照这个redis.conf的配置启动

–appendonly yes:redis启动后数据持久化

查看是否启动成功

docker ps

truedei@truedei:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
85cb7d83a2ff        redis               "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes        0.0.0.0:6379->6379/tcp              redis
0a122a08125f        mysql:5.7.29        "docker-entrypoint.s…"   5 weeks ago         Up About an hour    0.0.0.0:3306->3306/tcp, 33060/tcp   mysql57
truedei@truedei:~$

可以查看一下日志:sudo docker logs redis

truedei@truedei:~$ sudo docker logs redis
1:C 29 May 2020 01:16:22.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 29 May 2020 01:16:22.107 # Redis version=6.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 29 May 2020 01:16:22.107 # Configuration loaded
                _._                                              
           _.-``__ ''-._                                         
      _.-``    `.  `_.  ''-._           Redis 6.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                               
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'                               
 |`-._`-._    `-.__.-'    _.-'_.-'|                              
 |    `-._`-._        _.-'_.-'    |           http://redis.io    
  `-._    `-._`-.__.-'_.-'    _.-'                               
 |`-._`-._    `-.__.-'    _.-'_.-'|                              
 |    `-._`-._        _.-'_.-'    |                              
  `-._    `-._`-.__.-'_.-'    _.-'                               
      `-._    `-.__.-'    _.-'                                   
          `-._        _.-'                                       
              `-.__.-'                                           

1:M 29 May 2020 01:16:22.108 # 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 29 May 2020 01:16:22.108 # Server initialized
1:M 29 May 2020 01:16:22.108 # 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 29 May 2020 01:16:22.108 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 29 May 2020 01:16:22.108 * Ready to accept connections
truedei@truedei:~$

147352021c2631c720528606.webp

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值