redis cluster 模式安裝部署詳情

環境:

兩臺centos 6.5 服務器

IP:172.16.57.96

IP:172.16.57.97


步驟:

1、環境安裝 

yum -y install make automake gcc gcc-c++ libstdc++-devel tcl ruby rubygems zlib-devel openssl-devel curl
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p

2、下載

cd /usr/local/src
wget http://download.redis.io/releases/redis-3.0.5.tar.gz

3 步驟

cd /usr/local/src
tar zxvf redis-3.0.5.tar.gz
cd redis-3.0.5
make MALLOC=libc
make install PREFIX=/usr/redis-cluster/

4、配置端口

cd /usr/redis-cluster/
cp -r  bin 7000
cp -r  bin 7001
cp -r  bin 7002
cp -r /usr/local/src/redis-3.0.5/redis.conf 7000/
cp -r /usr/local/src/redis-3.0.5/redis.conf 7001/
cp -r /usr/local/src/redis-3.0.5/redis.conf 7002/

4-1、增加環境變量vim /etc/profile

export PATH=/usr/redis-cluster/bin:$PATH
source /etc/profile

5、配置文件修改  vim 7000/redis.conf (其他兩個目錄均需要修改)

daemonize yes
pidfile /var/run/redis_7000.pid
port 7000
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000


6、啓動腳本

#!/bin/bash
allpath="/usr/redis-cluster"
cd $allpath/7000
./redis-server redis.conf
cd $allpath/7001
./redis-server redis.conf
cd $allpath/7002
./redis-server redis.conf


7、啓動服務

chmod 777 redis-start-all.sh
sh redis-start-all.sh


8、檢查

ps -ef |grep redis
netstat -nuplt

在另外節點服務器上分別執行以上操作(1、2、3執行,4、5、6、7可以從配置好的這臺拷貝更新)。

確保以上節點中redis服務已經正常啓動。


下面開始集羣操作

9、集羣操作

9.1  執行命令:

cd /usr/redis-cluster/
gem install redis-3.0.5.gem
gem install redis --version 3.0.5 #時間有點久,耐心等待

注意:gem install redis --version 3.0.0 失敗的話,需要修改一下gem的源

gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/


手工下載並安裝:

wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
gem install -l ./redis-3.2.1.gem
cp -r /usr/local/src/redis-3.0.5/src/redis-trib.rb ./


執行的集羣操作命令:

./redis-trib.rb create --replicas 1 172.16.57.96:7000 172.16.57.96:7001 172.16.57.96:7002 172.16.57.97:7000 172.16.57.97:7001 172.16.57.97:7002
#--replicas 1 此處1爲每個主節點後面都有一個從節點
#--replicas 0 此處0爲沒有從節點

Using 3 masters:

172.16.57.97:7000

172.16.57.96:7000

172.16.57.97:7001

以上三個作爲集羣主節點


9.2 根據提示,在 Can I set the above configuration? (type 'yes' to accept): yes (此處輸入yes 回車)


[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered. 


提示以上信息則完成。



10、 集羣驗證

執行命令:

cd /usr/redis-cluster/bin 

./redis-cli -c -p 7001

127.0.0.1:7001> set name andy

-> Redirected to slot [5798] located at 172.16.57.96:7000

OK

172.16.57.96:7000> get name

"andy"


登錄另外一臺或者鏈接不同端口:

cd /usr/redis-cluster/bin 

./redis-cli -c -h 172.16.57.97 -p 7002


172.16.57.97:7002> get name

-> Redirected to slot [5798] located at 172.16.57.96:7000

"andy"

172.16.57.96:7000> 


返回 name 值爲 andy 即可


命令 

redis-cli -c -p 7000

> cluster info

> cluster nodes


故障問題


1 報錯 Connecting to node 172.16.57.97:7000: OK

[ERR] Node 172.16.57.97:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.


解決步驟:

killall  redis-server
find ./700* -type f -name "appendonly*" -o -name "nodes*" -o -name "dump.rdb" 
find ./700* -type f -name "appendonly*" -o -name "nodes*" -o -name "dump.rdb"  |xargs rm -rf

然後重新執行集羣命令


2 Redis的Cluster集羣的時候,在執行gem install redis時,提示如下錯誤:

gem install redis
    ERROR:  Error installing redis:
     redis requires Ruby version >= 2.2.2.

yum庫中ruby的版本支持到 2.0.0,可gem 安裝redis需要最低是2.2.2,採用rvm來更新ruby:

1、安裝RVM(具體命令可以查看官網,Ruby官網地址 和 Ruby官網安裝教程):

複製代碼

//具體RVM安裝命令地址:http://rvm.io/

[root@linux ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E37D2BAF1CF37B13E2069D6956105BD0E739499BDB 
[root@linux ~]# curl -sSL https://get.rvm.io | bash -s stable
[root@linux ~]# find / -name rvm -print

複製代碼

/usr/local/rvm
/usr/local/rvm/src/rvm
/usr/local/rvm/src/rvm/bin/rvm
/usr/local/rvm/src/rvm/lib/rvm
/usr/local/rvm/src/rvm/scripts/rvm
/usr/local/rvm/bin/rvm
/usr/local/rvm/lib/rvm
/usr/local/rvm/scripts/rvm
[root@linux ~]# source /usr/local/rvm/scripts/rvm


2、查看rvm庫中已知的ruby版本:

[root@linux ~]# rvm list known
MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head
….


3、安裝一個ruby版本:

[root@linux ~]# rvm install 2.4.1
    Searching for binary rubies, this might take some time.
    Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.4.1.tar.bz2
    Checking requirements for centos.
    Requirements installation successful.
    ruby-2.4.1 - #configure
    ruby-2.4.1 - #download
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 14.1M  100 14.1M    0     0    97k      0  0:02:27  0:02:27 --:--:--  159k
    No checksum for downloaded archive, recording checksum in user configuration.
    ruby-2.4.1 - #validate archive
    ruby-2.4.1 - #extract
    ruby-2.4.1 - #validate binary
    ruby-2.4.1 - #setup
    ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1@global
    ruby-2.4.1 - #importing gemset /usr/local/rvm/gemsets/global.gems..............................
    ruby-2.4.1 - #generating global wrappers........
    ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1
    ruby-2.4.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
    ruby-2.4.1 - #generating default wrappers........


4、使用一個ruby版本:

  [root@linux ~]# rvm use 2.4.1

       Using /usr/local/rvm/gems/ruby-2.4.1


5、設置默認版本:(設置ruby2.4.1爲默認的ruby,因爲還安裝有1.8.3)

  [root@linux ~]# rvm use 2.4.1 --default

        Using /usr/local/rvm/gems/ruby-2.4.1


6、卸載一個已知版本:

  [root@linux ~]# rvm remove 2.3.4


7、查看ruby版本:

  [root@linux ~]# ruby --version

      ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

8、安裝redis:

  [root@linux ~]# gem install redis

    Fetching: redis-4.0.1.gem (100%)

    Successfully installed redis-4.0.1

    Parsing documentation for redis-4.0.1

    Installing ri documentation for redis-4.0.1

    Done installing documentation for redis after 3 seconds

    1 gem installed


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章