Configuring Redis cluster mode under Linux

Source: Internet
Author: User
Tags redis cluster install redis

Configuring the Machine 1
    • In the demo, 172.16.179.130 is the IP of the current Ubuntu machine
    • In 172.16.179.130? Desktop record, create CONF record
    • In conf, create a 7000.conf, edit the content as follows

      port 7000bind 172.16.179.130daemonize yespidfile 7000.pidcluster-enabled yescluster-config-file 7000_node.confcluster-node-timeout 15000appendonly yes
    • In conf, create a 7001.conf, edit the content as follows

      port 7001bind 172.16.179.130daemonize yespidfile 7001.pidcluster-enabled yescluster-config-file 7001_node.confcluster-node-timeout 15000appendonly yes
    • In conf, create a 7002.conf, edit the content as follows

      port 7002bind 172.16.179.130daemonize yespidfile 7002.pidcluster-enabled yescluster-config-file 7002_node.confcluster-node-timeout 15000appendonly yes
    • Summary: Three pieces of configuration differences in port, Pidfile, cluster-config-file three items

    • To configure a piece to start the Redis service

      redis-server 7000.confredis-server 7001.confredis-server 7002.conf
    • View processes such as

Configuring the Machine 2
    • In the demo, 172.16.179.131 is the IP of the current Ubuntu machine
    • In 172.16.179.131? Desktop record, create CONF record
    • In conf, create a 7003.conf, edit the content as follows

      port 7003bind 172.16.179.131daemonize yespidfile 7003.pidcluster-enabled yescluster-config-file 7003_node.confcluster-node-timeout 15000appendonly yes
    • In conf, create a 7004.conf, edit the content as follows

      port 7004bind 172.16.179.131daemonize yespidfile 7004.pidcluster-enabled yescluster-config-file 7004_node.confcluster-node-timeout 15000appendonly yes
    • In conf, create a 7005.conf, edit the content as follows

      port 7005bind 172.16.179.131daemonize yespidfile 7005.pidcluster-enabled yescluster-config-file 7005_node.confcluster-node-timeout 15000appendonly yes
    • Summary: Three pieces of configuration differences in port, Pidfile, cluster-config-file three items

    • To configure a piece to start the Redis service

      redis-server 7003.confredis-server 7004.confredis-server 7005.conf
    • View processes such as

Create a cluster
    • REDIS-TRIB.RB is included in the Redis installation package to create a cluster
    • The next operation on the 172.16.179.130 machine is motivated?
    • Copy the command so that it can be lowered at any record? This command

      sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
    • Install the ruby environment, because REDIS-TRIB.RB is a ruby-developed

      sudo apt-get install Ruby

    • At the tip of the message. Y, then go back to the installation

    • The following command creates a cluster

      redis-trib.rb create --replicas 1 172.16.179.130:7000 172.16.179.130:7001 172.16.179.130:7002 172.16.179.131:7003 172.16.179.131:7004 172.16.179.131:7005
    • This command may be an error on some machines, mainly because the installed Ruby is not the latest version!

    • Celestial Anti-wall causes the latest version of the download, so you need to set the source of the gem

    • The solution is as follows

      -- 先查看??的 gem 源是什么地址gem source -l -- 如果是https://rubygems.org/ 就需要更换-- 更换指令为gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/-- 通过 gem 安装 redis 的相关依赖sudo gem install redis-- 然后重新执?指令

redis-trib.rb create --replicas 1 172.16.179.130:7000 172.16.179.130:7001 172.16.179.130:7002 172.16.179.131:7003 172.16.179.131:7004 172.16.179.131:7005
    • Prompt the following master and slave information, after the return of the output yes?

    • Prompt completion, cluster build success
    • Data validation
      • As can be seen, the current building of the main server is 7000, 7001, 7003, the corresponding slave server is 7004, 7005, 7002
      • Connect to the cluster on the 172.16.179.131 machine with 7002, plus-C

        Redis-cli-h 172.16.179.131-c-P 7002

      • Write the data.

        Set name Itheima

      • ? Jump to the 7003 server, and write? Data success

    • Data can be obtained at 7003 if the write data is redirected to 7000 (load balancer)

On which server to write data: CRC16
    • Redis cluster is designed to take into account the go to the middleware, that is, each node in the cluster is an equal relationship, are equivalent, each node holds the data and the state of the whole cluster. Each node is connected to all other nodes, and these connections remain active, which ensures that we only need to connect to any of the nodes in the cluster to get data to other nodes
    • The Redis cluster does not have and makes the traditional sex hash distribution data, which is the same as the hash slot (hash slot) type to allocate. Redis cluster is assigned 16,384 slots by default, and when we set a key, will it? The CRC16 algorithm takes the module to get the slot to which it belongs, and then points the key to the node of the hash slot interval, the algorithm is: CRC16 (key)% 16384. So when we see the set and get at the test, we jump directly to the 7000-terminal node.
    • The Redis cluster will present the data to a master node and then synchronize the data between this master and its corresponding salve. When the data is read, the data is also obtained from the corresponding master node based on the sexually-induced hash algorithm. Only when a master hangs up does it start? A corresponding salve node that acts as the master
    • It is important to note that 3 or more master nodes must be required, otherwise the cluster will fail when it is created, and when the number of surviving master nodes is at half the total number of nodes, the whole cluster will serve the law.

Configuring Redis cluster mode under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.