1. 程式人生 > >Redis4.0.9叢集配置

Redis4.0.9叢集配置

作業系統:CentOS-6.5-x86_64-bin-DVD1.iso

Redis:4.0.9

在一臺虛擬機器上驗證叢集配置,通過不同的埠,啟動不同的redis例項

1、使用原始碼安裝redis

把redis的壓縮包放到cd /usr/soft/ 路徑下

tar zxvf redis-4.0.9.tar.gz

cd redis-4.0.9

make

進入到src下進行安裝 make instal

cd src/ 執行  make  install

2、叢集需要至少6個節點,拷貝出6份配置檔案

#建立配置檔案路徑

mkdir -p /usr/RedisCluster/

#在RedisCluster路徑下建立7個資料夾(7001---7006)並將redis-server、redis-cli、redis.conf三個檔案拷貝到(7001--7006)每個資料夾下

cp redis-server redis-cli redis.conf /usr/RedisCluster/7001--7006下

3、進入(7001--7006)資料夾下修改redis.conf檔案,修改一下配置即可

port 7001

bind 192.168.189.128

daemonize yes

cluster-enabled yes

cluster-config-file nodes-6379.conf

cluster-node-timeout 15000

pidfile /var/run/redis_6379.pid

4、寫個批處理 vim start-all.sh

cd 7001
  ./redis-server redis.conf
cd ..
cd 7002
  ./redis-server redis.conf
cd ..
cd 7003
  ./redis-server redis.conf
cd ..
cd 7004
  ./redis-server redis.conf
cd ..
cd 7005
  ./redis-server redis.conf
cd ..
cd 7006
  ./redis-server redis.conf
cd ..

並執行 chmod +x start-all.sh  命令進行授權

5、啟動例項之前在根路徑下配置多種環境

yum install gcc-c++

6、啟動叢集例項,

./start-all.sh

7、配置叢集

/usr/RedisCluster/redis-trib.rb create --replicas 1 192.168.189.128:7001 192.168.189.128:7002 192.168.189.128:7003 192.168.189.128:7004 192.168.189.128:7005 192.168.189.128:7006

執行之後,報錯“/usr/bin/env: ruby: No such file or directory”,需要安裝ruby

 yum install ruby

繼續執行上個命令,又報錯“./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
        from ./redis-trib.rb:24”,需要安裝rubygems

            yum install ruby
            yum install rubygems

繼續執行上個命令,又報錯“/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from ./redis-trib.rb:25”,需要通過gem安裝redis

gem install redis

執行之後報錯“ERROR:  Error installing redis:
        redis requires Ruby version >= 2.2.2.”,需要升級ruby

8、升級ruby

1)確認rvm有沒有安裝

rvm -v

如果已經安裝,就跳過第2步

2)安裝rvm

   curl -L get.rvm.io | bash -s stable

如果沒有curl命令,就執行yum intall  curl進行安裝

執行結果如下

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24090  100 24090    0     0  21983      0  0:00:01  0:00:01 --:--:-- 21983
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: Signature made Mon 11 Sep 2017 04:59:21 AM CST using RSA key ID BF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).


GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:


    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3


or if it fails:


    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -


the key can be compared with:


    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis


NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.

按照提示,獲取一下public key

 gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

再次執行安裝curl -L get.rvm.io | bash -s stable,就可以了。

3)source /usr/local/rvm/scripts/rvm

4)檢視可以安裝的ruby版本

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]

5)安裝2.4.1版本

rvm install 2.4.1

6)確認ruby版本

ruby -v

9、再次安裝redis

gem install redis

10、啟動服務的情況下再次執行叢集配置

/usr/RedisCluster/redis-trib.rb create --replicas 1 192.168.189.128:7001 192.168.189.128:7002 192.168.189.128:7003 192.168.189.128:7004 192.168.189.128:7005 192.168.189.128:7006

11、驗證叢集

/usr/RedisCluster/7001/redis-cli -h 192.168.79.130 -p 7001 -c
-c:代表連線的是redis叢集

192.168.189.128:7001> set name zhangsan
-> Redirected to slot [5798] located at 192.168.189.128:7002
OK
192.168.189.128:7002>get name

zhangsan

登入的時候,必須加上-c引數,才會自動重定向到另外一個例項

./redis-cli -c -p 7000

再次執行,又出現(error) NOAUTH Authentication required.

登入的時候,必須加上密碼引數-a,這樣就不用要求輸入密碼了

以上問題只供參考!!

參考文章:

https://blog.csdn.net/gw85047034/article/details/78689885

https://blog.csdn.net/sdoyuxuan/article/details/79081873

https://blog.csdn.net/qq_14945847/article/details/77986900

https://www.cnblogs.com/subendong/p/7417601.html