一、安裝Ruby
cd /home/redis/software #把軟件下載到/home/redis/software目錄下,將應用安裝到/home/redis目錄下。 wget -r -np -nd --accept=gz --no-check-certificate https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz --http-user=username --http-password=password tar -zxvf ruby-2.2.2.tar.gz cd ruby-2.2.2 ./configure --profix=/home/redis/ruby make make install vim /etc/profile #將ruby運行bin目錄加到PATH裏。在/etc/profile里加入如下內容: export PATH=/home/redis/ruby/bin:$PATH source /etc/profile #由於國內網絡原因(你懂的),導致 rubygems.org 存放在 Amazon S3 上面的資源文件間歇性連接失敗。所以下面要將https://rubygems.org/改爲https://ruby.taobao.org/ gem sources --remove https://rubygems.org/ #移除https://rubygems.org/ gem sources -a https://ruby.taobao.org/ #增加https://ruby.taobao.org/ gem sources -l #請確保只有 ruby.taobao.org gem install redis #安裝Ruby的redis接口
二、安裝Redis
cd /home/redis/software #把軟件下載到/home/redis/software目錄下,將應用安裝到/home/redis目錄下。 wget http://download.redis.io/releases/redis-3.0.3.tar.gz tar -zxvf redis-3.0.3.tar.gz cd redis-3.0.3 make
三、配置集羣
cd /home/redis #把軟件下載到/home/redis/software目錄下,將應用安裝到/home/redis目錄下。 mkdir cluster #創建cluster存放集羣軟件 cd cluser mkdir 7000 7001 7002 7003 7004 7005 #創建6個目錄,裏面分別部署一個redis,三個master,三個slave cp /home/redis/software/redis.conf ./ #複製一份配置文件 cp /home/redis/software/src/redis-trib.rb ./ #複製集羣啓動腳本 cp /home/redis/software/src/redis-server ./ #複製redis server cp /home/redis/software/src/redis-cli ./ #複製redis client vim redis.conf #修改如下配置 daemonize yes port 7000 #把redis.conf分別複製到6個目錄後,此處端口值修改爲對應的目錄名 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes #將redis.conf分別複製到6個目錄下並修改port的值爲目錄名 cp redis.conf 7000 cp redis.conf 7001 cp redis.conf 7002 cp redis.conf 7003 cp redis.conf 7004 cp redis.conf 7005 #分別啓動6個redis cd 7000 ../redis-server ./redis.conf cd ../7001 ../redis-server ./redis.conf cd ../7002 ../redis-server ./redis.conf cd ../7003 ../redis-server ./redis.conf cd ../7004 ../redis-server ./redis.conf cd ../7005 ../redis-server ./redis.conf #創建redis集羣 ./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 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 Adding replica 127.0.0.1:7003 to 127.0.0.1:7000 Adding replica 127.0.0.1:7004 to 127.0.0.1:7001 Adding replica 127.0.0.1:7005 to 127.0.0.1:7002 M: 20aa266add02caae98dc0446259cb5f2e37336f1 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: c258baee22bee15698be3c85908a2103c36eb9ce 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 33e1731b173eb8c47d268c5c681887580e517ef1 127.0.0.1:7002 slots:10923-16383 (5461 slots) master S: f74bdac74b19919e9975dbd84db47fcb887f34d4 127.0.0.1:7003 replicates 20aa266add02caae98dc0446259cb5f2e37336f1 S: 32f7aa6f13ca0d50214b5fcafa50470bbe35edad 127.0.0.1:7004 replicates c258baee22bee15698be3c85908a2103c36eb9ce S: ed604701d8c7b85970dbced11541d339614e8338 127.0.0.1:7005 replicates 33e1731b173eb8c47d268c5c681887580e517ef1 Can I set the above configuration? (type 'yes' to accept): yes #輸入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:7000) M: 20aa266add02caae98dc0446259cb5f2e37336f1 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: c258baee22bee15698be3c85908a2103c36eb9ce 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 33e1731b173eb8c47d268c5c681887580e517ef1 127.0.0.1:7002 slots:10923-16383 (5461 slots) master M: f74bdac74b19919e9975dbd84db47fcb887f34d4 127.0.0.1:7003 slots: (0 slots) master replicates 20aa266add02caae98dc0446259cb5f2e37336f1 M: 32f7aa6f13ca0d50214b5fcafa50470bbe35edad 127.0.0.1:7004 slots: (0 slots) master replicates c258baee22bee15698be3c85908a2103c36eb9ce M: ed604701d8c7b85970dbced11541d339614e8338 127.0.0.1:7005 slots: (0 slots) master replicates 33e1731b173eb8c47d268c5c681887580e517ef1 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.