Redis 3.0集群搭建/配置/FAQ


·聲明

1,已官網中文教程為基礎,邊看邊學,結合環境現狀搭建。

2,哥對Ruby不熱愛、不熟悉、不感冒,所述內容如有疑義請諒解。

3,3.0官說集群還在測試中,其實用用也還算馬馬虎虎,對外集群API真心少,望有識之士能夠出力。

 

·准備材料

VM9,CentOS 6.4_x86_64(2.6+),SecureCRT,CentOS-6.4-x86_64-bin-DVD1.iso

redis官網:redis-3.0.0-beta1.tar.gz

ruby官網:rubygems-2.0.7.zip

rubygem官網:redis-3.0.7.gem

 

·下鍋

1,把一些基礎包裝一下,后面會用到

service iptables stop

放入DVD1-

yum install –y gcc*

yum install –y ruby

yum install –y ruby-rdoc

2,裝redis

tar -xvf redis-3.0.0-beta1.tar.gz

cd redis-3.0.0-beta

make

make install

ll /usr/local/bin

3,配置集群(假定 $REDIS_HOME=/root/soft/redis,就像ORACLE_HOME一樣)

cd $REDIS_HOME

mkdir cluster-test

cd cluster-test

mkdir 7000 7001 7002 7003 7004 7005

vim redis.conf,修改內容如下:

port 7000 個性化

cluster-enabled yes
cluster-config-file nodes.7000.conf 個性化
cluster-node-timeout 5000
appendonly yes
appendfilename "appendonly.7000.aof" 個性化
deamonize yes
pidfile 個性化
log 個性化

 

cp ../redis.conf ./7000

cp ../redis.conf ./7001

cp ../redis.conf ./7002

cp ../redis.conf ./7003

cp ../redis.conf ./7004

cp ../redis.conf ./7005

cp /usr/local/bin/redis-server ./7000

cp /usr/local/bin/redis-server ./7001

cp /usr/local/bin/redis-server ./7002

cp /usr/local/bin/redis-server ./7003

cp /usr/local/bin/redis-server ./7004

cp /usr/local/bin/redis-server ./7005

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7000/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7001/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7002/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7003/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7004/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7005/redis.conf

如果需要看一看:ps –ef|grep redis

如果需要殺一殺:ps -ef|grep redis|egrep -v grep|awk -F ' ' '{print $2}'|xargs kill -9

4,配置ruby集群腳本

cd /root/soft/rubygems

ruby setup.rb

到redis-3.0.7.gem路徑下

gem install -l redis(不用L的話,走ruby官網,95%被WALL,你懂得,自己改source吧)

./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7002 127.0.0.3:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7005(半路記得“yes"一下)

>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7000 replica #1 is 127.0.0.1:7003
127.0.0.1:7001 replica #1 is 127.0.0.1:7004
127.0.0.1:7002 replica #1 is 127.0.0.1:7005
M: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7001
   slots:5461-10921 (5461 slots) master
M: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7002
   slots:10922-16383 (5462 slots) master
S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7003
   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052
S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7004
   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052
S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 127.0.0.1:7005
   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join...
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 75bab28893c3536aecdb9879df97db89b24ce21e 127.0.0.1:7000
   slots:5461-10921 (5461 slots) master
M: cfc344721cad8a5ddb7a8d675eb3a4d6e5b9d1c1 127.0.0.1:7002
   slots:10922-16383 (5462 slots) master
M: 01b3977a3f592fd1538e8c83f86bbba37d0c1058 127.0.0.3:7003
   slots:0-5460 (5461 slots) master
M: df59fce238a1c538933bdc170edb27835d0b7cc7 127.0.0.1:7004
   slots: (0 slots) master
   replicates 01b3977a3f592fd1538e8c83f86bbba37d0c1058
M: b6bdb2d309aa7f0b810288f24e975230419f25b1 127.0.0.1:7005
   slots: (0 slots) master
   replicates 75bab28893c3536aecdb9879df97db89b24ce21e
M: b6bdb2d309aa7f0b810288f24e975230419f25b1 127.0.0.1:7005
   slots: (0 slots) master
   replicates cfc344721cad8a5ddb7a8d675eb3a4d6e5b9d1c1
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

  redis-cli -c -p 7000

127.0.0.1:7000> set b c
-> Redirected to slot [3300] located at 127.0.0.1:7003
OK
127.0.0.1:7003> set hello world
OK
127.0.0.1:7003> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
(nil)
127.0.0.1:7002> get hello
-> Redirected to slot [866] located at 127.0.0.1:7003
"world"
127.0.0.1:7003> get b
"c"
127.0.0.1:7003> 

 

·FAQ

*** ERROR: Invalid configuration for cluster creation.

*** Redis Cluster requires at least 3 master nodes.

*** This is not possible with 4 nodes and 1 replicas per node.

*** At least 6 nodes are required.

 

·Redis官說,至少3+3,還延續着Master-Slave的設計理念,這點上個人覺得Cassandra的一致性確實了得。

 

Either the node already knows other nodes

 

·因為報錯是ruby報的,不太能夠理解其意思,因為我之前做了些單機壓測,可能直接疊上集群會有垃圾數據,所以把/var/db/和/var/log/下能清空的都清空了。

 

[13321] 09 Mar 08:09:24.290 # Handshake error: we already know node bc66d90ca24eb6b69a3b375a4e242fef00de2052, updating the address if needed.

 

·同樣道理,ruby報的錯,一開始一直在join被我ctrl+c之后開始報錯,用上面的方法無果。把所有app目錄清空然后redis重裝。大家測試時,最后事先vmware快照一下或者redis現網數據備份一下。

 

·OK,自己爽一下吧

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM