Redis_配置

本文介绍了Redis的配置文件位置,通常为redis.window.conf,详细解析了CONFIG命令的使用,如GET和SET操作,以及如何直接编辑配置文件或通过命令动态修改配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Redis的配置文件为与Redis安装目录下,文件名为redis.window.conf(window下,非window有些操作系统下也叫redis.conf)。
在这里插入图片描述

Redis CONFIG 命令格式:
redis 127.0.0.1:6379>CONFIG GET CONFIG_SETTING_NAME

实例:

在这里插入图片描述

也可以使用*号获取所有配置项:
redis 127.0.0.1:6379>config get *
运行后如下代码:

127.0.0.1:6379> cls
(error) ERR unknown command 'cls'
127.0.0.1:6379>
127.0.0.1:6379> config get config_setting_name
(empty list or set)
127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "notice"
127.0.0.1:6379> config get *
  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"
  8) ""
  9) "logfile"
 10) ""
 11) "pidfile"
 12) ""
 13) "maxmemory"
 14) "0"
 15) "maxmemory-samples"
 16) "5"
 17) "timeout"
 18) "0"
 19) "auto-aof-rewrite-percentage"
 20) "100"
 21) "auto-aof-rewrite-min-size"
 22) "67108864"
 23) "hash-max-ziplist-entries"
 24) "512"
 25) "hash-max-ziplist-value"
 26) "64"
 27) "list-max-ziplist-size"
 28) "-2"
 29) "list-compress-depth"
 30) "0"
 31) "set-max-intset-entries"
 32) "512"
 33) "zset-max-ziplist-entries"
 34) "128"
 35) "zset-max-ziplist-value"
 36) "64"
 37) "hll-sparse-max-bytes"
 38) "3000"
 39) "lua-time-limit"
 40) "5000"
 41) "slowlog-log-slower-than"
 42) "10000"
 43) "latency-monitor-threshold"
 44) "0"
 45) "slowlog-max-len"
 46) "128"
 47) "port"
 48) "6379"
 49) "tcp-backlog"
 50) "511"
 51) "databases"
 52) "16"
 53) "repl-ping-slave-period"
 54) "10"
 55) "repl-timeout"
 56) "60"
 57) "repl-backlog-size"
 58) "1048576"
 59) "repl-backlog-ttl"
 60) "3600"
 61) "maxclients"
 62) "10000"
 63) "watchdog-period"
 64) "0"
 65) "slave-priority"
 66) "100"
 67) "min-slaves-to-write"
 68) "0"
 69) "min-slaves-max-lag"
 70) "10"
 71) "hz"
 72) "10"
 73) "cluster-node-timeout"
 74) "15000"
 75) "cluster-migration-barrier"
 76) "1"
 77) "cluster-slave-validity-factor"
 78) "10"
 79) "repl-diskless-sync-delay"
 80) "5"
 81) "tcp-keepalive"
 82) "0"
 83) "cluster-require-full-coverage"
 84) "yes"
 85) "no-appendfsync-on-rewrite"
 86) "no"
 87) "slave-serve-stale-data"
 88) "yes"
 89) "slave-read-only"
 90) "yes"
 91) "stop-writes-on-bgsave-error"
 92) "yes"
 93) "daemonize"
 94) "no"
 95) "rdbcompression"
 96) "yes"
 97) "rdbchecksum"
 98) "yes"
 99) "activerehashing"
100) "yes"
101) "protected-mode"
102) "yes"
103) "repl-disable-tcp-nodelay"
104) "no"
105) "repl-diskless-sync"
106) "no"
107) "aof-rewrite-incremental-fsync"
108) "yes"
109) "aof-load-truncated"
110) "yes"
111) "maxmemory-policy"
112) "noeviction"
113) "loglevel"
114) "notice"
115) "supervised"
116) "no"
117) "appendfsync"
118) "everysec"
119) "appendonly"
120) "no"
121) "dir"
122) "E:\\redis"
123) "save"
124) "jd 900 jd 300 jd 60"
125) "client-output-buffer-limit"
126) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
127) "unixsocketperm"
128) "0"
129) "slaveof"
130) ""
131) "notify-keyspace-events"
132) ""
133) "bind"
134) "127.0.0.1"
127.0.0.1:6379> config set bind 127.0.0.2
(error) ERR Unsupported CONFIG parameter: bind
127.0.0.1:6379> config set bind "127.0.0.2"
(error) ERR Unsupported CONFIG parameter: bind
127.0.0.1:6379> config set loglevel "notice"
OK
127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "notice"
127.0.0.1:6379> config get loglevel
1) "loglevel"
2) "notice"
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> config set *
(error) ERR Wrong number of arguments for CONFIG set
127.0.0.1:6379> config get 8
(empty list or set)
127.0.0.1:6379> config get 8
(empty list or set)
127.0.0.1:6379> config get *
  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"
  8) ""
  9) "logfile"
 10) ""
 11) "pidfile"
 12) ""
 13) "maxmemory"
 14) "0"
 15) "maxmemory-samples"
 16) "5"
 17) "timeout"
 18) "0"
 19) "auto-aof-rewrite-percentage"
 20) "100"
 21) "auto-aof-rewrite-min-size"
 22) "67108864"
 23) "hash-max-ziplist-entries"
 24) "512"
 25) "hash-max-ziplist-value"
 26) "64"
 27) "list-max-ziplist-size"
 28) "-2"
 29) "list-compress-depth"
 30) "0"
 31) "set-max-intset-entries"
 32) "512"
 33) "zset-max-ziplist-entries"
 34) "128"
 35) "zset-max-ziplist-value"
 36) "64"
 37) "hll-sparse-max-bytes"
 38) "3000"
 39) "lua-time-limit"
 40) "5000"
 41) "slowlog-log-slower-than"
 42) "10000"
 43) "latency-monitor-threshold"
 44) "0"
 45) "slowlog-max-len"
 46) "128"
 47) "port"
 48) "6379"
 49) "tcp-backlog"
 50) "511"
 51) "databases"
 52) "16"
 53) "repl-ping-slave-period"
 54) "10"
 55) "repl-timeout"
 56) "60"
 57) "repl-backlog-size"
 58) "1048576"
 59) "repl-backlog-ttl"
 60) "3600"
 61) "maxclients"
 62) "10000"
 63) "watchdog-period"
 64) "0"
 65) "slave-priority"
 66) "100"
 67) "min-slaves-to-write"
 68) "0"
 69) "min-slaves-max-lag"
 70) "10"
 71) "hz"
 72) "10"
 73) "cluster-node-timeout"
 74) "15000"
 75) "cluster-migration-barrier"
 76) "1"
 77) "cluster-slave-validity-factor"
 78) "10"
 79) "repl-diskless-sync-delay"
 80) "5"
 81) "tcp-keepalive"
 82) "0"
 83) "cluster-require-full-coverage"
 84) "yes"
 85) "no-appendfsync-on-rewrite"
 86) "no"
 87) "slave-serve-stale-data"
 88) "yes"
 89) "slave-read-only"
 90) "yes"
 91) "stop-writes-on-bgsave-error"
 92) "yes"
 93) "daemonize"
 94) "no"
 95) "rdbcompression"
 96) "yes"
 97) "rdbchecksum"
 98) "yes"
 99) "activerehashing"
100) "yes"
101) "protected-mode"
102) "yes"
103) "repl-disable-tcp-nodelay"
104) "no"
105) "repl-diskless-sync"
106) "no"
107) "aof-rewrite-incremental-fsync"
108) "yes"
109) "aof-load-truncated"
110) "yes"
111) "maxmemory-policy"
112) "noeviction"
113) "loglevel"
114) "notice"
115) "supervised"
116) "no"
117) "appendfsync"
118) "everysec"
119) "appendonly"
120) "no"
121) "dir"
122) "E:\\redis"
123) "save"
124) "jd 900 jd 300 jd 60"
125) "client-output-buffer-limit"
126) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
127) "unixsocketperm"
128) "0"
129) "slaveof"
130) ""
131) "notify-keyspace-events"
132) ""
133) "bind"
134) "127.0.0.1"
127.0.0.1:6379>

编辑配置
你可以通过直接修改redis.window.conf或者利用config set命令来修改配置。

语法

redis 127.0.0.1:6379>CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

实例:
在这里插入图片描述

redis.window.conf参数说明
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

### 如何在 Docker 中配置 Redis Exporter #### 安装与运行 Redis Exporter 为了在 Docker 中成功配置并运行 `redis_exporter`,可以采用如下方法: 通过指定镜像版本号来拉取特定版本的 `oliver006/redis_exporter` 镜像,并利用 `-p` 参数映射容器端口至主机端口以便外部访问。对于连接到Redis服务器,则需设置环境变量或命令行参数如 `--redis.addr` 和 `--redis.password` 来提供必要的认证信息。 ```bash docker pull oliver006/redis_exporter:v1.45.0 docker run -d \ --name redis_exporter \ -p 9121:9121 \ oliver006/redis_exporter:v1.45.0 \ --redis.addr=redis://<your_redis_host>:6379 \ --redis.password="<your_redis_password>" ``` 上述脚本展示了如何创建名为 `redis_exporter` 的Docker容器实例[^2]。请注意替换 `<your_redis_host>` 及 `<your_redis_password>` 为实际使用的Redis地址和密码。 #### 多实例部署方案 当需要在同一台机器上部署多个 `redis_exporter` 实例时,可以通过调整宿主机上的监听端口号以及给每个容器赋予不同的名称实现这一点。下面是一个例子,用于启动两个不同配置下的 exporter: ```bash # 启动第一个实例 docker run -d \ --name redis_exporter_1 \ -p 9121:9121 \ oliver006/redis_exporter:v1.45.0 \ --redis.addr=redis://<first_redis_instance>:6379 \ --redis.password="<password_for_first_instance>" # 启动第二个实例 docker run -d \ --name redis_exporter_2 \ -p 9122:9121 \ oliver006/redis_exporter:v1.45.0 \ --redis.addr=redis://<second_redis_instance>:6379 \ --redis.password="<password_for_second_instance>" ``` 这里的关键在于改变外网可访问的服务端口(即 `-p` 参数),从而允许同一物理机上的多个exporters各自独立工作而不发生冲突[^1]。 #### Prometheus集成 为了让Prometheus能够抓取来自这些 exporters 的指标数据,在Prometheus配置文件(`prometheus.yml`)中的scrape_configs部分添加job条目指向各个exporter服务的位置即可完成集成操作。 ```yaml scrape_configs: - job_name: 'redis_exporter' static_configs: - targets: ['localhost:9121', 'localhost:9122'] labels: instance: 'primary' ``` 此段YAML定义了一个新的抓取任务(job),它会定期请求位于 localhost 上对应端口处暴露出来的metrics接口获取性能统计信息[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值