Redis Cluster centos 搭建

1.首先下载redis cluster的最新稳定版

到http://redis.io/download确定稳定版版本号

在centos要下载的目当下执行wget命令,下载redis cluster最新版

shell > wget -c -P ./ http://download.redis.io/releases/redis-3.0.6.tar.gz

2.解压redis cluster安装包,并进入redis目录进行编译

shell > tar xzvf redis-3.0.6.tar.gz redis-3.0.6
shell > cd redis-3.0.6
shell > make MALLOC=libc(据说不加此参数会报错)

3.安装ruby,此举是为了运行redis-trib.rb这个脚本,因为这个脚本是作者用ruby写的

shell > yum -y install ruby

4.安装redis gem,这个也是运行redis-trib.rb这个脚本的条件之一,这个在redis目录下安装即可

shell > gem install redis

5.建立redis-cluster的各个节点目录,因redis集群最低要求6个节点,所以这边就建立了6个节点目录,并以端口号命名目录

mkdir redis-cluster/6000
……
mkdir redis-cluster/6005

//拷贝基础配置并去掉其中需要各节点需要单独定义的配置项

cp redis-3.0.6/redis.conf redis-cluster/cluster-common.conf


//在各端口目录建立单独的自定义配置,并把公共配置包含进去
vim redis-cluster/6000/node-6000.conf


//简单配置示例如下
include /opt/local/redis/redis-cluster/cluster-common.conf
pidfile /opt/local/redis/redis-cluster/6000/node-6000.pid
port 6000
bind 10.130.161.16
dir /opt/local/redis/redis-cluster/6000/
logfile /opt/local/redis/redis-cluster/6000/node-6000.log
dbfilename node-6000.rdb
appendfilename node-6000.aof
cluster-enabled yes 
#此配置项是redis建立集群时自身存储配置信息的文件,不可以人工修改其内容
cluster-config-file /opt/local/redis/redis-cluster/6000/nodes.conf
cluster-node-timeout 2000

6.建立启动脚本

shell > cd redis-cluster
shell > vim redis-start.sh
//使脚本可执行
shell > chmod 755 redis-start.sh


//脚本简单示例如下
#! /usr/bin/env bash
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6000/node-6000.conf
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6001/node-6001.conf
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6002/node-6002.conf
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6003/node-6003.conf
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6004/node-6004.conf
/opt/local/redis/redis-3.0.6/src/redis-server /opt/local/redis/redis-cluster/6005/node-6005.conf
#其中--replicas 1选项是指一个master节点分配一个slave从节点
/opt/local/redis/redis-3.0.6/src/redis-trib.rb create --replicas 1 10.130.161.16:6000 10.130.161.16:6001 10.130.161.16:6002 10.130.161.16:6003 10.130.161.16:6004 10.130.161.16:6005

7.启动脚本

./redis-start.sh 
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.130.161.16:6000
10.130.161.16:6001
10.130.161.16:6002
Adding replica 10.130.161.16:6003 to 10.130.161.16:6000
Adding replica 10.130.161.16:6004 to 10.130.161.16:6001
Adding replica 10.130.161.16:6005 to 10.130.161.16:6002
M: 2c29d9720d7f48040325e454e7f73eb58c438825 10.130.161.16:6000
   slots:0-5460 (5461 slots) master
M: e5eac3cb05b73e658c8bcd89169c163ebfafd7c6 10.130.161.16:6001
   slots:5461-10922 (5462 slots) master
M: 28146a165ec3204ed22919afde19127f2082461b 10.130.161.16:6002
   slots:10923-16383 (5461 slots) master
S: 57c14dec53a2185245b593fb203485c8e2cf9b1b 10.130.161.16:6003
   replicates 2c29d9720d7f48040325e454e7f73eb58c438825
S: 33a4ae96eafcd6389c71cc359970f935d8b04637 10.130.161.16:6004
   replicates e5eac3cb05b73e658c8bcd89169c163ebfafd7c6
S: 35e465c2960a684811eefd6f8b916ae18414d206 10.130.161.16:6005
   replicates 28146a165ec3204ed22919afde19127f2082461b
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 10.130.161.16:6000)
M: 2c29d9720d7f48040325e454e7f73eb58c438825 10.130.161.16:6000
   slots:0-5460 (5461 slots) master
M: e5eac3cb05b73e658c8bcd89169c163ebfafd7c6 10.130.161.16:6001
   slots:5461-10922 (5462 slots) master
M: 28146a165ec3204ed22919afde19127f2082461b 10.130.161.16:6002
   slots:10923-16383 (5461 slots) master
M: 57c14dec53a2185245b593fb203485c8e2cf9b1b 10.130.161.16:6003
   slots: (0 slots) master
   replicates 2c29d9720d7f48040325e454e7f73eb58c438825
M: 33a4ae96eafcd6389c71cc359970f935d8b04637 10.130.161.16:6004
   slots: (0 slots) master
   replicates e5eac3cb05b73e658c8bcd89169c163ebfafd7c6
M: 35e465c2960a684811eefd6f8b916ae18414d206 10.130.161.16:6005
   slots: (0 slots) master
   replicates 28146a165ec3204ed22919afde19127f2082461b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

猜你喜欢

转载自blog.csdn.net/feiying00544/article/details/83096145