僞集羣,單機上搭建,沒多的機器
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
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
yum -y install ruby ruby-devel rubygems rpm-build
gem install redis
[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.
建立集羣,出錯html
./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個節點
開始建立節點 node
從新建立redis集羣
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集羣搭建ruby