版本选择3.2.10
wget http://download.redis.io/releases/redis-3.2.10.tar.gz
tar -zxvf redis-3.2.10.tar.gz
cd redis-3.2.10.tar.gz
make
# make install 默认安装到/usr/local/bin下,建议使用下方命令指定安装路径并安装
make PREFIX=/usr/local/redis install
1、zlib-devel
ruby的依赖包,直接 yum -y install zlib-devel
2、ruby
ruby版本要求在2.2.0以上,但是yum仓库只有2.0.版本的ruby,无法使用,建议手动下载安装
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
tar xvf ruby-2.5.1.tar.gz
cd ruby-2.5.1/
./configure -prefix=/usr/local/ruby
make
make install
cd /usr/local/ruby/
cp bin/ruby /usr/local/bin
cp bin/gem /usr/local/bin
3、查看是否成功
ruby -v、gem -v
4、安装ruby环境下的redis类库,后面启动redis-trib.rb会依赖于此
wget http://rubygems.org/downloads/redis-3.2.0.gem
gem install -l redis-3.2.0.gem
【注:】文件路径要以自己情况为准
1、创建配置
cd /usr/local/redis/
cat redis.conf | grep -v "#" | grep -v "^$" > redis-6379.conf
2、配置
vim redis-6379.conf
# 以下是保留内容
port 6379
daemonize no
pidfile /var/run/redis_6379.pid
logfile ""
save 100 1
rdbcompression yes
rdbchecksum yes
dbfilename dump-6379.rdb
dir ./
appendonly yes
appendfilename "appendonly-6379.aof"
appendfsync everysec
# cluster config
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 10000
# end
3、集群配置
# 也可以写脚本,这里演示直接写
# 复制成别名文件,原内容中的6379别忘记替换掉
sed "s/6379/6380/g" redis-6379.conf > redis-6380.conf
sed "s/6379/6381/g" redis-6379.conf > redis-6381.conf
sed "s/6379/6382/g" redis-6379.conf > redis-6382.conf
sed "s/6379/6383/g" redis-6379.conf > redis-6383.conf
sed "s/6379/6384/g" redis-6379.conf > redis-6384.conf
1、启动六个节点
redis-server /usr/local/redis/redis-6379.conf
redis-server /usr/local/redis/redis-6380.conf
redis-server /usr/local/redis/redis-6381.conf
redis-server /usr/local/redis/redis-6382.conf
redis-server /usr/local/redis/redis-6383.conf
redis-server /usr/local/redis/redis-6384.conf
2、到redis源码包下找到redis-trib.rb
cd /usr/local/redis-3.2.10/src
./redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
有下面信息就成功了!!!
1、直接在只有redis的环境下启动集群
异常内容:/usr/bin/env:ruby
异常原因:无ruby环境运行集群管理工具
解决方法:(87条消息) 解决 /usr/bin/env: ruby_一纸情书ベ的博客-CSDN博客
2、有ruby环境,直接启动集群
异常内容:
2: from ./redis-trib.rb:25:in `'
1: from /usr/local/ruby/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/local/ruby/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- redis (LoadError)
异常原因:没有安装redis-trib.rb的依赖库
解决方法: (87条消息) /usr/local/ruby/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such_JAVA_猿-CSDN博客
3、gem install redis
异常内容:
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
异常原因:openssl未正常下载、ruby安装时未提前安装zlib-devel依赖
解决方法:
(87条消息) gem install redis报错解决办法_feinifi的博客-CSDN博客_gem install redis报错(87条消息) gem install redis报错解决办法_feinifi的博客-CSDN博客_gem install redis报错
【注:】
wget http://rubygems.org/downloads/redis-3.2.0.gem
gem install -l redis-3.2.0.gem(注意文件路径,以及保证zlib-devel依赖成功安装)
4、启动集群报错
异常内容:
[ERR] Node is not empty. Either the node already knows other nodes
解决方法:
第一步:删除 appendonly.aof 和 dump.rdb;
第二部(第一步之后如果还不行再做):删除所有节点的cluster-config-file,也就是节点配置文件,自动生成的,路劲也配置在conf文件中。
示例:
将所有节点shutdown,为什么呢,不然你删除完A节点的AOF和RDB文件后,没过多久他自己又重新生成,(免去了 在redis-cli中执行 flushdb 命令),下面是代码示例:
关闭节点
redis-cli -h 192.168.43.155 -p 7001 shutdown
进入到持久化文件所在目录,并将其删除
(如果这个目录下还有其他文件就把 * 换成你要删除的文件的文件名)
[root@esshop-cach02 init.d]# cd 目标目录
[root@esshop-cach02 7003]# rm -rf *
上述无效再找到并删除cluster-config-file