前言:
集羣環境的搭建
[root@localhost ~]# yum install zlib
[root@localhost ~]# yum install ruby
3.redis的安裝
[root@localhost software]# mkdir redis
[root@localhost software]# wget http://download.redis.io/redis-stable.tar.gz
[root@localhost software]# tar xvzf redis-stable.tar.gz
[root@localhost software]# make && make test
redis:[root@localhost software]# whereis redis-cli
redis-cli: /usr/local/bin/redis-cli
[root@localhost software]# <strong>redis-server </strong>
13237:C 13 Aug 20:48:24.171 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
13237:M 13 Aug 20:48:24.171 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 13237
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
13237:M 13 Aug 20:48:24.172 # Server started, Redis version 3.0.3
13237:M 13 Aug 20:48:24.173 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
13237:M 13 Aug 20:48:24.173 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
13237:M 13 Aug 20:48:24.174 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
13237:M 13 Aug 20:48:24.174 * The server is now ready to accept connections on port 6379
表明redis安裝成功!
[root@localhost my-redis-cluster]# pwd
/root/software/redis-3.0.3/my-redis-cluster
[root@localhost my-redis-cluster]# ls
node-7000.conf node-7001.conf node-7002.conf node-7003.conf node-7004.conf node-7005.conf
node-7000.conf 文件內容如下:
[root@localhost my-redis-cluster]# cat node-7000.conf
pidfile /root/software/redis-3.0.3/pid/node7000.pid
logfile "/root/software/redis-3.0.3/logs/node-7000.log"
dir /root/software/redis-3.0.3/data/node-7000
port <span style="color:#ff0000;">7000</span>
daemonize yes
cluster-enabled <span style="color:#ff0000;"><strong>yes</strong></span>
cluster-config-file node-7000.conf
cluster-node-timeout 5000
appendonly yes
大概解釋下: 開啓集羣、監聽端口...這個文件的內容比較簡單,其他node-700x.conf 文件類似,就不一一羅列
[root@localhost my-redis-cluster]# cd ..
[root@localhost redis-3.0.3]# ls
00-RELEASENOTES COPYING dump.rdb Makefile pid runtest sentinel.conf utils
BUGS data INSTALL MANIFESTO README runtest-cluster src
CONTRIBUTING deps logs my-redis-cluster redis.conf runtest-sentinel tests
[root@localhost redis-3.0.3]# cd data
[root@localhost data]# ls
<strong><span style="color:#ff0000;">node-7000 node-7001 node-7002 node-7003 node-7004 node-7005</span></strong>
下一步開始啓動這6個node [root@localhost my-redis-cluster]# redis-server node-7000.conf
[root@localhost my-redis-cluster]# redis-server node-7001.conf
[root@localhost my-redis-cluster]# redis-server node-7002.conf
[root@localhost my-redis-cluster]# redis-server node-7003.conf
[root@localhost my-redis-cluster]# redis-server node-7004.conf
[root@localhost my-redis-cluster]# redis-server node-7005.conf
[root@localhost my-redis-cluster]# ps -ef|grep redis
root 12937 1 0 20:22 ? 00:00:00 redis-server *:7000 [cluster]
root 12941 1 1 20:22 ? 00:00:00 redis-server *:7001 [cluster]
root 12945 1 1 20:22 ? 00:00:00 redis-server *:7002 [cluster]
root 12949 1 0 20:22 ? 00:00:00 redis-server *:7003 [cluster]
root 12953 1 0 20:22 ? 00:00:00 redis-server *:7004 [cluster]
root 12957 1 2 20:23 ? 00:00:00 redis-server *:7005 [cluster]
從上發現Node都成功啓動,但此時每個Node都是相互獨立的,需要講各個Node join cluster
./redis-trib.rb create --replicas 1 192.168.1.103:7000 192.168.1.103:7001 192.168.1.103:7002 192.168.1.103:7003 192.168.1.103:7004 192.168.1.103:7005
[root@localhost src]# ./redis-trib.rb create --replicas 1 192.168.1.103:7000 192.168.1.103:7001 192.168.1.103:7002 192.168.1.103:7003 192.168.1.103:7004 192.168.1.103:7005
>>> Creating cluster
Connecting to node 192.168.1.103:7000: OK
Connecting to node 192.168.1.103:7001: OK
Connecting to node 192.168.1.103:7002: OK
Connecting to node 192.168.1.103:7003: OK
Connecting to node 192.168.1.103:7004: OK
Connecting to node 192.168.1.103:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.103:7000
192.168.1.103:7001
192.168.1.103:7002
Adding replica 192.168.1.103:7003 to 192.168.1.103:7000
Adding replica 192.168.1.103:7004 to 192.168.1.103:7001
Adding replica 192.168.1.103:7005 to 192.168.1.103:7002
<strong><span style="color:#ff0000;">M</span></strong>: <span style="background-color: rgb(51, 255, 255);">4bc092eb4731152d15172b065c74c7a795fe6304</span> 192.168.1.103:7000
slots:<span style="color:#ff0000;"><strong>0-5460</strong></span> (5461 slots) <strong><span style="color:#ff0000;">master</span></strong>
M: f37ec54101536425ce8798e041ad75a582d7e153 192.168.1.103:7001
slots:5461-10922 (5462 slots) master
M: 7b0ca3978858454051ad572aa816eec450f31a53 192.168.1.103:7002
slots:10923-16383 (5461 slots) master
<strong><span style="color:#ff0000;">S</span></strong>: 778e649f47fa98f6d1f6b1f1043812c6685dc4a8 192.168.1.103:7003
<strong><span style="color:#ff0000;">replicates</span></strong> <span style="background-color: rgb(102, 255, 255);">4bc092eb4731152d15172b065c74c7a795fe6304</span>
S: 907feee1b665554cadc64921c7fcb8c05b8a5ab6 192.168.1.103:7004
replicates f37ec54101536425ce8798e041ad75a582d7e153
S: b2bea8ede402e2112cced7d7cea52127f18edef2 192.168.1.103:7005
replicates 7b0ca3978858454051ad572aa816eec450f31a53
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 192.168.1.103:7000)
M: 4bc092eb4731152d15172b065c74c7a795fe6304 192.168.1.103:7000
slots:0-5460 (5461 slots) master
M: f37ec54101536425ce8798e041ad75a582d7e153 192.168.1.103:7001
slots:5461-10922 (5462 slots) master
M: 7b0ca3978858454051ad572aa816eec450f31a53 192.168.1.103:7002
slots:10923-16383 (5461 slots) master
M: 778e649f47fa98f6d1f6b1f1043812c6685dc4a8 192.168.1.103:7003
slots: (0 slots) master
replicates 4bc092eb4731152d15172b065c74c7a795fe6304
M: 907feee1b665554cadc64921c7fcb8c05b8a5ab6 192.168.1.103:7004
slots: (0 slots) master
replicates f37ec54101536425ce8798e041ad75a582d7e153
M: b2bea8ede402e2112cced7d7cea52127f18edef2 192.168.1.103:7005
slots: (0 slots) master
replicates 7b0ca3978858454051ad572aa816eec450f31a53
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
http://blog.csdn.net/liaokailin/article/details/47988617