Ubuntu 15.10下Redis叢集部署文檔

來源:互聯網
上載者:User

Ubuntu 15.10下Redis叢集部署文檔

Linux版本:Ubuntu15.10系統。

(要讓叢集正常工作至少需要3個主節點,在這裡我們要建立6個redis節點,其中三個為主節點,三個為從節點,對應的redis節點的ip和連接埠對應關係如下)
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
127.0.0.1:7004
127.0.0.1:7005


1:下載redis。官網下載3.0.0版本,之前2.幾的版本不支援叢集模式
:http://download.redis.io/releases/redis-3.0.7.tar.gz
2:上傳伺服器,解壓,編譯

tar -zxvf redis-3.0.7.tar.gzmv redis-3.0.7 /usr/local/redis3.0cd /usr/local/redis3.0make

之後就產生了 redis-server redis-client 等檔案在 src裡。

3:建立叢集需要的目錄

mkdir -p /usr/local/clustercd /usr/local/clustermkdir 7000mkdir 7001mkdir 7002mkdir 7003mkdir 7004mkdir 7005 

4:修改設定檔redis.conf
cp /usr/local/redis3.0/redis.conf /usr/local/cluster
vi redis.conf
##修改設定檔中的下面選項

pidfile /var/run/redis.7000.pid #個人化port 7000 #個人化daemonize yescluster-enabled yescluster-config-file nodes.7000.conf #個人化cluster-node-timeout 5000appendonly yesappendfilename "appendonly.7000.aof" #個人化

##修改完redis.conf設定檔中的這些配置項之後把這個設定檔分別拷貝到7000/7001/7002/7003/7004/7005目錄下面

cp /usr/local/cluster/redis.conf /usr/local/cluster/7000cp /usr/local/cluster/redis.conf /usr/local/cluster/7001cp /usr/local/cluster/redis.conf /usr/local/cluster/7002cp /usr/local/cluster/redis.conf /usr/local/cluster/7003cp /usr/local/cluster/redis.conf /usr/local/cluster/7004cp /usr/local/cluster/redis.conf /usr/local/cluster/7005

##注意:拷貝完成之後要修改7001/7002/7003/7004/7005目錄下面redis.conf檔案中 標註個人化的 參數,分別改為對應的檔案夾的名稱

5:分別啟動這6個redis執行個體
vi /usr/local/cluster/redis-start.sh
加入以下內容

#!/bin/sh/usr/local/redis3.0/src/redis-server /usr/local/cluster/7000/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7001/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7002/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7003/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7004/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7005/redis.conf &

然後

chmod +x /usr/local/cluster/redis-start/usr/local/cluster/redis-start

##啟動之後使用命令查看redis的啟動情況ps -ef|grep redis


6:執行redis的建立叢集命令建立叢集
安裝ruby ,因為./redis-trib.rb 是執行的ruby的指令碼,需要ruby的環境
sudo apt-get install ruby

為了執行 redis-trib.rb 需要安裝 gem redis sudo gem install redis 可能會有長城防火牆的問題
可以去https://rubygems.org/gems/redis/versions/3.2.2 下載最新版本。
然後用命令 sudo gem install redis-3.2.2.gem

cd /usr/local/redis3.0/src./redis-trib.rb  create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

有下面輸出表示成功了。

>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002Adding replica 127.0.0.1:7003 to 127.0.0.1:7000Adding replica 127.0.0.1:7004 to 127.0.0.1:7001Adding replica 127.0.0.1:7005 to 127.0.0.1:7002M: 1cdc6971ddbcf64427a9499e19b048afa55aff08 127.0.0.1:7000   slots:0-5460 (5461 slots) masterM: a355b2ccb1fdf413652a14cec722076af958a079 127.0.0.1:7001   slots:5461-10922 (5462 slots) masterM: 0bc286b514d36e7195142ff0d55a87542048b5a9 127.0.0.1:7002   slots:10923-16383 (5461 slots) masterS: a3b7c85fe957917bd383b181de3f1a3f31df8a05 127.0.0.1:7003   replicates 1cdc6971ddbcf64427a9499e19b048afa55aff08S: 9f0f4045497a72b64783fd9c2387f38b7e3bda6c 127.0.0.1:7004   replicates a355b2ccb1fdf413652a14cec722076af958a079S: f4b371c4e1d0fddfbe1552e540ddd36a5a00200b 127.0.0.1:7005   replicates 0bc286b514d36e7195142ff0d55a87542048b5a9Can 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 clusterWaiting for the cluster to join...>>> Performing Cluster Check (using node 127.0.0.1:7000)M: 1cdc6971ddbcf64427a9499e19b048afa55aff08 127.0.0.1:7000   slots:0-5460 (5461 slots) masterM: a355b2ccb1fdf413652a14cec722076af958a079 127.0.0.1:7001   slots:5461-10922 (5462 slots) masterM: 0bc286b514d36e7195142ff0d55a87542048b5a9 127.0.0.1:7002   slots:10923-16383 (5461 slots) masterM: a3b7c85fe957917bd383b181de3f1a3f31df8a05 127.0.0.1:7003   slots: (0 slots) master   replicates 1cdc6971ddbcf64427a9499e19b048afa55aff08M: 9f0f4045497a72b64783fd9c2387f38b7e3bda6c 127.0.0.1:7004   slots: (0 slots) master   replicates a355b2ccb1fdf413652a14cec722076af958a079M: f4b371c4e1d0fddfbe1552e540ddd36a5a00200b 127.0.0.1:7005   slots: (0 slots) master   replicates 0bc286b514d36e7195142ff0d55a87542048b5a9[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.

這樣redis-cluster叢集就啟動了

7、查看叢集目前狀況:

$ redis-cli -c -p 7000127.0.0.1:7000> cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:0cluster_stats_messages_sent:8770cluster_stats_messages_received:8770

8、測試存值取值:每一次操作過後可能就跳到別的裡面了。就是那個Redirected to slot ……

127.0.0.1:7002> set foo bar
OK
127.0.0.1:7000> set hello world
OK
127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
127.0.0.1:7002> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"
127.0.0.1:7000> get name
-> Redirected to slot [5798] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001>
127.0.0.1:7002> get name
-> Redirected to slot [5798] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001>

下面關於Redis的文章您也可能喜歡,不妨參考下:

Ubuntu 14.04下Redis安裝及簡單測試

Redis主從複製基本配置

Redis叢集明細文檔

Ubuntu 12.10下安裝Redis(圖文詳解)+ Jedis串連Redis

Redis系列-安裝部署維護篇

CentOS 6.3安裝Redis

Redis安裝部署學習筆記

Redis設定檔redis.conf 詳解

Redis 的詳細介紹:請點這裡
Redis 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.