安裝redis3.2叢集出現的一些問題及解決方法
安裝系統是在centOS上面時行的。有不足之處還記指正。
系統版本centOS6.5.
redis叢集配置如下:
節點1
=============================================
主192.168.135.128 :1000
/usr/local/redis-cluster-test/cluster1/master
從 192.168.135.128 :1001
/usr/local/redis-cluster-test/cluster1/slave
節點1主配置
pidfile /usr/local/redis-cluster-test/cluster1/master/redis_1000.pid
logfile /usr/local/redis-cluster-test/cluster1/master/redist-1000.log
port 1000
bind 192.168.135.128
appendonly yes
daemonize yes
dir /usr/local/redis-cluster-test/cluster1/master/
cluster-enabled yes
cluster-config-file nodes-1000.conf
節點1從配置
pidfile /usr/local/redis-cluster-test/cluster1/slave/redis_1001.pid
logfile /usr/local/redis-cluster-test/cluster1/salve/redist-1001.log
port 1001
bind 192.168.135.128
appendonly yes
daemonize yes
dir /usr/local/redis-cluster-test/cluster1/slave/
cluster-enabled yes
cluster-config-file nodes-1001.conf
節點2
=============================================
節點2主192.168.135.128 :2000
/usr/local/redis-cluster-test/cluster2/master
/usr/local/redis-cluster-test/cluster2/slave
pidfile /usr/local/redis-cluster-test/cluster2/slave/redis_2001.pid
logfile /usr/local/redis-cluster-test/cluster2/salve/redist-2001.log
port 2001
bind 192.168.135.128
appendonly yes
daemonize yes
cluster-enabled yes
dir /usr/local/redis-cluster-test/cluster1/slave/
cluster-config-file nodes-2000.conf
節點2從 192.168.135.128 :2001
/usr/local/redis-cluster-test/cluster2/slave
pidfile /usr/local/redis-cluster-test/cluster2/slave/redis_2001.pid
logfile /usr/local/redis-cluster-test/cluster2/salve/redist-2001.log
port 2001
bind 192.168.135.128
appendonly yes
daemonize yes
dir /usr/local/redis-cluster-test/cluster1/slave/
cluster-enabled yes
cluster-config-file nodes-2001.conf
節點3
=============================================
節點3主192.168.135.128 :3000
/usr/local/redis-cluster-test/cluster3/master
/usr/local/redis-cluster-test/cluster2/slave
pidfile /usr/local/redis-cluster-test/cluster3/slave/redis_3000.pid
logfile /usr/local/redis-cluster-test/cluster3/salve/redist-3000.log
port 3000
bind 192.168.135.128
appendonly yes
daemonize yes
cluster-enabled yes
dir /usr/local/redis-cluster-test/cluster1/slave/
cluster-config-file nodes-3000.conf
節點3從 192.168.135.128 :3001
redis.conf /usr/local/redis-cluster-test/cluster3/slave
pidfile /usr/local/redis-cluster-test/cluster3/slave/redis_3001.pid
logfile /usr/local/redis-cluster-test/cluster3/salve/redist-3001.log
port 3001
bind 192.168.135.128
appendonly yes
daemonize yes
dir /usr/local/redis-cluster-test/cluster1/slave/
cluster-enabled yes
cluster-config-file nodes-3001.conf
以上配置在從中設定少了一個cluster-node-timeout 15000這個配置可以自行設定。
下面就是主題了,搞下叢集。
也有一些野路子配置叢集的,在網上看到,試過了,也可以用,但是在刪除和增加節點時不是那麼靈活。官方文件上推薦使用ruby,而且redis3.2裡面內建了redis-trib.rb檔案,所以在centOS上面安裝ruby就可以了。可是,我是糾結了一下午才搞定了ruby的執行環境,可能是我安裝的centos太純淨了,有些依賴包沒有找到的問題。
一些問題如下:
問題1:
執行命令:./redis-trib.rb
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- redis (LoadError)
from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from ./redis-trib.rb:25:in `<main>'
解決方法:下載安裝rubygem 進入解壓包中.configure make && make install
此時就可以執行gem intall redis 命令,來安裝ruby執行redis的相關依賴。
問題2:
gem install redis 命令出現的問題
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass手動安裝opensll,此問題解決。
問題3:
接著執行命令:gem install redis
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
手動安裝zlib包解決(這個可能是系統太純淨,沒有些包的問題)。安裝過程不多說,手動下載安裝包安裝。
問題3:
接著執行命令:gem install redis
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
網上搜索到的解決方法:gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
還是問題以舊。
解決方法:
gem sources -a https://gems.ruby-china.org/ 把https地址改成 gem sources -a http://gems.ruby-china.org/
執行成功,檢視gem source -l 映象地址修改成功。
再次執行:gem install redis成功。
通過命令檢視:
gem list 已經成功安裝了redis的依賴。
執行redis 目錄下的ruby-trib.rb
命令格式如下:
./redis-trib.rb create --replicas 1 192.168.135.128:1000 192.168.135.128:2000
192.168.135.128:3000 192.168.135.128:1001 192.168.135.128:2001 192.168.135.128:3001
注意:--replicas 1 代表每個master有一個slave,還有就是前面三個是主服務,後面三個從服務地址,叢集配置成功。
如圖所示:
以上是在個人配置叢集的時候碰到的問題。
java 程式測試叢集:
JedisPoolConfig poolConfig=new JedisPoolConfig(); Set<HostAndPort> nodeList=new HashSet<HostAndPort>(); nodeList.add(new HostAndPort(host,1000)); nodeList.add(new HostAndPort(host,1001)); nodeList.add(new HostAndPort(host,2000)); nodeList.add(new HostAndPort(host,2001)); nodeList.add(new HostAndPort(host,3000)); nodeList.add(new HostAndPort(host,3001)); JedisCluster cluster=new JedisCluster(nodeList,poolConfig); String name=cluster.get("name"); System.out.println("args = [" + name + "]");程式執行效果如下: