zoukankan      html  css  js  c++  java
  • 第十节 redis集群搭建

    为什么要有集群
      一主可以有多从,如果同时的访问量过大或者发生自燃灾害,主服务可能会挂掉,数据服务就会挂掉
      大公司都会有很多的服务器(华东、华南、华中等等)
    集群概念
      集群是一组相互独立的、通过高速网络互联的计算机,它们构成了一个组,并以单一系统的模式加以管理。一个客户与集群相互作用时,集群像是一个独立的服务器。集群配置是用于提高可用性和可缩放性。

    Redis集群
      分类
        软件层面:只要一台电脑,在这台电脑上启动了多个redis服务
        硬件层面:存在多台实体电脑,每台电脑上都启动了一个或者多个redis服务

    环境:两台虚拟机,需要网络互通,必须有三个或者以上的主节点,否则集群会创建失败
      第一台虚拟机
        创建一个conf目录,在目录下创建文件7000.conf,写入
          prot 7000
          bind 本机ip
          daemonize yes
          pidfile 7000.pid
          cluster-enabled yes
          cluster-config-file 7000_node.conf
          cluster-node-timeout 15000
          appendonly yes
        再创建一个7001.conf文件,写入
          prot 7001
          bind 本机ip
          daemonize yes
          pidfile 7001.pid
          cluster-enabled yes
          cluster-config-file 7001_node.conf
          cluster-node-timeout 15000
          appendonly yes
        再创建一个7002.conf文件,写入
          prot 7002
          bind 本机ip
          daemonize yes
          pidfile 7002.pid
          cluster-enabled yes
          cluster-config-file 7002_node.conf
          cluster-node-timeout 15000
          appendonly yes
        三个文件的区别配置在port、pidfile、cluster-config-file

        使用配置文件启动服务
          redis-server 7000.conf
          redis-server 7001.conf
          redis-server 7002.conf
        查看进程是否启动 ps -ef | grep redis

      第二台虚拟机
        创建一个conf目录,在目录下创建文件7003.conf,写入
          prot 7003
          bind 本机ip
          daemonize yes
          pidfile 7003.pid
          cluster-enabled yes
          cluster-config-file 7003_node.conf
          cluster-node-timeout 15000
          appendonly yes
        再创建一个7004.conf文件,写入
          prot 7004
          bind 本机ip
          daemonize yes
          pidfile 7004.pid
          cluster-enabled yes
          cluster-config-file 7004_node.conf
          cluster-node-timeout 15000
          appendonly yes
        再创建一个7005.conf文件,写入
          prot 7005
          bind 本机ip
          daemonize yes
          pidfile 7005.pid
          cluster-enabled yes
          cluster-config-file 7005_node.conf
          cluster-node-timeout 15000
          appendonly yes
        三个文件的区别配置在port、pidfile、cluster-config-file

        使用配置文件启动服务
          redis-server 7003.conf
          redis-server 7004.conf
          redis-server 7005.conf
        查看进程是否启动 ps -ef | grep redis

    创建集群
      redis的安装包中包含了redis-trib.rb
      接下来的操作任选一台虚拟机进行(这里称为主机)
      安装ruby环境 yum install ruby
      将命令redis-trib.rb复制
        cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
    执行创建集群命令
      redis-trib.rb create --replicas 1 主机ip:7000 主机ip:7001 主机ip:7002 另外一台虚拟机ip:7003 另外一台虚拟机ip:7004 另外一台虚拟机ip:7005

      如有报错,看是否是ruby版本的问题

    数据验证
      redis-cli -h ip -c -p 7001
      set name itheima
      数据存储在哪个主服务器由CRC16算法决定

  • 相关阅读:
    Entity Framework 学习 Code First(1)
    CLR via C# 读书笔记 运行时序列化
    Entity Framework 学习 Model First
    轻量级开发工具 SharpDevelop
    bit加载失败
    [Reminder] 影响EMIF16异步读写性能因素
    Field Alert: Initial Voltage Level Setting of CVDD rail power supplies
    PHP函数Imap电子邮件系统函数
    PHP函数PHP选项及相关信息函数
    PHP函数Soap函数
  • 原文地址:https://www.cnblogs.com/kogmaw/p/12420030.html
Copyright © 2011-2022 走看看