如何创建redis集群

1.Download

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
or
curl -o http://download.redis.io/releases/redis-5.0.5.tar.gz

 

2.Compile

On linux: make MALLOC=libc
On Mac: make MALLOC=jemalloc

 

3.Install

make install

 

4.Configuration

(3 Master and 3 Slave nodes)

port 7000(-7005)
bind 192.168.133.130
daemonize yes
pidfile /var/run/redis_7000.pid
dir /data/redis_data/7000
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 10100
appendonly yes


5.Start Server

On Master Node:
/usr/local/bin/redis-server redis01.conf
/usr/local/bin/redis-server redis03.conf
/usr/local/bin/redis-server redis05.conf


On Slave Node:
/usr/local/bin/redis-server redis02.conf
/usr/local/bin/redis-server redis04.conf
/usr/local/bin/redis-server redis06.conf


6.Create Cluster

On 4.x:
redis-trib.rb create --replicas 1 192.168.133.130:7000 192.168.133.130:7002 192.168.133.130:7004 192.168.133.132:7001 192.168.133.132:7003 192.168.133.132:7005


On 5.x:
redis-cli --cluster create 192.168.133.130:7000 192.168.133.130:7002 192.168.133.130:7004 192.168.133.132:7001 192.168.133.132:7003 192.168.133.132:7005 --cluster-replicas 1

 


7.Manage Cluster

redis-cli -c -h 192.168.133.130 -p 7000
192.168.133.130:7000> 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:1
cluster_stats_messages_ping_sent:1329
cluster_stats_messages_pong_sent:1248
cluster_stats_messages_sent:2577
cluster_stats_messages_ping_received:1243
cluster_stats_messages_pong_received:1329
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:2577

192.168.133.130:7000> CLUSTER HELP
1) CLUSTER <subcommand> arg arg ... arg. Subcommands are:
2) ADDSLOTS <slot> [slot ...] -- Assign slots to current node.
3) BUMPEPOCH -- Advance the cluster config epoch.
4) COUNT-failure-reports <node-id> -- Return number of failure reports for <node-id>.
5) COUNTKEYSINSLOT <slot> - Return the number of keys in <slot>.
6) DELSLOTS <slot> [slot ...] -- Delete slots information from current node.
7) FAILOVER [force|takeover] -- Promote current replica node to being a master.
8) FORGET <node-id> -- Remove a node from the cluster.
9) GETKEYSINSLOT <slot> <count> -- Return key names stored by current node in a slot.
10) FLUSHSLOTS -- Delete current node own slots information.
11) INFO - Return onformation about the cluster.
12) KEYSLOT <key> -- Return the hash slot for <key>.
13) MEET <ip> <port> [bus-port] -- Connect nodes into a working cluster.
14) MYID -- Return the node id.
15) NODES -- Return cluster configuration seen by node. Output format:
16) <id> <ip:port> <flags> <master> <pings> <pongs> <epoch> <link> <slot> ... <slot>
17) REPLICATE <node-id> -- Configure current node as replica to <node-id>.
18) RESET [hard|soft] -- Reset current node (default: soft).
19) SET-config-epoch <epoch> - Set config epoch of current node.
20) SETSLOT <slot> (importing|migrating|stable|node <node-id>) -- Set slot state.
21) REPLICAS <node-id> -- Return <node-id> replicas.
22) SLOTS -- Return information about slots range mappings. Each range is made of:
23) start, end, master and replicas IP addresses, ports and ids

shutdown cluster:
redis_sourcecode/utils/create-cluster stop

8. Compression Test

redis-benchmark -n 1000000 -q -h 192.168.128.131 -p 7000
PING_INLINE: 85470.09 requests per second
PING_BULK: 102040.82 requests per second
SET: 112359.55 requests per second
GET: 92592.59 requests per second
INCR: 88495.58 requests per second
LPUSH: 86956.52 requests per second
RPUSH: 97087.38 requests per second
LPOP: 101010.10 requests per second
RPOP: 93457.95 requests per second
SADD: 88495.58 requests per second
HSET: 90090.09 requests per second
SPOP: 97087.38 requests per second
LPUSH (needed to benchmark LRANGE): 93457.95 requests per second
LRANGE_100 (first 100 elements): 53475.93 requests per second
LRANGE_300 (first 300 elements): 23094.69 requests per second
LRANGE_500 (first 450 elements): 16863.41 requests per second
LRANGE_600 (first 600 elements): 13513.51 requests per second
MSET (10 keys): 98039.22 requests per second

posted @ 2019-10-17 22:45  heycomputer  阅读(144)  评论(0编辑  收藏  举报