1,準備ruby環境
安裝ruby
<code> </code><code>wget https:</code><code>//cache</code><code>.ruby-lang.org</code><code>/pub/ruby/2</code><code>.4</code><code>/ruby-2</code><code>.4.1.</code><code>tar</code><code>.gz</code>
<code> </code><code>tar</code> <code>xvf ruby-2.4.1.</code><code>tar</code><code>.gz </code>
<code> </code><code>cd</code> <code>ruby-2.4.1.</code><code>tar</code><code>.gz</code>
<code> </code><code>cd</code> <code>ruby-2.4.1</code>
<code> </code><code>.</code><code>/configure</code> <code>--prefix=</code><code>/usr/local/ruby</code>
<code> </code><code>make</code>
<code> </code><code>make</code> <code>install</code>
<code> </code><code>cp</code> <code>bin</code><code>/ruby</code> <code>/usr/local/bin/</code>
<code> </code><code>cp</code> <code>bin</code><code>/gem</code> <code>/usr/local/bin/</code>
安裝rubygem redis依賴:
<code> </code><code>wget http:</code><code>//rubygems</code><code>.org</code><code>/downloads/redis-3</code><code>.3.0.gem</code>
<code> </code><code>gem </code><code>install</code> <code>-l redis-3.3.0.gem </code>
<code> </code><code>gem list | </code><code>grep</code> <code>redis</code>
安裝redis-trib.rb:
<code>cp</code> <code>/opt/redis/redis-3</code><code>.2.4</code><code>/src/redis-trib</code><code>.rb </code><code>/usr/local/bin/</code>
/opt/redis/redis-3.2.4/目錄對應的redis源碼包解壓目錄
2,準備叢集節點
在普通redis配置檔案中加上這三項即可:
<code>cluster-enabled </code><code>yes</code> <code>#開啟群集模式</code>
<code>cluster-node-timeout 15000 </code><code>#節點逾時時間,機關為毫秒</code>
<code>cluster-config-</code><code>file</code> <code>"nodes-6379.conf"</code> <code>#指定叢集内部的配置檔案</code>
<code>ll </code><code>/data/app/redis3</code><code>.2.4</code><code>/conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:50 redis_6479.conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:50 redis_6480.conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:51 redis_6481.conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:51 redis_6482.conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:51 redis_6483.conf</code>
<code>-rw-r--r--. 1 root root 2229 Jul 11 01:51 redis_6484.conf</code>
啟動節點:
<code>redis-server redis_6479.conf</code>
<code>redis-server redis_6480.conf</code>
<code>redis-server redis_6481.conf</code>
<code>redis-server redis_6482.conf</code>
<code>redis-server redis_6483.conf</code>
<code>redis-server redis_6484.conf</code>
3,建立叢集
<code>redis-trib.rb create --replicas 1 127.0.0.1:6479 127.0.0.1:6480 127.0.0.1:6481 127.0.0.1:6482 127.0.0.1:6483 127.0.0.1:6484</code>
# --replicas 1 代表每個主節點配置多少個從節點
>>> Creating cluster
/usr/local/ruby/lib/ruby/gems/2.4.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:6479
127.0.0.1:6480
127.0.0.1:6481
Adding replica 127.0.0.1:6482 to 127.0.0.1:6479
Adding replica 127.0.0.1:6483 to 127.0.0.1:6480
Adding replica 127.0.0.1:6484 to 127.0.0.1:6481
M: 78581cf153d821c734c238d00f4de264fc95072e 127.0.0.1:6479
slots:0-5460 (5461 slots) master
M: d0d4a89f567aed7caa4b87e78be2b6b1b86d02d3 127.0.0.1:6480
slots:5461-10922 (5462 slots) master
M: e71eae6b79e529997fb7716da6d20be68e76830d 127.0.0.1:6481
slots:10923-16383 (5461 slots) master
S: cd2f4e96f575b7b84d48144e832bf7cd6fcd8fc1 127.0.0.1:6482
replicates 78581cf153d821c734c238d00f4de264fc95072e
S: 89e54b0f1fd33adf5ef624104e7d17bb93785b3d 127.0.0.1:6483
replicates d0d4a89f567aed7caa4b87e78be2b6b1b86d02d3
S: b1ad93513254bb6bcb3cc6166afc7d4a89458802 127.0.0.1:6484
replicates e71eae6b79e529997fb7716da6d20be68e76830d
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 127.0.0.1:6479)
1 additional replica(s)
slots: (0 slots) slave
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
4,叢集完整性檢查
<code>redis-trib.rb check 127.0.0.1:6479</code>
當看到時代表叢集所有的槽位都已經配置設定出去。
本文轉自 emma_cql 51CTO部落格,原文連結:http://blog.51cto.com/chenql/1947291