Pro-Test Jedis (jedis2.7.2) client jediscluster available
1: Installing Redis cluster and dependencies
1. Installing zlib
wget:htpp://zlib.net/zlib-1.2.8.tar.gz tar-zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8./config Ure make make Install
2. Installing Redis
wget:http://download.redis.io/redis-stable.tar.gz tar-zxvf redis-stable.tar.gz CD redis-stable Make make Install
3. Install Ruby
Gem sources-a http://ruby.taobao.org/yum install rubygems gem install Redis
2: Configure Redis
1. Create a node directory
To differentiate between master and slave, slave is 1000 more than master
mkdir/server/cluster/6380 6381 6382 7380 7381 7382
General configuration
mkdir -p /server/server/cluster/ Redis-common.conf
daemonize yes #守护进程运行 (running in the background) tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice databases 16 dir /opt/redis/data slave-serve-stale-data yes #slave只读 slave-read-only yes #not use default repl-disable-tcp-nodelay yes slave-priority 100 #打开aof持久化 appendonly yes #每秒一次aof写 appendfsync everysec the new write operation fsync no-appendfsync-on-rewrite when the #关闭在aof rewrite yes auto-aof-rewrite-min-size 64mb lua-time-limit 5000 #打开redis集群 cluster-enabled yes #节点互连超时的阀值 cluster-node-timeout 15000 cluster-migration-barrier 1 slowlog-log-slower-than 10000 slowlog-max-len 128 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 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
Special configuration
Remember to change the port
vim/server/cluster/6380/redis.conf vim/server/cluster/6381/redis.conf vim/server/cluster/6382/redis.conf vim/serve/cluster/7380/redis.conf vim/server/cluster/7381/redis.conf vim/server/cluster/6382/redis.conf
#包含通用配置 include /server/cluster/redis-common.conf #监听tcp端口 port 6379 #最大可用内存 maxmemory 100m #内存耗尽时采用的淘汰策略: # volatile-lru -> remove the key with an expire set using an lru algorithm # allkeys-lru -> remove any key Accordingly to the lru algorithm # volatile-random -> remove a random key with an expire set # allkeys-random - > remove a random key, any key # volatile-ttl -> remove the key with the nearest expire time (Minor ttl) # noeviction -> don ' t expire at all, just return An error on write operations maxmemory-policy allkeys-lru #aof存储文件 appendfilename " Appendonly-6379.aof " #不开启rdb存储, only for adding slave procedures dbfilename dump-6379.rdb # Cluster configuration file (start auto-generate) cluster-config-file nodes-6379.conf #部署在同一机器的redis实例, Auto-aof-rewrite, because the cluster environment is basically consistent memory consumption . #防止同意机器下瞬间fork所有redis进程做aof rewrite, consumes a lot of memory (PS: Cluster must turn on AOF) auto-aof-rewrite-percentage 80-100
2: Create a cluster
1. Start the Redis service
redis-server/server/cluster/6380/redis.conf redis-server/server/cluster/6381/redis.conf redis-server/server/c luster/6382/redis.conf redis-server/server/cluster/7380/redis.conf redis-server/server/cluster/7381/redis.conf Redis-server/server/cluster/7382/redis.conf
2. Create a cluster
Cd/server/server/redis-stable/src./REDIS-TRIB.RB Create--replicas 1 host:6380 host:6381 host:6382 host:7380 ..... #这里注意redis官方翻译过来的集群教程, using 127.0.0.1:prot actually very pit Daddy, #如果你使用的是java并且使用JedisCluster API to access #会报错: too many Redis cluste R redirection. #比如我的本机ip为123.133.122.141, then you should use 123.133.122.141:prot #而非127.0.0.1:p Ort
The meaning of the command is as follows:
The redis-trib.rb
command for a given program is create
, that means we want to create a new cluster.
Option --replicas 1
indicates that we want to create a slave node for each master node in the cluster.
The other parameters followed are the address lists of the instances, and we want the program to use the instance indicated by these addresses to create a new cluster.
the above command means redis-trib
that The program creates a cluster that contains three primary nodes and three slave nodes.
redis-trib
will print out an expected configuration for you to see, if you feel no problem, you can enter, you will yes
redis-trib
apply this configuration to the cluster.
View cluster Information
Redis-cli-p 6380-c127.0.0.1:6380>cluster INFOCLUSTER_STATE:OKCLUSTER_SLOTS_ASSIGNED:16384CLUSTER_SLOTS_OK : 16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch : 6cluster_my_epoch:1cluster_stats_messages_sent:19161cluster_stats_messages_received:19161
You can see that the current cluster_state is OK
use the./REDIS-TRIB.RB check host port to examine the status
./redis-trib.rb check 115.28.138.150:6380 connecting to node 115.28.138.150:6380: OK Connecting to node 115.28.138.150:7380: ok connecting to node 115.28.138.150:7382: OK Connecting to node 115.28.138.150:7381: OK connecting to node 115.28.138.150:6382: ok connecting to node 115.28.138.150:6381: OK >>> Performing cluster check (using node 115.28.138.150:6380) M: 3046c8e6efbcea5c77e90483d97b928c5e4fbe05 115.28.138.150:6380 slots:0-5460 (5461 slots) master 1 additional replica (s) s: 2f045aaecb9addea7ae8ef636e3a5415686889e4 115.28.138.150:7380 slots: (0 slots) slave replicates 3046c8e6efbcea5c77e90483d97b928c5e4fbe05 s: c09ffe456b44abedd7ba811aaad470b3f7a36ea5 115.28.138.150:7382 slots: (0 slots) slave replicates ed7200bf1cdacc18661d70c39270995582559037 s: 1866624d3330f6491d5c57e269811694bb061759 115.28.138.150:7381 slots: (0 slots) slave replicates fb5c50e062d0e770aa534315fec1aa11488c228a m: ed7200bf1cdacc18661d70c39270995582559037 115.28.138.150:6382 slots:10923-16383 (5461 slots) master 1 additional replica (s) M: fb5c50e062d0e770aa534315fec1aa11488c228a 115.28.138.150:6381 slots:5461-10922 (5462 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration. >>> check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
This article is from the "eye-tired column" blog, be sure to keep this source http://miaoni.blog.51cto.com/10720758/1696050
Redis Cluster deployment