首页 / 数据库 / MySQL / Ubuntu 15.10下Redis集群部署文档
Linux版本:Ubuntu15.10系统。(要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下)
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
1:下载redis。官网下载3.0.0版本,之前2.几的版本不支持集群模式
下载地址:http://download.redis.io/releases/redis-3.0.7.tar.gz
2:上传服务器,解压,编译tar -zxvf redis-3.0.7.tar.gzmv redis-3.0.7 /usr/local/redis3.0cd /usr/local/redis3.0make之后就生成了 redis-server redis-client 等文件在 src里。3:创建集群需要的目录mkdir -p /usr/local/clustercd /usr/local/clustermkdir 7000mkdir 7001mkdir 7002mkdir 7003mkdir 7004mkdir 7005 4:修改配置文件redis.conf
cp /usr/local/redis3.0/redis.conf /usr/local/cluster
vi redis.conf
##修改配置文件中的下面选项pidfile /var/run/redis.7000.pid #个性化port 7000 #个性化daemonize yescluster-enabled yescluster-config-file nodes.7000.conf #个性化cluster-node-timeout 5000appendonly yesappendfilename "appendonly.7000.aof" #个性化##修改完redis.conf配置文件中的这些配置项之后把这个配置文件分别拷贝到7000/7001/7002/7003/7004/7005目录下面cp /usr/local/cluster/redis.conf /usr/local/cluster/7000cp /usr/local/cluster/redis.conf /usr/local/cluster/7001cp /usr/local/cluster/redis.conf /usr/local/cluster/7002cp /usr/local/cluster/redis.conf /usr/local/cluster/7003cp /usr/local/cluster/redis.conf /usr/local/cluster/7004cp /usr/local/cluster/redis.conf /usr/local/cluster/7005##注意:拷贝完成之后要修改7001/7002/7003/7004/7005目录下面redis.conf文件中 标注个性化的 参数,分别改为对应的文件夹的名称5:分别启动这6个redis实例
vi /usr/local/cluster/redis-start.sh
加入以下内容#!/bin/sh/usr/local/redis3.0/src/redis-server /usr/local/cluster/7000/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7001/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7002/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7003/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7004/redis.conf &/usr/local/redis3.0/src/redis-server /usr/local/cluster/7005/redis.conf &然后chmod +x /usr/local/cluster/redis-start/usr/local/cluster/redis-start##启动之后使用命令查看redis的启动情况ps -ef|grep redis
6:执行redis的创建集群命令创建集群
安装ruby ,因为./redis-trib.rb 是执行的ruby的脚本,需要ruby的环境
sudo apt-get install ruby为了执行 redis-trib.rb 需要安装 gem redis sudo gem install redis 可能会有长城防火墙的问题
可以去https://rubygems.org/gems/redis/versions/3.2.2 下载最新版本。
然后用命令 sudo gem install redis-3.2.2.gemcd /usr/local/redis3.0/src./redis-trib.rbcreate --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有下面输出表示成功了。>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002Adding replica 127.0.0.1:7003 to 127.0.0.1:7000Adding replica 127.0.0.1:7004 to 127.0.0.1:7001Adding replica 127.0.0.1:7005 to 127.0.0.1:7002M: 1cdc6971ddbcf64427a9499e19b048afa55aff08 127.0.0.1:7000 slots:0-5460 (5461 slots) masterM: a355b2ccb1fdf413652a14cec722076af958a079 127.0.0.1:7001 slots:5461-10922 (5462 slots) masterM: 0bc286b514d36e7195142ff0d55a87542048b5a9 127.0.0.1:7002 slots:10923-16383 (5461 slots) masterS: a3b7c85fe957917bd383b181de3f1a3f31df8a05 127.0.0.1:7003 replicates 1cdc6971ddbcf64427a9499e19b048afa55aff08S: 9f0f4045497a72b64783fd9c2387f38b7e3bda6c 127.0.0.1:7004 replicates a355b2ccb1fdf413652a14cec722076af958a079S: f4b371c4e1d0fddfbe1552e540ddd36a5a00200b 127.0.0.1:7005 replicates 0bc286b514d36e7195142ff0d55a87542048b5a9Can 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 clusterWaiting for the cluster to join...>>> Performing Cluster Check (using node 127.0.0.1:7000)M: 1cdc6971ddbcf64427a9499e19b048afa55aff08 127.0.0.1:7000 slots:0-5460 (5461 slots) masterM: a355b2ccb1fdf413652a14cec722076af958a079 127.0.0.1:7001 slots:5461-10922 (5462 slots) masterM: 0bc286b514d36e7195142ff0d55a87542048b5a9 127.0.0.1:7002 slots:10923-16383 (5461 slots) masterM: a3b7c85fe957917bd383b181de3f1a3f31df8a05 127.0.0.1:7003 slots: (0 slots) master replicates 1cdc6971ddbcf64427a9499e19b048afa55aff08M: 9f0f4045497a72b64783fd9c2387f38b7e3bda6c 127.0.0.1:7004 slots: (0 slots) master replicates a355b2ccb1fdf413652a14cec722076af958a079M: f4b371c4e1d0fddfbe1552e540ddd36a5a00200b 127.0.0.1:7005 slots: (0 slots) master replicates 0bc286b514d36e7195142ff0d55a87542048b5a9[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.这样redis-cluster集群就启动了7、查看集群目前状况:$ redis-cli -c -p 7000127.0.0.1:7000> cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:0cluster_stats_messages_sent:8770cluster_stats_messages_received:87708、测试存值取值:每一次操作过后可能就跳到别的里面了。就是那个Redirected to slot ……127.0.0.1:7002> set foo bar
OK
127.0.0.1:7000> set hello world
OK
127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
127.0.0.1:7002> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"
127.0.0.1:7000> get name
-> Redirected to slot [5798] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001>
127.0.0.1:7002> get name
-> Redirected to slot [5798] located at 127.0.0.1:7001
(nil)
127.0.0.1:7001>下面关于Redis的文章您也可能喜欢,不妨参考下:Ubuntu 14.04下Redis安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htmRedis主从复制基本配置 http://www.linuxidc.com/Linux/2015-03/115610.htmRedis集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htmUbuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis http://www.linuxidc.com/Linux/2013-06/85816.htmRedis系列-安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htmCentOS 6.3安装Redis http://www.linuxidc.com/Linux/2012-12/75314.htmRedis安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htmRedis配置文件redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htmRedis 的详细介绍:请点这里
Redis 的下载地址:请点这里本文永久更新链接地址