您的位置:首页 > 数据库 > Redis

搭建redis集群环境

2017-02-24 00:00 447 查看
摘要: 闲来无事^_^

搭建redis集群环境

伪集群,单机上搭建,没多的机器

说明

Redis3.0版本之后支持Cluster
当前版本3.2.8
redis集群搭建最少6个节点其中3个主节点

修改配置

接上文redis环境搭建
redis1配置
打开集群配置
port 7001
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 5000
redis2配置
port 7002
cluster-enabled yes
cluster-config-file nodes-7002.conf
cluster-node-timeout 5000
redis3配置
port 7003
cluster-enabled yes
cluster-config-file nodes-7003.conf
cluster-node-timeout 5000




启动redis

cd redis1
./redis-server redis.conf
cd redis2
./redis-server redis.conf
cd redis3
./redis-server redis.conf

查看服务是否正常

ps -ef|grep redis 查看redis进程




创建集群

官方有提供工具redis-trib.rb,采用ruby编写,so安装ruby

安装ruby

yum -y install ruby ruby-devel rubygems rpm-build

通过ruby命令工具安装redis

gem install redis

通过redis-trib.rb 创建集群

查看命令参数

[root@vultr src]# ./redis-trib.rb
Usage: redis-trib <command> <options> <arguments ...>

set-timeout     host:port milliseconds
reshard         host:port
--pipeline <arg>
--to <arg>
--yes
--slots <arg>
--from <arg>
--timeout <arg>
del-node        host:port node_id
add-node        new_host:new_port existing_host:existing_port
--slave
--master-id <arg>
fix             host:port
--timeout <arg>
help            (show this help)
rebalance       host:port
--pipeline <arg>
--simulate
--auto-weights
--use-empty-masters
--weight <arg>
--timeout <arg>
--threshold <arg>
check           host:port
info            host:port
create          host1:port1 ... hostN:portN
--replicas <arg>
import          host:port
--replace
--copy
--from <arg>
call            host:port command arg arg .. arg
For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

创建集群,出错

./redis-trib.rb  create  --replicas  1  127.0.0.1:7001 127.0.0.1:7002  127.0.0.1:7003

*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 3 nodes and 1 replicas per node.
*** At least 6 nodes are required.

至少需要6个节点

开始创建节点



重新创建redis集群





测试

1.通过redis-cli链接redis redis-cli -c -p 7001
[root@vultr bin]# redis-cli -c -p 7001
127.0.0.1:7001> set name kite
-> Redirected to slot [5798] located at 127.0.0.1:7002
OK
127.0.0.1:7002> get name
"kite"
127.0.0.1:7002> exit
[root@vultr bin]# redis-cli -c -p 7003
127.0.0.1:7003> get name
-> Redirected to slot [5798] located at 127.0.0.1:7002
"kite"
127.0.0.1:7002>

已经进行同步

参考

Redis 3.2.1集群搭建
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: