一、安装redis
略
二、主节点配置文件
daemonize yes
pidfile /usr/local/redis/logs/redis_6379.pid
port 6379
tcp-backlog 1024
bind 0.0.0.0
timeout 0
tcp-keepalive 60
loglevel notice
logfile "/usr/local/redis/logs/redis_6379.log"
databases 16
save ""
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/data/
如果做故障切换,不论主从节点都要填写密码且要保持一致
masterauth linlin
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
requirepass linlin
appendonly yes
appendfilename "appendonly.aof"
appendfsync always
appendfsync everysec
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 1000
slowlog-max-len 1000
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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
三、从节点配置文件
只需要复制主节点配置,增加slaveof xxx
修改6379端口 使用 sed -i 's/6379/6380/g' 6380.conf就可以
daemonize yes
pidfile /usr/local/redis/logs/redis_6380.pid
port 6380
tcp-backlog 1024
bind 0.0.0.0
timeout 0
tcp-keepalive 60
loglevel notice
logfile "/usr/local/redis/logs/redis_6380.log"
databases 16
save ""
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/data/
slaveof 10.211.55.7 6379
如果做故障切换,不论主从节点都要填写密码且要保持一致
masterauth linlin
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
requirepass linlin
appendonly yes
appendfilename "appendonly.aof"
appendfsync always
appendfsync everysec
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 1000
slowlog-max-len 1000
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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
四、同上配置6381节点的配置文件
五、启动
主节点启动
./redis-server 6379.conf
会报logs文件夹不存在
可以使用 mkdir -p /usr/local/xxx/logs 完成logs文件夹的创建
可以使用 mkdir -p /usr/local/xxx/data完成data文件夹的创建
./redis-server 6380.conf
./redis-server 6381.conf
六、启动完毕后查看 redis集群
./redis-cli -p 6379 -a xxx密码 info replication