redis集群安装搭建

vi redis-6379.conf
 
#包含通用配置
include "/usr/local/redis/conf/redis-common.conf"
pidfile "/usr/local/redis/run/redis-6379.pid"
logfile "/home/aspire/logs/redis/redis_6379.log"
 
#监听tcp端口
port 6379
bind 10.255.202.44 127.0.0.1
 
#最大可用内存
maxmemory 1g
 
#内存耗尽时采用的淘汰策略:
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
 
#aof存储文件
appendfilename "appendonly-6379.aof"
 
#rdb文件,只用于动态添加slave过程
dbfilename "dump-6379.rdb"
dir "/home/aspire/data/redis/6379"
 
#cluster配置文件(启动自动生成)
cluster-config-file "nodes-6379.conf"
 
安装ruby
yum install ruby
安装rubygem
yum install rubygems
安装gem-redis
https://rubygems.org/gems/redis/versions/3.2.2 gem install -l /data/soft/redis-3.2.2.gem
 
redis-server /usr/local/redis/conf/redis-6377.conf
redis-server /usr/local/redis/conf/redis-7377.conf
redis-server /usr/local/redis/conf/redis-6378.conf
redis-server /usr/local/redis/conf/redis-7378.conf
redis-server /usr/local/redis/conf/redis-6379.conf
redis-server /usr/local/redis/conf/redis-7379.conf
 
./redis-trib.rb create --replicas 1 10.255.201.90:6377 10.255.201.91:6378 10.255.201.92:6379 10.255.201.90:7377 10.255.201.91:7378 10.255.201.92:7379
 
[ERR] Sorry, can't connect to node 127.0.0.1:7000 配置了密码,去掉密码OK
#########################################################
No problem. We are using Redis Cluster with AUTH.
Although redis-trib.rb doesn't support AUTH yet, you can create a cluster manually or rcm.
 
For instance, rcm can easily create clusters with AUTH ( requirepass = secret ) like this.
 
% rcm -a secret create :7001 :7002 :7003
#########################################################
 
 
新添加主节点 redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000 分配slot redis-trib.rb reshard 127.0.0.1:7006 给主节点新加从节点 redis-trib.rb add-node --slave --master-id 2e30017779471ea0c2609b5badf2733951fb9f46 127.0.0.1:7007 192.168.56.160:7006
 
cluster删除节点
CLUSTER FORGET 5d992a0fb6eb25e785d819407b9030569c5bb03a
cluster添加从节点
CLUSTER REPLICATE 30e6051ec67d786dc414a182dc22cff43c83f15e 查看节点信息 127.0.0.1:7004> CLUSTER NODES
 
 
基本命令
CLUSTER INFO 打印集群的信息
CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。
CLUSTER MEET <ip> <port> 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。 CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。
CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。
CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面
CLUSTER ADDSLOTS <slot> [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。
CLUSTER DELSLOTS <slot> [slot ...] 移除一个或多个槽对当前节点的指派。
CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。 CLUSTER SETSLOT <slot> NODE <node_id> 将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。
CLUSTER SETSLOT <slot> MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。 CLUSTER SETSLOT <slot> IMPORTING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。 CLUSTER SETSLOT <slot> STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。
CLUSTER KEYSLOT <key> 计算键 key 应该被放置在哪个槽上。
CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的键值对数量。
CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 个 slot 槽中的键。
 
http://note.youdao.com/noteshare?id=76561d9e1f8416737fd6eb112717a0d0
原文地址:https://www.cnblogs.com/zhengchunyuan/p/10950641.html