注意点:
1.redis集群至少需要6个节点。2.redis集群至少部署在3台服务器上。3.redis的版本需要在3.0以上。4.需要ruby的支持。
步骤:
1.安装依赖环境:
yum install gcc-c++
2.下载ruby-2.4.6,编译安装
https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.6.tar.gz
http://www.ruby-lang.org/zh_cn/downloads/
tar zxf ruby-2.4.6.tar.gz
cd ruby-2.4.6
autoconf
./configure --prefix=/data/tools/ruby
##sed -i 's/$(top_srcdir)/..\/../g' Makefile
make && make install
echo "export PATH=$PATH:/data/tools/ruby/bin"
3.下载redis-3.0.7,编译安装
git clone https://github.com/antirez/redis.git
http://www.ruby-lang.org/en/downloads/
make
make PREFIX=/data/server/redis install
echo 'export PATH=$PATH:/data/server/redis/bin' >> /etc/profile
source /etc/profile
安装redis-gem
https://rubygems.org/gems/redis/versions/3.3.2
gem install redis-3.3.2.gem
报错:
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
cd ruby_source/ext/zlib/
ruby extconf.rb
sed -i 's/$(top_srcdir)/..\/../g' Makefile
make && make install
报错:
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources
cd ruby_source/ext/openssl/
ruby extconf.rb
sed -i 's/$(top_srcdir)/..\/../g' Makefile
make && make install
gem install redis-3.3.2.gem
创建多个redis服务,最少6个,修改配置文件,在单机配置文件中添加下面参数
cluster-enabled yes
cluster-config-file /data/server/redis-8002/nodes_8002.conf
cluster-node-timeout 5000
注意:cluster-config-file 只需要指定即可,这个配置文件是启动redis后自动创建的,里面保存了整个集群的node节点的信息,不需要手动创建和编辑。