Loading... #### 一、安装 * **下载redis安装包** * **解压** ``` tar -xvf redis-6.2.6.tar.gz ``` * **编译** ``` cd redis-6.2.6 make ``` * **创建集群目录** ``` mkdir -p redis-cluster/6379 mkdir -p redis-cluster/6380 ``` * **创建节点配置文件** ``` #分别在节点文件夹下创建 touch redis.conf ``` #### 二、配置 * **添加环境变量 ** ``` #编辑 vi /etc/profile #添加如下内容 export REDIS_HOME="/app/redis-6.2.6/" export PATH=$REDIS_HOME/src:$PATH #生效 source /etc/profile ``` * **配置redis.conf** ``` bind 0.0.0.0 protected-mode no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes pidfile /app/redis-cluster/6379/redis.pid loglevel notice logfile "/app/redis-cluster/6379/redis.log" databases 16 always-show-logo no set-proc-title yes proc-title-template "{title} {listen-addr} {server-mode}" ################################ SNAPSHOTTING ################################ # Save the DB to disk. # # save <seconds> <changes> # # Redis will save the DB if both the given number of seconds and the given # number of write operations against the DB occurred. # # Snapshotting can be completely disabled with a single empty string argument # as in following example: # # save "" # # Unless specified otherwise, by default Redis will save the DB: # * After 3600 seconds (an hour) if at least 1 key changed # * After 300 seconds (5 minutes) if at least 100 keys changed # * After 60 seconds if at least 10000 keys changed # # You can set these explicitly by uncommenting the three following lines. # # save 3600 1 # save 300 100 # save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb rdb-del-sync-files no dir /app/redis-cluster/6379/ replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-diskless-load disabled repl-disable-tcp-nodelay no replica-priority 100 acllog-max-len 128 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no lazyfree-lazy-user-del no lazyfree-lazy-user-flush no oom-score-adj no oom-score-adj-values 0 200 800 disable-thp yes appendonly yes 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 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 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 jemalloc-bg-thread yes ``` #### 三、启动 ``` #依次启动所有集群节点 redis-server redis-cluster/6379/redis.conf & ``` #### 四、创建集群 ``` redis-cli --cluster create 10.0.0.58:6379 10.0.0.58:6380 10.0.0.59:6379 10.0.0.59:6380 10.0.0.60:6379 10.0.0.60:6380 --cluster-replicas 1 ``` #### 五、问题 1. **需要开启相关端口,除了redis配置的端口外还需****放开N+10000**的端口。 2. **公网访问需要配置公网ip,且nodes.conf需要把内网ip换成公网ip。需要停止redis服务后,修改才会生效。** © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 If you think my article is useful to you, please feel free to appreciate