目前线上使用2.8.4版本的,一直很稳定,但是数据量越来越大,所以想升级到支持集群的3.X版本
特此记录安装过程
下载安装
cd /soft (我习惯放在这个目录下)
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar xzf redis-3.2.9.tar.gzcd redis-3.2.9
make && make install
依赖项
yum install automake autoconf ruby rubygems -y
创建六个实例
实例目录
mkdir -p /usr/local/cluster
mkdir -p /usr/local/cluster/6379
mkdir -p /usr/local/cluster/6380
mkdir -p /usr/local/cluster/6381
mkdir -p /usr/local/cluster/6382
mkdir -p /usr/local/cluster/6383
mkdir -p /usr/local/cluster/6384
修改配置文件
cp /soft/redis-3.2.9/redis.conf /usr/local/cluster/6379/
打开redis.conf并修改(注意不同文件夹下端口都不一样)
所有port都要修改(一般cp过来的都是6379,可以根据6379查找、修改)
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly ye
每个文件夹下都一样
启动实例
cd 6379
redis-server redis.conf
其他同理
所有实例启动成功
root 7607 1 0 21:32 ? 00:00:02 redis-server 127.0.0.1:6379 [cluster] root 7723 1 0 21:33 ? 00:00:02 redis-server 127.0.0.1:6380 [cluster] root 7748 1 0 21:33 ? 00:00:02 redis-server 127.0.0.1:6381 [cluster] root 7775 1 0 21:33 ? 00:00:02 redis-server 127.0.0.1:6382 [cluster] root 7786 1 0 21:33 ? 00:00:02 redis-server 127.0.0.1:6383 [cluster] root 7847 1 0 21:33 ? 00:00:02 redis-server 127.0.0.1:6384 [cluster]
配置集群
cd/soft/redis-3.2.9/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
如果报以下错误:
/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
则需要安装redis和ruby的接口
gem install redis
安装好后继续执行上面命令,提示输入yes即可
>>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 Adding replica 127.0.0.1:6382 to 127.0.0.1:6379 Adding replica 127.0.0.1:6383 to 127.0.0.1:6380 Adding replica 127.0.0.1:6384 to 127.0.0.1:6381 M: c274b5d0921e59a50838afd5d2975f1ead774aa0 127.0.0.1:6379 slots:0-5460 (5461 slots) master M: 515b30be975005a102837fd75298ad4ec87cd2e7 127.0.0.1:6380 slots:5461-10922 (5462 slots) master M: 72bbf9cf89ae3eb64230b0b60d720c46400983fb 127.0.0.1:6381 slots:10923-16383 (5461 slots) master S: 1d8a5458a13b4a13b3c21f73981a463bc7dd8652 127.0.0.1:6382 replicates c274b5d0921e59a50838afd5d2975f1ead774aa0 S: f28ecdd64376fd41cd78ec8d1ccf0b3ede2352c1 127.0.0.1:6383 replicates 515b30be975005a102837fd75298ad4ec87cd2e7 S: df431bd756cf57b4711ae3dd64d569e7958e4acc 127.0.0.1:6384 replicates 72bbf9cf89ae3eb64230b0b60d720c46400983fb Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.... >>> Performing Cluster Check (using node 127.0.0.1:6379) M: c274b5d0921e59a50838afd5d2975f1ead774aa0 127.0.0.1:6379 slots:0-5460 (5461 slots) master 1 additional replica(s) S: f28ecdd64376fd41cd78ec8d1ccf0b3ede2352c1 127.0.0.1:6383 slots: (0 slots) slave replicates 515b30be975005a102837fd75298ad4ec87cd2e7 S: df431bd756cf57b4711ae3dd64d569e7958e4acc 127.0.0.1:6384 slots: (0 slots) slave replicates 72bbf9cf89ae3eb64230b0b60d720c46400983fb M: 72bbf9cf89ae3eb64230b0b60d720c46400983fb 127.0.0.1:6381 slots:10923-16383 (5461 slots) master 1 additional replica(s) M: 515b30be975005a102837fd75298ad4ec87cd2e7 127.0.0.1:6380 slots:5461-10922 (5462 slots) master 1 additional replica(s) S: 1d8a5458a13b4a13b3c21f73981a463bc7dd8652 127.0.0.1:6382 slots: (0 slots) slave replicates c274b5d0921e59a50838afd5d2975f1ead774aa0 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
这时候执行
redis-cli cluster info
cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_sent:552 cluster_stats_messages_received:552
redis-cli cluster nodes
f28ecdd64376fd41cd78ec8d1ccf0b3ede2352c1 127.0.0.1:6383 slave 515b30be975005a102837fd75298ad4ec87cd2e7 0 1497362977647 5 connected df431bd756cf57b4711ae3dd64d569e7958e4acc 127.0.0.1:6384 slave 72bbf9cf89ae3eb64230b0b60d720c46400983fb 0 1497362978648 6 connected 72bbf9cf89ae3eb64230b0b60d720c46400983fb 127.0.0.1:6381 master - 0 1497362978147 3 connected 10923-16383 515b30be975005a102837fd75298ad4ec87cd2e7 127.0.0.1:6380 master - 0 1497362978147 2 connected 5461-10922 1d8a5458a13b4a13b3c21f73981a463bc7dd8652 127.0.0.1:6382 slave c274b5d0921e59a50838afd5d2975f1ead774aa0 0 1497362977146 4 connected c274b5d0921e59a50838afd5d2975f1ead774aa0 127.0.0.1:6379 myself,master - 0 0 1 connected 0-5460
竟然自动分配了主从和slot = =(我自己测试使用的是3.2.8,主从和slot都需要自己配置,不过也很简单)
完成
@H_502_154@[root@src]# redis-cli -c set test001 hahaha
OK
[root@src]# redis-cli -c get test001
"hahaha"
OK