操作系统: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