1. 程式人生 > >基於docker的config配置方式啟動redis

基於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替換內容為空。

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

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