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

Installation and deployment of Redis

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "installation and deployment of Redis". In daily operation, I believe many people have doubts about the installation and deployment of Redis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "installation and deployment of Redis"! Next, please follow the editor to study!

First, install Redis

This document is based on CentOS 7.6.1810. Due to the large number of Linux distributions, the installation process may be slightly different, for reference only.

1. Download the Redis source code: wget http://download.redis.io/releases/redis-4.0.14.tar.gz

2. Decompress: tar xzf redis-4.0.14.tar.gz

3. Enter the directory: cd redis-4.0.14/

4. Compile: make-j 4 (4 means to compile with 4 cores. The default is 1 core. Please modify the parameters according to the actual situation)

The compilation is successful when you see the following prompt

2. Deploy stand-alone Redis

1. Use the cd command to change the directory to the Redis home directory

2. Create a folder to store stand-alone data and configuration: mkdir single

3. Copy a configuration file to the single folder: cp redis.conf single/redis.conf

4. Change to the single directory: cd single/

5. Use your familiar editor to modify the redis.conf file

The configurations that may need to be modified are as follows:

Line 69: bind 127.0.0.1 (whitelist configuration, only client connections for specified IP are allowed Comment out line 88: protected-mode yes (yes means only local connections are allowed) line 92: port 6379 (port number) line 136: daemonize no (changed to yes for background operation) line 158: pidfile / var/run/redis_6379.pid (the following number is changed to the same as the port number) line 171: logfile "" (log path, specified as ${redis.home} / single/redis.log, must be an absolute path ${redis.home} indicates the installation directory of redis, which must be configured. Line 218: RDB persistent configuration, all commented out and added save "" means to turn off RDB persistence save 9001 (1 key modification every 900s) save 30010 (persisted with 10 key changes every 300s) save 60 10000 (persisted with 10000 key changes every 60 seconds) line 263: dir. / (indicates the saved directory of RDB files The absolute path to single needs to be modified, otherwise it will be saved in src and must be configured) Line 500: requirepass foobared (set the password of redis, comment out indicates no need) Line 559: maxmemory (maximum memory consumption of redis, according to the actual situation, in bytes, memory is not limited if commented out, but it is still limited by system available memory) Line 590: maxmemory-policy noeviction (cache clearing policy, when memory is full Will trigger this policy, clear part of the key, do not clear by default, but report errors on write requests) there are mainly two strategies: volatile-lru: use the LRU algorithm to clear the cache with expiration time, LRU is to clear the cache that has not been used for a long time, volatile-lfu: use the LFU algorithm to clear the cache with expiration time, and LFU clears the rarely used cache line 672: appendonly no (whether AOF persistence is enabled)

6. Create a new file in the single directory: touch start.sh and add the following

#! / bin/sh# Note this directory refers to your actual redis installation directory cd / home/iceberg/Program/redis-4.0.12src/redis-server single/redis.conf

Give it executable permission chmod 777 start.sh, run it and start it.

7. Close redis

Do not use the Kill-9 method to force Redis shutdown, not only Redis, any program should not be closed in this way! This will prevent the program's default cleanup code from being executed!

Create a new file in the single directory: touch stop.sh and add the following

#! / bin/shcd / home/iceberg/Program/redis-4.0.12src/redis-cli-p 6379 shutdown III. Deploy master / slave Redis

1. Use the cd command to change the directory to the Redis home directory

2. Create a folder to store the master / slave data and configuration: mkdir replication

3. Enter the directory: cd relication

4. Create two folders: mkdir master slave

5. Change to the home directory and copy the configuration files to master, slave,cp redis.conf replication/master/redis.conf and cp redis.conf replication/slave/redis.conf, respectively.

6. Most of the master-slave configuration is the same as the stand-alone version, which must be modified as follows

Line 92: port 6379 (port number, master and slave port numbers must be different) Line 171: logfile "(log path, specified as ${redis.home} / replication/master or slave/redis.log, must be absolute, ${redis.home} indicates the installation directory of redis, must be configured) Line 263: dir. / (represents the directory where the RDB file is saved, which needs to be changed to the absolute path of master or slave, otherwise it will be saved in src (must be configured) Line 281: slaveof (configure the ip and port number of the primary node) Line 288: masterauth (if the primary node is configured with a password, the same password should be configured here, otherwise it will not be connected)

7. The startup and shutdown scripts are also the same as the stand-alone version

IV. Deploy Sentinel Redis

1. Use the cd command to change the directory to the Redis home directory

2. Create a folder to store Sentinel data and configuration: mkdir sentinel

3. First configure the master and slave nodes, and start

4. Create three folders: mkdir sentinel1 sentinel2 sentinel3

5. Copy sentinel.conf to three folders (note that the configuration file here is not redis.conf! )

6. The areas that need to be modified are as follows

Line 21: port 26379 (port number) Line 50: dir / tmp (data storage directory) Line 69: sentinel monitor mymaster 127.0.0.1 6379 2 (configure which master node to monitor. Mymaster is the alias of the master node. 2 means that the master-slave switch requires the consent of at least two sentinel nodes. Generally, the number of sentinel nodes is denoted by the number of sentinel nodes.

7. Create a new file in the sentinel1 folder, touch start.sh, and fill in the following

#! / bin/sh# Note this directory refers to your actual redis installation directory cd / home/iceberg/Program/redis-4.0.12src/redis-sentinel sentinel/sentinel1/sentinel.conf

Give it executable permission chmod 777 start.sh, run it and start it.

8. Disable Redis is the same as the stand-alone version, and configure the port number.

5. Configure cluster version of Redis

1. Use the cd command to change the directory to the Redis home directory

2. Create a folder to store the data and configuration of cluster version: mkdir cluster

3. Prepare the pre-environment

Just enter the following command. Although the official website says this is an older version, it can be used.

Sudo yum install ruby

After the installation is complete, enter the following instructions to appear the version number and the installation is successful.

Ruby-v

Install rubygem redis dependencies

Wget http://rubygems.org/downloads/redis-3.3.0.gemgem install-l redis-3.3.0.gem

Once all installed, go to the {redis.home} / src directory and execute

. / redis-trib.rb

If the following message appears, it will succeed

4. Create six new folders (at least three masters and three slaves in the Redis cluster), mkdir cluster1 cluster2 cluster3 cluster4 cluster5 cluster6, and copy the redis.conf file into it

5. The cluster-related configurations are as follows, and the rest are the same as the stand-alone mode.

# Node port port 638 enables cluster-enable yes# node timeout in cluster mode (in millisecond cluster-node-timeout 1500pm). Cluster internal configuration file cluster-config-file "nodes-6381.conf"

6. Using the stand-alone startup script will start the above six redis instances

7. Change to the home directory and execute (the port number can be modified by yourself)

#-- replicas is used to specify that each master node in the cluster is equipped with several slave nodes src/redis-trib.rb create-- replicas 1 127.0.0.1Plus 6381 127.0.0.1replicas 6382 127.0.1Plus 6383 127.0.0.1 replicas 6384 127.0.16385 127.0.0.16386

The results are as follows

Enter yes

It was found that all 16384 slots were allocated successfully and the cluster was created.

8. Cluster integrity check

Cluster integrity means that all slots must be allocated to the surviving primary node, and as long as one of the 16384 slots is not allocated to the node, the cluster is incomplete. We can use the redis-trib.rb check command to detect any node to complete the check, enter:

Src/redis-trib.rb check 127.0.0.1:6381

The above prompt indicates that the cluster is complete.

At this point, the study on "installation and deployment of Redis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Internet Technology

Wechat

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

12
Report