搭建环境:redis-4.0.10.tar.gz安装包、Red Hat Enterprise Linux 7(64位)
1、将redis安装包上传至服务器并解压缩至/usr/local路径下;
2、顺序执行下面命令:
mkdir /usr/local/redis-cluster(创建运行路径)
cd redis-cluster/
mkdir -p 9001/data 9002/data 9003/data 9004/data 9005/data 9006/data(服务端口对应数据持久化存储路径)
3、顺序执行下面命令:
mkdir redis-cluster/bin(创建集中执行文件路径)
cd /usr/local/redis-4.0.10/src(进入执行wen文件的路径)
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-trib.rb /usr/local/redis-cluster/bin/.(把将用到的各个执行文件集中复制到执行路径下)
4、执行cp /usr/local/redis-4.0.10/* /usr/local/redis-cluster/9001,将redis整体复制到9001实例下;
5、编辑redis.conf文件如下:
port 9001(每个节点的端口号)
daemonize yes(设置成后台守护模式)
bind 172.23.129.222(绑定当前机器 IP)
dir /usr/local/redis-cluster/9001/data/(数据文件存放位置)
pidfile /var/run/redis_9001.pid(pid 9001和port要对应)
cluster-enabled yes(启动集群模式)
cluster-config-file nodes9001.conf(9001和port要对应)
cluster-node-timeout 15000
6、执行复制操作:
cp -rf /usr/local/redis-cluster/9001/* /usr/local/redis-cluster/9002
cp -rf /usr/local/redis-cluster/9001/* /usr/local/redis-cluster/9003
cp -rf /usr/local/redis-cluster/9001/* /usr/local/redis-cluster/9004
cp -rf /usr/local/redis-cluster/9001/* /usr/local/redis-cluster/9005
cp -rf /usr/local/redis-cluster/9001/* /usr/local/redis-cluster/9006
7、顺序编辑900X下的每个redis.conf文件,将其中的9001替换成各自对应的900X;
8、启动各个节点:
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9001/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9002/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9003/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9004/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9005/redis.conf
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/9006/redis.conf
9、查看启动状态:
10、查看ruby的版本,ruby --version,如果低于2.2执行下面的升级安装操作:
11、安装rvm:
12、执行source /usr/local/rvm/scripts/rvm使更新生效;
13、执行rvm list known命令后显示ruby的版本:
# 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[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
ruby-head
# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2
# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.0.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.100]
rbx-head
# TruffleRuby
truffleruby[-1.0.0-rc2]
# Opal
opal
# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.0]
mruby[-head]
# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]
# Topaz
topaz
# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head
# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head
# IronRuby
ironruby[-1.1.3]
ironruby-head
14、执行rvm install 2.5.1开始安装;
15、如果ruby版本没有问题的话就可以继续执行命令gem install redis创建redis的集群;
16、构建redis集群:
/usr/local/redis-cluster/bin/redis-trib.rb create --replicas 1 172.23.129.222:9001 172.23.129.222:9002 172.23.129.222:9003 172.23.129.222:9004 172.23.129.222:9005 172.23.129.222:9006
replicas 1表示一个副本;
17、执行./redis-cli -c -h 172.23.129.222 -p 9001登录redis集群;
18、执行cluster info和cluster nodes查看集群的基本信息;