概述这里只记录操作步骤和集群测试,保证快速搭建集群环境。具体原理请查阅官方文档(中文版): http://redisdoc.com/topic/cluster-tutorial.html http://redisdoc.com/topic/cluster-spec.html 准备工作
安装Ruby环境sudo apt-get install ruby安装ruby的redis接口: sudo gem install redis 如果不安装,后面执行脚本会报错: custom_require.rb:36:in `require': cannot load such file -- redis (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from ./redis-trib.rb:25:in `<main>' 启动集群进入到redis的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 命令的意义如下:
查看集群目前状况$ redis-cli -c -p 7000 127.0.0.1:7000> 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:0 cluster_stats_messages_sent:8770 cluster_stats_messages_received:8770 测试存值取值127.0.0.1:7000> set foo bar -> Redirected to slot [12182] located at 127.0.0.1:7002 OK 127.0.0.1:7002> set hello world -> Redirected to slot [866] located at 127.0.0.1:7000 OK 127.0.0.1:7000> get foo -> Redirected to slot [12182] located at 127.0.0.1:7002 "bar" 127.0.0.1:7000> get hello -> Redirected to slot [866] located at 127.0.0.1:7000
"world" 转载请保留固定链接: https://linuxeye.com/Linux/2464.html |