• CacheCloud+Redis Cluster 3部署


    CacheCloud环境需求

    • Java 7
    • Maven 3
    • MySQL
    • Redis 3

    具体用法可参考:https://cachecloud.github.io

    1.下载CacheCloud

    官网https://github.com/sohutv/cachecloud

    下载cachecloud-master.zip

    解压并移动cachecloud-master到/usr/local目录

    2.在MySQL中创建库并授权

    导入初始数据

    3.编辑/usr/local/cachecloud-master/cachecloud-open-web/src/main/swap/online.properties文件

    3.1在cachecloud根目录下运行

    mvn clean compile install -Ponline

    3.2创建/opt/cachecloud-web目录,并拷贝相关文件

    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/6380
    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/6384
    pidfile /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/

    1. redis-trib.rb的create子命令构建
    2. --replicas 1则指定了为Redis Cluster中的每个Master节点配备1个Slave节点
    3. 节点角色由顺序决定,先是master之后是slave

    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

  • 相关阅读:
    ECMAScript6 入门 函数的扩展
    ECMAScript6 入门-let与const命令
    编码规范
    webpack常用插件
    JS与CSS那些特别小的知识点区别
    常见数组方法及细节
    JS库
    Object冷知识
    html5-语义化标签
    Css继承属性和非继承属性
  • 原文地址:https://www.cnblogs.com/wsl222000/p/6410233.html
Copyright © 2020-2023  润新知