基于docker的config配置方式启动redis

本文主要写真正上生产环境的部署策略-config文件的方式,简单的命令行直接启动的,这里不体现

一剔除原config配置文件中的各种注释和空行

# actively rehash the main dictionaries, freeing memory when possible.
#
# If unsure:

原本的config文件如上,有很多注释行,这些东西有利于理解整个redis的配置项,但在实际使用时,很不容易看到config里到底开启了什么。按 以下方法可以对#开头的注释行和空行进行删除。

用notepad++打开文件

ctrl+f进入到替换标签中,查找目标内容^#.*替换内容为空(),其中查找模式选择正则表达式,勾选循环查找。替换后

查找目标内容改为^[\t ]*\r\n替换内容为空。

对原http://download.redis.io/redis-stable/redis.conf完成替换后内容如下:

bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

二通过docker部署单机版config文件的redis

参数里bind比较难理解,这边写的比较好:https://blog.csdn.net/a578977626/article/details/78202202 bind配置了什么ip,别人就得访问bind里面配置的ip才访问到redis服务

docker命令启动时,如果daemonize为yes,会出现docker用config文件是部署始终失败,改为no即可。

protected-mode需要设置为no,否则需要进行密码设置等。否则只能本地访问,不能其他pc访问

config内容为:

#bind 0.0.0.0
daemonize no
port 6379
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "6379.log"
dbfilename dump_6379.rdb
dir ./
appendonly yes
appendfilename "appendonly_6379.aof"
appendfsync everysec
timeout 0

protected-mode no
tcp-backlog 511
tcp-keepalive 300
supervised no
databases 16
always-show-logo yes
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

docker的启动命令为

docker run -d --restart=always -p 6379:6379 --name some-redis -v /cloud/redis/data/:/data -v /cloud/redis/conf/redis-6379.conf:/usr/local/etc/redis/redis.conf  redis redis-server /usr/local/etc/redis/redis.conf
 

 

 

你可能感兴趣的:(redis)