Distributed design - Cluster

  • A plurality of nodes together to save data
  • effect
    • Extended storage space
    • Increase throughput, improve write performance
  • And different points of single
    • No longer distinguish between databases, library only 0, stand-alone default 0-15
    • Does not support transactions / pipeline / multi-value operation
  • Feature
    • It requires at least three leading and three from
    • Requirements must be turned AOF persistence
    • Automatically selected cluster nodes for storage
    • Sentinel default integrated, automatic failover
  • Configuration
    # 每个节点分别配置ip/端口
    bind 127.0.0.1
    port 6379
    # 集群配置
    cluster-enabled yes   # 开启集群
    cluster-config-file nodes-7000.conf  # 节点日志文件
    cluster-node-timeout 15000  # 节点超时时长 15秒
    # 开启AOF 及相关配置  
    appendonly yes  
  • Create a cluster
    • redis installation package contains redis-trib.rb, Use to create a cluster
    • After you create a cluster, restart the cluster starts automatically redis
      # 将命令复制,这样可以在任何⽬录下调⽤此命令
      sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
      # 安装ruby环境,因为redis-trib.rb是⽤ruby开发的
      sudo apt-get install ruby
      gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
      sudo gem install redis
    
      # 启动主从数据库 7000-7005.conf
      sudo redis-server 7000.conf
      ...
    
      # 创建集群
      redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
      # 访问集群  访问集群必须加-c选项, 否则无法进行读写操作
      redis-cli -p 7000 -c
  • redis clusters can not support the transaction and WATCH, pessimistic concurrency control can only design your own lock (setnx)

  • python operation redis clusters
    • installation pip install redis-py-cluster
  • Use project
    • Sentinel and the master-slave configuration persistence mechanism for saving user's reading history / search history
    • Cluster is responsible for implementing cache design

Guess you like

Origin www.cnblogs.com/oklizz/p/11414389.html