一 。准备文件:
Ruby :http://www.ruby-lang.org/en/downloads/ redis-3.0.5.tar.gz
Redis:http://www.redis.cn/download.html ruby-2.2.4.tar.gz
二 。安装Ruby
- 将ruby的安装文件ruby-2.2.4.tar.gz放到/usr/local目录下。
- 进入/usr/local目录解压文件。
cd /usr/local
tar -zxvf ruby-2.2.4.tar.gz
- 进入/usr/local目录解压文件。
cd ruby-2.2.4
- 进行预编译配置
./configure
- 编译安装
make && make install
- 检验安装结果
ruby -v
- 设置PATH路径,把自己安装的ruby放在系统PATH前面,避免调用操作系统自带的ruby
export PATH=/usr/local/ruby-2.2.4./bin:$PATH - Ruby安装完成后gem也默认安装了,不过版本不是最新版本,且由于网络原因,导致rubygems.org存放在Amazon S3上的资源文件间歇性连接失败。我们将原来的源替换下:
gem source --remove
https://rubygems.org
gem source -a https://ruby.taobao.org/
gem sources –l
- gem升级
gem update –system
三. 安装redis集群
1:上传服务器,解压,编译
tar –zxvf redis-3.0.5.tar.gz
cd redis-3.0.5
make
make install
2:创建集群需要的目录
mkdir -p /usr/local/cluster
cd /usr/local/cluster
mkdir 7000 7001 7002 7003 7004
7005
3:修改配置文件redis.conf
cp /usr/local/ redis-3.0.5/redis.conf /usr/local/cluster
vi redis.conf
##修改配置文件中的下面选项
port 7000
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
##修改完redis.conf配置文件中的这些配置项之后把这个配置文件分别拷贝到7000/7001/7002/7003/7004/7005目录下面
cp /usr/local/cluster/redis.conf /usr/local/cluster/7000
cp /usr/local/cluster/redis.conf /usr/local/cluster/7001
cp /usr/local/cluster/redis.conf /usr/local/cluster/7002
cp /usr/local/cluster/redis.conf /usr/local/cluster/7003
cp /usr/local/cluster/redis.conf /usr/local/cluster/7004
cp /usr/local/cluster/redis.conf /usr/local/cluster/7005
##注意:拷贝完成之后要修改7001/7002/7003/7004/7005目录下面redis.conf文件中的port参数,分别改为对应的文件夹的名称
4: 分别启动这6个redis实例
cd /usr/local/cluster/7000
redis-server redis.conf
cd /usr/local/cluster/7001
redis-server redis.conf
cd /usr/local/cluster/7002
redis-server redis.conf
cd /usr/local/cluster/7003
redis-server redis.conf
cd /usr/local/cluster/7004
redis-server redis.conf
cd /usr/local/cluster/7005
redis-server redis.conf
##启动之后使用命令查看redis的启动情况ps -ef|grep redis
如下图显示则说明启动成功
5:执行redis的创建集群命令创建集群
cd /usr/local/redis3.0.5/src ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 |
6.2 再次执行第6步的命令,正常执行
输入yes,然后配置完成。
测试集群
测试 Redis 集群比较简单的办法就是使用 redis-rb-cluster
或者 redis-cli
, 接下来我们将使用 redis-cli
为例来进行演示:
$ redis-cli -c -p 7000
redis 127.0.0.1:7000> set foo bar
-> Redirected to slot [12182] located at 127.0.0.1:7002
OK
redis 127.0.0.1:7002> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7000
OK
redis 127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
redis 127.0.0.1:7000> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"
$ redis-cli -c -p 7004
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"