Redis Cluster centos 搭建
阿新 • • 發佈:2018-11-11
1.首先下載redis cluster的最新穩定版
到http://redis.io/download確定穩定版版本號
在centos要下載的目當下執行wget命令,下載redis cluster最新版
shell > wget -c -P ./ http://download.redis.io/releases/redis-3.0.6.tar.gz
2.解壓redis cluster安裝包,並進入redis目錄進行編譯
shell > tar xzvf redis-3.0.6.tar.gz redis-3.0.6 shell > cd redis-3.0.6 shell > make MALLOC=libc(據說不加此引數會報錯)
3.安裝ruby,此舉是為了執行redis-trib.rb這個指令碼,因為這個指令碼是作者用ruby寫的
shell > yum -y install ruby
4.安裝redis gem,這個也是執行redis-trib.rb這個指令碼的條件之一,這個在redis目錄下安裝即可
shell > gem install redis
5.建立redis-cluster的各個節點目錄,因redis叢集最低要求6個節點,所以這邊就建立了6個節點目錄,並以埠號命名目錄
mkdir redis-cluster/6000 …… mkdir redis-cluster/6005 //拷貝基礎配置並去掉其中需要各節點需要單獨定義的配置項 cp redis-3.0.6/redis.conf redis-cluster/cluster-common.conf //在各埠目錄建立單獨的自定義配置,並把公共配置包含進去 vim redis-cluster/6000/node-6000.conf //簡單配置示例如下 include /opt/local/redis/redis-cluster/cluster-common.conf pidfile /opt/local/redis/redis-cluster/6000/node-6000.pid port 6000 bind 10.130.161.16 dir /opt/local/redis/redis-cluster/6000/ logfile /opt/local/redis/redis-cluster/6000/node-6000.log dbfilename node-6000.rdb appendfilename node-6000.aof cluster-enabled yes #此配置項是redis建立叢集時自身儲存配置資訊的檔案,不可以人工修改其內容 cluster-config-file /opt/local/redis/redis-cluster/6000/nodes.conf cluster-node-timeout 2000
6.建立啟動指令碼
shell > cd redis-cluster shell > vim redis-start.sh //使指令碼可執行 shell > chmod 755 redis-start.sh //指令碼簡單示例如下 #! /usr/bin/env bash /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6000/node-6000.conf /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6001/node-6001.conf /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6002/node-6002.conf /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6003/node-6003.conf /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6004/node-6004.conf /opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6005/node-6005.conf #其中--replicas 1選項是指一個master節點分配一個slave從節點 /opt/local/redis/redis-3.0.6/src/redis-trib.rb create --replicas 1 10.130.161.16:6000 10.130.161.16:6001 10.130.161.16:6002 10.130.161.16:6003 10.130.161.16:6004 10.130.161.16:6005
7.啟動指令碼
./redis-start.sh
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.130.161.16:6000
10.130.161.16:6001
10.130.161.16:6002
Adding replica 10.130.161.16:6003 to 10.130.161.16:6000
Adding replica 10.130.161.16:6004 to 10.130.161.16:6001
Adding replica 10.130.161.16:6005 to 10.130.161.16:6002
M: 2c29d9720d7f48040325e454e7f73eb58c438825 10.130.161.16:6000
slots:0-5460 (5461 slots) master
M: e5eac3cb05b73e658c8bcd89169c163ebfafd7c6 10.130.161.16:6001
slots:5461-10922 (5462 slots) master
M: 28146a165ec3204ed22919afde19127f2082461b 10.130.161.16:6002
slots:10923-16383 (5461 slots) master
S: 57c14dec53a2185245b593fb203485c8e2cf9b1b 10.130.161.16:6003
replicates 2c29d9720d7f48040325e454e7f73eb58c438825
S: 33a4ae96eafcd6389c71cc359970f935d8b04637 10.130.161.16:6004
replicates e5eac3cb05b73e658c8bcd89169c163ebfafd7c6
S: 35e465c2960a684811eefd6f8b916ae18414d206 10.130.161.16:6005
replicates 28146a165ec3204ed22919afde19127f2082461b
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 10.130.161.16:6000)
M: 2c29d9720d7f48040325e454e7f73eb58c438825 10.130.161.16:6000
slots:0-5460 (5461 slots) master
M: e5eac3cb05b73e658c8bcd89169c163ebfafd7c6 10.130.161.16:6001
slots:5461-10922 (5462 slots) master
M: 28146a165ec3204ed22919afde19127f2082461b 10.130.161.16:6002
slots:10923-16383 (5461 slots) master
M: 57c14dec53a2185245b593fb203485c8e2cf9b1b 10.130.161.16:6003
slots: (0 slots) master
replicates 2c29d9720d7f48040325e454e7f73eb58c438825
M: 33a4ae96eafcd6389c71cc359970f935d8b04637 10.130.161.16:6004
slots: (0 slots) master
replicates e5eac3cb05b73e658c8bcd89169c163ebfafd7c6
M: 35e465c2960a684811eefd6f8b916ae18414d206 10.130.161.16:6005
slots: (0 slots) master
replicates 28146a165ec3204ed22919afde19127f2082461b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.