之前写过一套基于redis-4.0.6版本的测试集群部署
https://www.cnblogs.com/mrice/p/10730309.html
最近生产环境需要部署一套redis-5.0.5版本集群;
环境:
服务器:6台
操作系统:Red Hat Enterprise Linux Server release 7.4
redis:redis-5.0.5
ruby:ruby-2.0.0 (redis-3.3.5.gem)
一、基础安装
1、安装好ruby
2、安装redis-3.3.5.gem
gem install redis-3.3.5.gem
3、修改系统变量
echo never > /sys/kernel/mm/transparent_hugepage/enabled echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf echo 511 > /proc/sys/net/core/somaxconn sysctl -p
二、redis安装
1、安装redis
压缩安装包后
make && make install
2、配置redis
从安装文件中复制一份redis.conf,下面是配置文件内容,红色字体大家需要注意一下。
bind 10.20.1.56 //修改绑定地址 protected-mode yes port 6379 //可修改自己规则端口,但集群状态下需要注意,集群使用端口会在此端口上增加10000,所以redis自身端口+10000不能超过65535。 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile /mrice/redis-cluster/redis-6379/redis_6379.pid //pid存放位置 loglevel notice logfile "/mrice/redis-cluster/redis-6379/logs/redis_6379.log" 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 "/mrice/redis-cluster/redis-6379/data" //数据存放目录 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 mrice //增加认证 masterauth mrice //主从复制时认证密码 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 cluster-enabled yes //开启集群功能 cluster-config-file /mrice/redis-cluster/redis-6379/logs/nodes.conf //集群状态 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
3、配置文件修改完后,启动redis服务
redis-server redis.conf
4、建立集群
这里注意的是以之前版本不同的是,通过redis-cli 来完成。
redis-cli --cluster create 10.20.1.51:6379 10.20.1.52:6379 10.20.1.53:6379 10.20.1.54:6379 10.20.1.55:6379 10.20.1.56:6379 --cluster-replicas 1 -a mrice
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 10.20.1.55:6379 to 10.20.1.51:6379 Adding replica 10.20.1.56:6379 to 10.20.1.52:6379 Adding replica 10.20.1.54:6379 to 10.20.1.53:6379 M: 9cd49f7033ab577919a645bc0b8fed7e14084e02 10.20.1.51:6379 slots:[0-5460] (5461 slots) master M: 2ecfdb47842b341c7dd91d3d5a807787c1790ca2 10.20.1.52:6379 slots:[5461-10922] (5462 slots) master M: 6efe5181ae476ae33274b81c8f2f877444381795 10.20.1.53:6379 slots:[10923-16383] (5461 slots) master S: 9f3fce417fbe0febe818e1b67a1b402c3b831b61 10.20.1.54:6379 replicates 6efe5181ae476ae33274b81c8f2f877444381795 S: c13ffcdc2960bd59471eb050c2e8bfdf0a8e36e8 10.20.1.55:6379 replicates 9cd49f7033ab577919a645bc0b8fed7e14084e02 S: 05a2efa665ee97246591a42836ed62e807b3f240 10.20.1.56:6379 replicates 2ecfdb47842b341c7dd91d3d5a807787c1790ca2 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join ........ >>> Performing Cluster Check (using node 10.20.1.51:6379) M: 9cd49f7033ab577919a645bc0b8fed7e14084e02 10.20.1.51:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 05a2efa665ee97246591a42836ed62e807b3f240 10.20.1.56:6379 slots: (0 slots) slave replicates 2ecfdb47842b341c7dd91d3d5a807787c1790ca2 M: 6efe5181ae476ae33274b81c8f2f877444381795 10.20.1.53:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 2ecfdb47842b341c7dd91d3d5a807787c1790ca2 10.20.1.52:6379 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: c13ffcdc2960bd59471eb050c2e8bfdf0a8e36e8 10.20.1.55:6379 slots: (0 slots) slave replicates 9cd49f7033ab577919a645bc0b8fed7e14084e02 S: 9f3fce417fbe0febe818e1b67a1b402c3b831b61 10.20.1.54:6379 slots: (0 slots) slave replicates 6efe5181ae476ae33274b81c8f2f877444381795 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [root@EOMS-daiwei3-OSS logs]#
5、验证
redis-cli -p 6379 -h 10.20.1.56 -a mrice
10.20.1.56:6379> INFO cluster # Cluster cluster_enabled:1 10.20.1.56:6379> CLUSTER INFO cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:2 cluster_stats_messages_ping_sent:17879 cluster_stats_messages_pong_sent:18519 cluster_stats_messages_sent:36398 cluster_stats_messages_ping_received:18519 cluster_stats_messages_pong_received:17168 cluster_stats_messages_fail_received:2 cluster_stats_messages_received:35689 10.20.1.56:6379> CLUSTER SLOTS 1) 1) (integer) 10923 2) (integer) 16383 3) 1) "10.20.1.53" 2) (integer) 6379 3) "6efe5181ae476ae33274b81c8f2f877444381795" 4) 1) "10.20.1.54" 2) (integer) 6379 3) "9f3fce417fbe0febe818e1b67a1b402c3b831b61" 2) 1) (integer) 0 2) (integer) 5460 3) 1) "10.20.1.51" 2) (integer) 6379 3) "9cd49f7033ab577919a645bc0b8fed7e14084e02" 4) 1) "10.20.1.55" 2) (integer) 6379 3) "c13ffcdc2960bd59471eb050c2e8bfdf0a8e36e8" 3) 1) (integer) 5461 2) (integer) 10922 3) 1) "10.20.1.52" 2) (integer) 6379 3) "2ecfdb47842b341c7dd91d3d5a807787c1790ca2" 4) 1) "10.20.1.56" 2) (integer) 6379 3) "05a2efa665ee97246591a42836ed62e807b3f240"