Master安裝Redis
- 從Redis官方網站下載下傳Redis的安裝檔案
- CentOSMini安裝GCC環境
yum install -y gcc-g++
- 編譯
5.0版本的Redis安裝需要加上參數
make MALLOC=libc
- 安裝
make install PROFIX=/usr/local/redis
拷貝配置檔案
将Redis的配置檔案拷貝到Redis的安裝目錄(/usr/local/redis/bin)
修改配置檔案
# 保護模式取消
protected-mode no
# Redis執行個體的端口号
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
# 背景運作
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
# 日志檔案路徑
logfile "/usr/local/redis5/redis.log"
# 資料庫的數量預設16個這裡我的是3個
databases 3
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
# RBD持久化檔案名字
dbfilename dump.rdb
# RBD持久化檔案存儲路徑
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
# 用戶端密碼通路
requirepass Your password
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
# AOF持久化
appendonly yes
# AOF檔案的名字
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 yes
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
注釋的行是需要配置的,其他的都預設.
配置Slave
安裝Redis
過程和Master安裝過程一樣
拷貝配置檔案
過程一樣
修改配置檔案
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/usr/local/redis5/redis.log"
databases 3
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 ./
# master和端口号,這裡我沒有寫ip是因為我在第一篇環境搭建的文章中設定了主機名
# 因為我用的是Redis5.0是以配置不死slaveof而是replicaof
replicaof master 6379
# master執行個體的認證密碼
masterauth xiaochen0.
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass YouPassword
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-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 yes
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
其他配置都和master一樣,注釋内容是需要修改的.
replicaof master 6379
為什麼不是slaveof呢?
詳情請參考:<太無奈!Redis 作者被迫修改 master-slave 架構的描述>
開啟master和slave
兩台機器都在redis目錄下執行
./redis-server ./redis.conf
其中master啟動之後由log記錄可以發現.

測試主從同步是否成功
我這裡的環境是一台Master兩台slave,master set一個key之後slave自動同步.
預設情況下slave隻能對master提供一個讀操作,不提供寫操作.