Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build redis environment

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to build a redis environment, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Because there is redis in the work environment, I learned about redis. Of course, the first step is to build the environment. Here is my record of building the redis environment.

The system is SuSE 11 sp2

The software environment is as follows:

Linux-svnfile:/home/apps/redis # ls

Redis-3.0.0.gem ruby-1.9.2-p290.tar.gz zlib-1.2.7.tar.gz

Redis-3.0.0.tar.gz rubygems-2.4.6.tgz

Redis.conf zlib-1.2.6.tar.gz

Install the base environment:

Linux-svnfile:/home/apps/redis # tar-zxf zlib-1.2.6.tar.gz-C / usr/local/src

Linux-svnfile:/usr/local/src/zlib-1.2.6 #. / configure-prefix=/usr/local/zlib

Linux-svnfile:/usr/local/src/zlib-1.2.6 # make & & make install

Linux-svnfile:/home/apps/redis # tar-zxf ruby-1.9.2-p290.tar.gz-C / usr/local/src

Linux-svnfile:/usr/local/src/ruby-1.9.2-p290 #. / configure-prefix=/usr/local/ruby

Linux-svnfile:/usr/local/src/ruby-1.9.2-p290 # make & & make install

Linux-svnfile:/usr/local/ruby # ln-s / usr/local/ruby/bin/ruby / usr/local/bin

Linux-svnfile:/home/apps/redis # tar xf rubygems-2.4.6.tgz-C / usr/local/src

Linux-svnfile:/usr/local/src # mv rubygems-2.4.6.. / gem

Linux-svnfile:/usr/local/gem # ruby setup.rb

Linux-svnfile:/usr/local/gem # cp bin/gem / usr/local/bin/

Linux-svnfile:/home/apps/redis # gem install-l redis-3.0.0.gem

Successfully installed redis-3.0.0

Installing ri documentation for redis-3.0.0

Done installing documentation for redis after 0 seconds

1 gem installed

Linux-svnfile:/home/apps/redis # tar-zxf redis-3.0.0.tar.gz-C / usr/local/src

Linux-svnfile:/usr/local/src # mv redis-3.0.0.. / redis

Linux-svnfile:/usr/local/redis # make

At this point, the basic environment has been built.

Let's build the cluster.

Linux-svnfile:/usr/local/redis # cp src/redis-server / usr/local/bin/

Linux-svnfile:/usr/local/redis # cp src/redis-cli / usr/local/bin/

Linux-svnfile:/usr/local/redis # cp src/redis-trib.rb / usr/local/bin

Linux-svnfile:/usr/local/redis # mkdir-p / usr/local/cluster/ {7000.7005}

Linux-svnfile:/usr/local/redis # vi redis.conf

Daemonize yes

Port 7000

Cluster-enabled yes

Cluster-config-file nodes.conf

Cluster-node-timeout 5000

Appendonly yes

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7000

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7001

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7002

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7003

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7004

Linux-svnfile:/usr/local/redis # cp redis.conf.. / cluster/7005

It should be noted here that the file name corresponds to the configuration of the port in the file. For example, the port parameter under file 7001 needs to be changed to 7001, and other changes should be made as well.

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7000/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7001/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7002/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7003/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7004/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7005/redis.conf

Linux-svnfile:/usr/local/redis # ps-ef | grep redis

Root 15590 1 0 18:52? 00:00:00 redis-server *: 7000 [cluster]

Linux-svnfile:/usr/local/redis # redis-trib.rb create-- replicas 1 127.0.0.1VR 7000 127.0.0.1V 7001 127.0.0.1V 7002 127.0.0.1V 7003 127.0.1V 7003 127.0.1V 7004 127.0.0.1V 7005

> Creating cluster

Connecting to node 127.0.0.1:7000: OK

Connecting to node 127.0.0.1:7001: [ERR] Sorry, can't connect to node 127.0.0.1:7001

You have new mail in / var/mail/root

Linux-svnfile:/usr/local/cluster/7000 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7000 # cd.. / 7001

Linux-svnfile:/usr/local/cluster/7001 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7001 # cd.. / 7002

Linux-svnfile:/usr/local/cluster/7002 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7002 # cd.. / 7003

Linux-svnfile:/usr/local/cluster/7003 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7003 # cd.. / 7004

Linux-svnfile:/usr/local/cluster/7004 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7004 # cd.. / 7005

Linux-svnfile:/usr/local/cluster/7005 # redis-server redis.conf

Linux-svnfile:/usr/local/cluster/7005 # ps-ef | grep redis

Root 17575 1 0 20:05? 00:00:00 redis-server *: 7000 [cluster]

Root 17590 1 0 20:06? 00:00:00 redis-server *: 7001 [cluster]

Root 17604 1 0 20:06? 00:00:00 redis-server *: 7002 [cluster]

Root 17612 1 0 20:06? 00:00:00 redis-server *: 7003 [cluster]

Root 17616 1 0 20:06? 00:00:00 redis-server *: 7004 [cluster]

Root 17624 1 0 20:06? 00:00:00 redis-server *: 7005 [cluster]

For example, when starting the service above, you need to switch to the directory of the corresponding configuration file, otherwise the service of the corresponding port cannot be started. For example, only 7000 of the corresponding service has been started after I started it in the / usr/local/redis directory.

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7000/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7001/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7002/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7003/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7004/redis.conf

Linux-svnfile:/usr/local/redis # redis-server.. / cluster/7005/redis.conf

Linux-svnfile:/usr/local/redis # ps-ef | grep redis

Root 15144 19064 0 18:37 pts/0 00:00:00 vi redis.conf

Root 15590 1 0 18:52? 00:00:00 redis-server *: 7000 [cluster]

Root 15616 19443 0 18:52 pts/1 00:00:00 grep redis

Linux-svnfile:/usr/local/cluster # redis-cli-p 7000

127.0.0.1PUR 7000 >

Delete a slave nod

Delete a master nod

Linux-svnfile:/usr/local/redis # redis-trib.rb reshard 127.0.0.1:7001

How many slots do you want to move (from 1 to 16384)? 5461

What is the receiving node ID? 42929649e533ec8aad7cbb81f204f04c849d4bff

Please enter all the source node IDs.

Type 'all' to use all the nodes as source nodes for the hash slots.

Type 'done' once you entered all the source nodes IDs.

Source node # 1: 6fe9561e605b7ee85e67a2557f7fb641f482afb4

Source node # 2:done

# Do you want to proceed with the proposed reshard plan (yes/no)? Yes

Description:

5461 indicates that you want to delete all the slot quantity of master

What is the receiving node ID refers to the node-id of node 7001 that migrates the slot of 7000

Source node # 1 refers to the node-id of the master to be deleted

Below, you can see that the slot of 7000 is 0, while 7001 is more than 4561.

The error shown below occurs when deleting the master node because the slave node of the master node was not deleted before deleting the master node.

The above is a cluster done on a single machine, and the following shows a cluster on two machines, which is actually very simple.

Refer to the previous environment to compile the source code to another machine

Edit the configuration file on both machines

/ usr/local/redis # vi redis.conf

Daemonize yes

Port 7000

Cluster-enabled yes

Cluster-config-file nodes.conf

Cluster-node-timeout 5000

Appendonly yes

Cluster-config-file nodes-7001.conf

Create directories and files respectively

Linux-svnfile:/usr/local/redis # mkdir-p/usr/local/cluster/ {7001.. 7003}

Localhost:/usr/local/redis # mkdir-p/usr/local/cluster/ {8001.. 8003}

Linux-svnfile:/usr/local/redis # cpredis.conf.. / cluster/7001

Linux-svnfile:/usr/local/redis # cpredis.conf.. / cluster/7002

Linux-svnfile:/usr/local/redis # cpredis.conf.. / cluster/7003

Localhost:/usr/local/redis # cp redis.conf../cluster/8001

Localhost:/usr/local/redis # cp redis.conf../cluster/8002

Localhost:/usr/local/redis # cp redis.conf../cluster/8003

Modify the configuration file of the corresponding directory where port and cluster-config-file correspond to their respective directory names respectively, which can be modified using the sed command

Sed-I "s Universe 7001max 7002Universe g"

Start the service

This is the answer to the question on how to build the redis environment. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report