安装redis集群

  1. 安装zlib
    yum install -y zlib

  2. 安装ruby
    yum install -y ruby

  3. 安装ruby-redis
    下载 ruby-redis3.3.5
    gem install redis-3.3.5.gem

  4. 安装redis
    下载 redis-4.0.6

> tar xvf redis-4.0.6.tar.gz
> cd redis-4.0.6
> make
> make test
> mkdir -p /redis/redis-4.0.6/cluster/8001
> cp /redis/redis-4.0.6/redis.conf /redis/redis-4.0.6/cluster/8001
> vi redis.conf

一般参数

bind 192.168.0.47
port 8001
daemonize yes #以守护进程运行
pidfile /redis/redis-4.0.6/cluster/8001/redis_8001.pid
logfile /redis/redis-4.0.6/cluster/8001/redis_8001.log
dir /redis/redis-4.0.6/cluster/8001/
masterauth redis_ #集群密码
requirepass redis_ #登陆密码
maxclients 2048

集群参数

cluster-enabled yes
cluster-config-file nodes-8001.conf
cluster-node-timeout 15000
appendonly yes

  1. 目录加入PATH
    export PATH=./:/redis/redis-4.0.6/src/:${PATH}

  2. 所有节点启动redis
    redis-server ./redis.conf

  3. 创建集群

> redis-trib.rb create --replicas 1 192.168.0.47:8001 192.168.0.48:8001 192.168.0.49:8001 192.168.0.50:8001 192.168.0.51:8001 192.168.0.52:8001
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.0.47:8001
192.168.0.48:8001
192.168.0.49:8001
Adding replica 192.168.0.50:8001 to 192.168.0.47:8001
Adding replica 192.168.0.51:8001 to 192.168.0.48:8001
Adding replica 192.168.0.52:8001 to 192.168.0.49:8001
  1. 问题
> redis-trib.rb info 192.168.0.47:8001
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /redis/redis-4.0.6/src/redis-trib.rb:25:in `
' > ruby -v ruby 2.0.0p648 (2015-12-16) [x86_64-linux] ruby缺少redis库 https://rubygems.org/gems/redis/versions/3.3.5 > gem install redis-3.3.5.gem 增加reids密码后无法连接 > redis-trib.rb create --replicas 1 192.168.0.47:8001 192.168.0.48:8001 192.168.0.49:8001 192.168.0.50:8001 192.168.0.51:8001 192.168.0.52:8001 >>> Creating cluster [ERR] Sorry, can't connect to node 192.168.0.47:8001 client.rb路径可以通过find命令查找:find / -name 'client.rb' 修改client.rb文件 :password => "passwd123"

你可能感兴趣的:(redis,redis)