Redis集群安装
检查环境:
Ruby
[hadoop@hadoop01 ~]$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
zlib
[hadoop@hadoop01 ~]$ rpm -qa |grep zlib
zlib-1.2.3-29.el6.x86_64
rubygems
[hadoop@hadoop01 ~]$ rpm -qa |grep rubygems
rubygems-1.3.7-5.el6.noarch
gcc
[hadoop@hadoop01 ~]$ rpm -qa |grep gcc libgcc-4.4.7-11.el6.x86_64 gcc-4.4.7-11.el6.x86_64
gem-redis
[hadoop@hadoop01 ~]$ sudo gem install redis --version 3.0.0 Successfully installed redis-3.0.0 1 gem installed Installing ri documentation for redis-3.0.0... Installing RDoc documentation for redis-3.0.0...
解压编译Redis
解压:
[root@hadoop01 redis]# tar zxvf redis-3.0.1.tar.gz
make install
[root@hadoop01 redis]# cd redis-3.0.1 [root@hadoop01 redis-3.0.1]# make install
运行、测试
[hadoop@hadoop01 bin]$ redis-server /usr/lib/redis/redis-3.0.1/redis.conf [hadoop@hadoop01 ~]$ redis-cli 127.0.0.1:6379> set name gsw OK 127.0.0.1:6379> get name "gsw" 127.0.0.1:6379> set age 16 OK 127.0.0.1:6379> get age "16" 127.0.0.1:6379> set age 17 OK 127.0.0.1:6379> get age "17"
数据测试:
redis-benchmark -l
分布式集群安装
创建本地测试目录
$ mkdir -p /home/hadoop/redis $ cd /root/test/redis-cluster $ mkdir 7001 7002 7003 8001 8002 8003 bin conf log rdb
结构如下:
. |-- 7001 | |-- appendonly-7001.aof | |-- dump-7001.rdb | `-- nodes.conf |-- 7002 | |-- appendonly-7002.aof | |-- dump-7002.rdb | `-- nodes.conf |-- 7003 | |-- appendonly-7003.aof | |-- dump-7003.rdb | `-- nodes.conf |-- 8001 | |-- appendonly-8001.aof | |-- dump-8001.rdb | `-- nodes.conf |-- 8002 | |-- appendonly-8002.aof | |-- dump-8002.rdb | `-- nodes.conf |-- 8003 | |-- appendonly-8003.aof | |-- dump-8003.rdb | `-- nodes.conf |-- bin | |-- create-cluster.sh | `-- start.sh |-- conf | |-- redis-7001.conf | |-- redis-7002.conf | |-- redis-7003.conf | |-- redis-8001.conf | |-- redis-8002.conf | |-- redis-8003.conf | `-- redis-common.conf |-- log | |-- redis-7001.log | |-- redis-7002.log | |-- redis-7003.log | |-- redis-8001.log | |-- redis-8002.log | `-- redis-8003.log `-- rdb `-- dump.rdb
配置redis cluster
通用配置文件
daemonize no pidfile /var/run/redis.pid #port 7001 tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice #logfile "/var/log/redis/redis-7001.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes #dbfilename dump.rdb #dir /usr/lib/redis/redis-3.0.1/7001 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 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 lua-time-limit 5000 cluster-enabled yes #cluster-config-file /home/hadoop/redis/redis-3.0.1/7001/nodes.conf cluster-node-timeout 5000 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-entries 512 list-max-ziplist-value 64 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
node配置文件
include /home/hadoop/redis/conf/redis-common.conf port 7001 logfile /home/hadoop/redis/log/redis-7001.log dbfilename dump-7001.rdb dir /home/hadoop/redis/7001 cluster-config-file /home/hadoop/redis/7001/nodes.conf appendfilename appendonly-7001.aof
集群初始化、构建
初始化集群
测试
$ redis-cli -c -p 7001
查看节点分布信息
127.0.0.1:7001> cluster nodes 77c473e72ba1816dca3a0f1a32d87b97c863df04 192.168.37.128:7003 master - 0 1432421074590 3 connected 10923-16383 65ddf149df8abf05e371eedf54fc05dfc86012a9 192.168.37.128:8001 slave 4370c6374cf4d9574ca49b9dd1db6d6385bfceb9 0 1432421075094 4 connected 3e106fbd715e3ba9b3a3dc4cccf81678cb12218d 192.168.37.128:8002 slave fd936189b66f5f954481aea578dcb529e51b70e4 0 1432421076107 5 connected fd936189b66f5f954481aea578dcb529e51b70e4 192.168.37.128:7002 master - 0 1432421076107 2 connected 5461-10922 4370c6374cf4d9574ca49b9dd1db6d6385bfceb9 192.168.37.128:7001 myself,master - 0 0 1 connected 0-5460 656756164efb04c9f5446460bb51ec3adf5a3689 192.168.37.128:8003 slave 77c473e72ba1816dca3a0f1a32d87b97c863df04 0 1432421076612 6 connected
查看 slots 分布信息
127.0.0.1:7001> cluster slots 1) 1) (integer) 10923 2) (integer) 16383 3) 1) "192.168.37.128" 2) (integer) 7003 4) 1) "192.168.37.128" 2) (integer) 8003 2) 1) (integer) 5461 2) (integer) 10922 3) 1) "192.168.37.128" 2) (integer) 7002 4) 1) "192.168.37.128" 2) (integer) 8002 3) 1) (integer) 0 2) (integer) 5460 3) 1) "192.168.37.128" 2) (integer) 7001 4) 1) "192.168.37.128" 2) (integer) 8001