前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Redis 容器与配置(5)

Redis 容器与配置(5)

作者头像
franket
发布2021-10-20 09:56:41
2420
发布2021-10-20 09:56:41
举报
文章被收录于专栏:技术杂记技术杂记

后面是与默认配置的差异,这里稍微解释一下

Option

Comment

daemonize no

不以后台服务的形式运行

timeout 1800

将超时时间限定为半小时,默认是不限的

logfile "/data/redis6379.log"

指定日志的路径

databases 50

将数据库设为50个

dir /data/

指定存储目录

dbfilename dump6379.rdb

指定数据文件名

appendfilename "appendonly6379.aof"

指定append文件名

Note: 为什么普通情况下使用redis都是开启后台服务模式,而这里要使用前台模式呢,那是因为,容器化后,必须终结于一个前台进程,否则容器就直接退出了,这涉及容器交互模式运行和后台运行的一些特性


挂载本地卷到容器

代码语言:javascript
复制
[root@h104 x]# pwd
/tmp/x
[root@h104 x]# ls
redis6379.conf
[root@h104 x]# docker run --name myredis -d -v /tmp/x:/data redis  redis-server /data/redis6379.conf 
a1a4cfe7e7498827aeeb770744a9443a89212017282b41233cb3c4258a9a0b61
[root@h104 x]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a1a4cfe7e749        redis               "docker-entrypoint.sh"   12 seconds ago      Up 11 seconds       6379/tcp            myredis
[root@h104 x]#

这里对 docker run --name myredis -d -v /tmp/x:/data redis redis-server /data/redis6379.conf 进行一下解析

Option

Comment

docker run

调用 docker 命令的 run 子命令

--name myredis

给这个容器取名为 myredis

-d

后台模式运行

-v /tmp/x:/data

将本地的 /tmp/x 目录挂载到容器中的 /data 目录

redis

使用redis镜像

redis-server /data/redis6379.conf

使用指定的配置初始化并启动redis服务


查看日志

因为本地目录挂载到了容器中,那么日志根据映射就直接记录到了本地

代码语言:javascript
复制
[root@h104 x]# pwd
/tmp/x
[root@h104 x]# ls
redis6379.conf  redis6379.log
[root@h104 x]# cat /tmp/x/redis6379.log 
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1:M 28 Apr 14:47:24.523 # 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 28 Apr 14:47:24.523 # Server started, Redis version 3.0.7
1:M 28 Apr 14:47:24.523 # 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 28 Apr 14:47:24.524 # 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 28 Apr 14:47:24.524 * The server is now ready to accept connections on port 6379
[root@h104 x]#

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 挂载本地卷到容器
  • 查看日志
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档