具体用法可参考:https://cachecloud.github.iojava
1.下载CacheCloudnode
官网https://github.com/sohutv/cachecloudgit
下载cachecloud-master.zipgithub
解压并移动cachecloud-master到/usr/local目录web
2.在MySQL中建立库并受权redis
导入初始数据数据库
3.编辑/usr/local/cachecloud-master/cachecloud-open-web/src/main/swap/online.properties文件ruby
3.1在cachecloud根目录下运行服务器
mvn clean compile install -Ponline
3.2建立/opt/cachecloud-web目录,并拷贝相关文件app
mkdir -p /opt/cachecloud-web
cp cachecloud-open-web/target/cachecloud-open-web-1.0-SNAPSHOT.war /opt/cachecloud-web/
cp cachecloud-open-web/src/main/resources/cachecloud-web.conf /opt/cachecloud-web/
ln -s /opt/cachecloud-web/cachecloud-open-web-1.0-SNAPSHOT.war /etc/init.d/cachecloudweb
4.启动cachecloud-web并经过http://IP:8585访问,用户名和密码admin
/etc/init.d/cachecloudweb start
5.使用cachecloud-init.sh安装redis和初始化,可根据需求修改脚本中redis的版本
6.在服务器上建立cachecloud SSH链接帐号,和系统配置管理页面里的用户名和密码保持一致便可
useradd cachecloud
passwd cachecloud
6.1点击右上角管理后台—>机器管理,添加机器
6.2点击右上角导入应用
7.redis cluster安装(要让集群正常工做至少须要3个主节点,在这里咱们要建立6个redis节点,其中三个为主节点,三个为从节点)
172.17.20.127 | redis-6379/1680 |
172.17.20.128 | redis-6381/6382 |
172.17.20.129 | redis-6383/6384 |
Redis 集群使用数据分片(sharding)而非一致性哈希(consistency hashing)来实现: 一个 Redis 集群包含 16384 个哈希槽(hash slot), 数据库中的每一个键都属于这 16384 个哈希槽的其中一个, 集群使用公式 CRC16(key) % 16384 来计算键 key 属于哪一个槽, 其中 CRC16(key) 语句用于计算键 key 的 CRC16 校验和 。集群中的每一个节点负责处理一部分哈希槽。
下载编译安装redis
cp -pr redis redis-6380 #其余相似按照端口号复制
修改redis.conf
daemonize yes
port 6379 #其余配置改成6380/6381/6382/6383/6384pidfile /var/run/redis_6379.pid #其余配置按端口号修改
cluster-enabled yes
cluster-config-file nodes-6379.conf # 其余配置按端口号修改
cluster-node-timeout 15000
appendonly yes
建立配置文件软链接并启动redis
ln -s /opt/cachecloud/redis-6379/redis.conf /etc/redis-6379.conf #其余按照相似配置
分别启动集群redis
8.安装Redis 集群须要的Ruby工具
yum install ruby rubygems
gem install redis
进入reids目录下面运行
cd /opt/cachecloud/redis/src/
9.经常使用命令
查看集群状况
redis-trib.rb check ip:port #检查集群状态
redis-cli -c -h ip -p port #使用-c进入集群命令模式
redis-trib.rb rebalance ip:port --auto-weights #从新分配权重
增长、删除集群节点
redis-trib.rb add-node ip:port(新增节点) ip:port(现有效节点)
redis-trib.rb del-node ip:port id(目标节点的id) #删除master节点以前首先要使用reshard移除master的所有slot
从新划分slot
redis-trib.rb reshard ip:port
10.将master转换为salve
cluster replicate master-id #转换前6380端必须没有slots
11.模拟故障切换
杀死一个redis进程,观察FailOver状况
Redis集群经过选举方式进行容错,保证一台Server挂了还能跑,这个选举是所有集群超过半数以上的Master发现其余Master挂了后,会将其余对应的Slave节点升级成Master.
12.把redis cluster加入cachecloud