欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Redis运维和开发学习笔记(3)redis搭建集群

程序员文章站 2022-07-05 13:21:31
...

Redis运维和开发学习笔记(3)redis搭建集群

Redis集群搭建

cp /etc/redis.d/redistest_7001.conf /etc/redis.d/redistest_XXXX.conf

:%s/7001/xxxx/g
配置文件内容:cluster-enabled yes

################################## NETWORK #####################################
#bind 10.16.9.101
protected-mode no
port 7001
tcp-backlog 511
timeout 300
tcp-keepalive 300

################################# GENERAL #####################################
daemonize yes
supervised no
pidfile /data/service/redis/run/7001.pid
loglevel notice
logfile "/data/service_logs/redis/redistest_7001.log"
databases 16

################################ SNAPSHOTTING  ################################
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redistest_7001.rdb
dir "/data/service_data/redis/redistest_7001"

################################# REPLICATION #################################
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

################################## SECURITY ###################################

################################### LIMITS ####################################
maxmemory 1G
maxmemory-policy volatile-lru
save 1500 1
save 1200 10
save 900 10000

############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "redistest_7001.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 250mb
aof-load-truncated yes

################################ LUA SCRIPTING  ###############################

lua-time-limit 5000

################################ REDIS CLUSTER  ###############################
cluster-enabled yes
cluster-config-file nodes_redistest_7001.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1

################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 1024

################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################
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

rename-command flushall gzdbaflushall
rename-command flushdb gzdbaflushdb
rename-command shutdown gzdbashutdown
############################### AUTH CONFIG ###############################
#masterauth "no"

  1. 创建一个目录
    mkdir /data/service_data/redis/redistest_xxxx

  2. 以配置文件启动
    /usr/local/redis/3.2/redis-server /etc/redis.d/redistest_7001.conf

  3. 搭建集群
    ./redis-trib.rb create --replicas 1 127.0.0.1:7001 1127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

  4. 客户端连接进行验证
    ./redis-cli -c -p 7001