Redis環境簡單部署(集群/雙機)


 

redis 3.0 壓縮包下載:

百度雲    ---鏈接:http://pan.baidu.com/s/1i5quyzz 密碼:7kka

 

當前解壓redis,包含了dependency 目錄;

 dependency 目錄 包含了所需要的ruby,redis.gem,rubygems; 

1、ruby 源碼安裝;

[root@cswg9vm992800 ruby-2.2.2]# ./configure --prefix=/usr/local/ruby    

[root@cswg9vm992800 ruby-2.2.2]# make &&make install

安裝完成配置環境變量  /usr/local/ruby/bin

2、安裝rubygems;

[root@cswg9vm992800 rubygems-2.4.7]# ruby setup.rb

3、gem指定源表;

[root@cswg9vm992800 rubygems-2.4.7]# gem install -l /home/redis3.0/dependency/redis-3.0.6.gem

注:把壓縮包原本的ruby和rubtgems 刪掉重新解壓;否則編譯會出現問題;

 

redis 安裝

client 1:

1、當前解壓redis包含三個基礎配置節點

從上圖可以看出,分別是7001、7002、7003

redis-common.conf為當前三個節點的公共配置文件(默認開啟rdb,關閉aof)

 

2、進入7001下面,查看如下

編輯redis-7001.conf文件:

注:當前紅色框中的配置路徑如果有更改,需配置路徑信息。

注: 刪除 nodes-7001.conf  節點配置文件,該配置文件創建集群節點時會自動生產,不刪除啟動集群會報錯;7002,7003 根據上述進行相同配置操作;

 

3、在redis目錄下創建log文件夾

mkdir log

 

4、啟動當前配置好的節點

src/redis-server  conf/7001/redis-7001.conf > log/redis-7001.log 2>&1 &  

src/redis-server  conf/7002/redis-7002.conf > log/redis-7002.log 2>&1 &  

src/redis-server  conf/7003/redis-7003.conf > log/redis-7003.log 2>&1 &

 

client 2:

 根據client 1 進行相同配置操作;其中節點建議將7001、7002、7003 改為 7004、7005、7006 ;其余不變;

啟動當前配置好的節點

src/redis-server  conf/7004/redis-7004.conf > log/redis-7004.log 2>&1 &  

src/redis-server  conf/7005/redis-7005.conf > log/redis-7005.log 2>&1 &  

src/redis-server  conf/7006/redis-7006.conf > log/redis-7006.log 2>&1 &

 

啟動集群

[root@cswg9vm992800 redis3.0]#

[root@cswg9vm992800 redis3.0]# /home/cattsoft/redis3.0/src/redis-trib.rb  create  --replicas  1   172.51.46.10:7001  172.51.46.10:7002  172.51.46.10:7003 172.51.46.11:7004 172.51.46.11:7005  172.51.46.11:7006

>>> Creating cluster

Connecting to node 172.51.46.10:7001: OK

Connecting to node 172.51.46.10:7002: OK

Connecting to node 172.51.46.10:7003: OK

Connecting to node 172.51.46.11:7004: OK

Connecting to node 172.51.46.11:7005: OK

Connecting to node 172.51.46.11:7006: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

172.51.46.10:7001

172.51.46.11:7004

172.51.46.10:7002

Adding replica 172.51.46.11:7005 to 172.51.46.10:7001

Adding replica 172.51.46.10:7003 to 172.51.46.11:7004

Adding replica 172.51.46.11:7006 to 172.51.46.10:7002

M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001

   slots:0-5460 (5461 slots) master

M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002

   slots:10923-16383 (5461 slots) master

S: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003

   replicates 564ed966653081e9b1834b8bd56bd379b13ece4f

M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004

   slots:5461-10922 (5462 slots) master

S: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005

   replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae

S: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006

   replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091

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 172.51.46.10:7001)

M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001

   slots:0-5460 (5461 slots) master

M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002

   slots:10923-16383 (5461 slots) master

M: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003

   slots: (0 slots) master

   replicates 564ed966653081e9b1834b8bd56bd379b13ece4f

M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004

   slots:5461-10922 (5462 slots) master

M: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005

   slots: (0 slots) master

   replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae

M: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006

   slots: (0 slots) master

   replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

[root@cswg9vm992800 redis3.0]#

至此,集群啟動成功;

 

查看集群狀態:

[root@cswg9vm992800 redis3.0]# src/redis-trib.rb check 172.51.46.10:7001

Connecting to node 172.51.46.10:7001: OK

Connecting to node 172.51.46.11:7005: OK

Connecting to node 172.51.46.10:7002: OK

Connecting to node 172.51.46.10:7003: OK

Connecting to node 172.51.46.11:7004: OK

Connecting to node 172.51.46.11:7006: OK

>>> Performing Cluster Check (using node 172.51.46.10:7001)

M: f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae 172.51.46.10:7001

   slots:0-5460 (5461 slots) master

   1 additional replica(s)

S: 54b3a75fd7dd3006c8600852ed1ee9029885f55d 172.51.46.11:7005

   slots: (0 slots) slave

   replicates f8ca2cfd45213e51fe00aa90e4f8bb2d661b56ae

M: 2556b9dacd53e7f7344a8964c1e59d44a4a45091 172.51.46.10:7002

   slots:10923-16383 (5461 slots) master

   1 additional replica(s)

S: 27fca5f41cfe0387e8b1f3133251f45ae0d01c73 172.51.46.10:7003

   slots: (0 slots) slave

   replicates 564ed966653081e9b1834b8bd56bd379b13ece4f

M: 564ed966653081e9b1834b8bd56bd379b13ece4f 172.51.46.11:7004

   slots:5461-10922 (5462 slots) master

   1 additional replica(s)

S: 119232a9a68a4baa4d653207c18da249e8e9fa31 172.51.46.11:7006

   slots: (0 slots) slave

   replicates 2556b9dacd53e7f7344a8964c1e59d44a4a45091

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

 

測試:

[root@cswg9vm992800 redis3.0]# ./bin/redis-cli -c -p 7002

127.0.0.1:7002> set a1 999

-> Redirected to slot [7785] located at 172.51.46.11:7004

OK

172.51.46.11:7004>

[root@cswg9vm992800 redis3.0]# ./bin/redis-cli -c -p 7001

127.0.0.1:7001> get a1

-> Redirected to slot [7785] located at 172.51.46.11:7004

"999"

172.51.46.11:7004>

[root@cswg9vm992800 redis3.0]# ./bin/redis-cli -c -p 7003

127.0.0.1:7003> get a1

-> Redirected to slot [7785] located at 172.51.46.11:7004

"999"

172.51.46.11:7004>

[root@cswg9vm992800 redis3.0]#

 

redis 常見問題:

1、[ERR] Node 172.51.46.11:7001 is not empty. Either the nodealready knows other nodes (check with CLUSTER NODES) or contains some

解決辦法:

1)將每個節點下aof、rdb、nodes.conf本地備份文件刪除; 
3)之后再執行腳本,成功執行;

2、/lib/redis/client.rb:85:in `call': ERR Slot 0 is already busy  巴拉巴拉的錯誤;

 建議:修復集群

src/redis-trib.rb fix 127.0.0.1:7001

修復每個節點7001、7002、7003、7004、7005、7006 ;

注:其余問題,百度都比較容易找到解決辦法,在此不再一一枚舉說明;

 


免責聲明!

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



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