环境:Vmware+3台CentOS7.0虚拟机
1.wget http://download.redis.io/releases/redis-4.0.10.tar.gz
2.tar xzf redis-4.0.10.tar.gz
3.yum -y install gcc gcc-c++ libstdc++-devel
4.make CFLAGS="-march=x86-64"
5.cd redis-4.0.10
6.make
7.make install
8.redis-server 如果启动成功,则说明安装成功
redis集群要求最少6台机器,本文采用3台Linux主机,每台主机部署两个redis server,下面以一台主机为例讲解
1.创建两个目录node1和node2
mkdir node1 node2
2.将/usr/local/bin下的文件分别拷贝到node1和node2(该步骤多余,可省略)
cp -r /usr/local/bin node1
cp -r /usr/local/bin node2
3.将redis安装目录下的redis.conf文件分别复制一份到node1和node2中
cp redis.conf node1
cp redis.conf node2
4.配置redis.conf文件
注意:同一台主机的两个server配置不同的端口号,比如:node1-6379 node2-6380
# 绑定主机IP
69 bind 10.193.50.15
# 设置可从其他主机的客户端登陆
88 protected-mode no
# 绑定主机端口
92 port 6380
# 设置server在后台运行
136 daemonize yes
# 设置pid文件名
158 pidfile /var/run/redis_6379.pid
# 设置日志文件名
171 logfile "node1.log"
# 集群
814 cluster-enabled yes
828 cluster-node-timeout 15000
5.启动6台redis服务器并查看进程是否启动
cd node1
bin/redis-server redis.conf
cd ../node2
bin/redis-server redis.conf
ps -ef | grep redis
如图表示某两台启动成功:
6.安装ruby环境CentOS7 yum库中ruby的版本支持到 2.0.0,可gem 安装redis需要最低是2.2.2,采用rvm来更新ruby:
//具体RVM安装命令地址:http://rvm.io/
[root@linux ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys \
409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
[root@linux ~]# curl -sSL https://get.rvm.io | bash -s stable
[root@linux ~]# find / -name rvm -print
[root@linux ~]# source /usr/local/rvm/scripts/rvm
#查看rvm库中版本
[root@linux ~]# rvm list known
[root@linux ~]# rvm install 2.4.1
[root@linux ~]# rvm use 2.4.1
[root@linux ~]# rvm use 2.4.1 --default
[root@linux ~]# ruby --version
yum install rubygems
gem install redis
7.进入某一台主机的redis安装路经下的src目录,执行(这个步骤可以省略)
[root@node1 src]# ./redis-trib.rb create --replicas 1 10.193.50.14:6379 10.193.50.14:6380 10.193.50.15:6379 10.193.50.15:6380 10.193.50.16:6379 10.193.50.16:6380
会得到如下结果:
输入yes,搭建成功
8.测试
1.输入rvm -v报错,并且系统的Ctrl+C失效
Warning! PATH is not properly set up, /usr/local/rvm/gems/ruby-2.4.1/bin is not available.
Usually this is caused by shell initialization files. Search for PATH=... entries.
You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
To fix it temporarily in this shell session run: rvm use ruby-2.4.1
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
rvm 1.29.4 (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
解决:rvm reset
2.启动redis集群时报错,./redis-trib.rb create ***
/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-trib.rb:25:in `'
原因:rvm reset导致rvm配置失效
解决:rvm use 2.4.1 --default
3.启动redis集群时报错
[ERR] Node 10.193.50.14:6380 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
解决:rm dump.rdb appendonly.aof(如果配置了appendonly的话) nodes.conf
重启redis服务器
4.在redis客户端执行set k1 v1时,报错
(error) MOVED 12706 10.193.50.16:6379
原因:k1的槽信息所在服务器和当前客户端连接的服务器不同,需要客户端跟踪重定向,使用-c参数
解决:redis-cli -h 10.193.50.14 -p 6379 -c
参考:https://www.cnblogs.com/PatrickLiu/p/8454579.html 和 https://blog.csdn.net/u012042021/article/details/72818759