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 install Redis under Linux

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "how to install Redis under Linux", the content is easy to understand, clear, hope to help you solve your doubts, let the editor lead you to study and learn "how to install Redis under Linux" this article.

Redis is a high-performance key-value database. The emergence of redis makes up for the deficiency of keyvalue storage such as memcached to a great extent, and can play a good complementary role to relational database in partial situations.

Installation environment Redis version 5.0.4

Server version Linux CentOS 7.6 64-bit

Install Redis under Linux step by step download Redis go to the official website and find the download address https://redis.io/download

Right-click the Download button and select copy link. Go to the Xshell console (default is the root root directory), and type wget to paste the download link copied above, as follows:

Wget http: ``/ / download.redis.io/releases/redis-5.0.7.tar.gz: enter the enter key and execute it as shown below:

Wait for the download to complete.

Extract and install Redis to extract

After the download is complete, you need to extract the compressed file. Enter the following command to extract it to the current directory.

After the tar-zvxf redis-5.0.7.tar.gz is unzipped, type ls on the root directory to list all directories and you will find that there is an extra redis-5.0.7.tar.gz file and redis-5.0.7 directory before downloading redis.

Move the redis directory

The redis directory is usually placed in the / usr/local/redis directory, so enter the following command here to change the directory of the redis-5.0.7 folder currently in the / root directory and change the folder name to redis.

Enter the ls command from mv / root/redis-5.0.7 / usr/local/rediscd to / usr/local directory to find that there is already one more redis subdirectory in the current directory, and there is no redis-5.0.7 folder in the / root directory.

Compile

Cd to the / usr/local/redis directory, enter the command make to execute the compilation command, and then the console will output the output from various compilation processes.

The final running result of make is as follows:

Installation

Enter the following command

Make PREFIX=/usr/local/redis install there is an extra keyword PREFIX= which is used to specify the path to which the program is stored when compiling. For example, we now specify that redis must be stored in the / usr/local/redis directory. Suppose that not adding the keyword Linux will store the executable in the / usr/local/bin directory

The library files are stored in the / usr/local/lib directory. The configuration file is stored in the / usr/local/etc directory. Other resource files are stored in the usr/local/share directory. The directory specified here is also convenient for subsequent uninstallation, and the redis can be deleted by directly rm-rf / usr/local/redis.

The execution result is as follows:

Starting redis has finished installing redis according to the above actions. Enter the following command in the directory / usr/local/redis to start redis

?

. / bin/redis-server&. / redis.conf

The above startup mode is the background process mode, and the following is the display startup mode (for example, setting the daemonize attribute to yes in the configuration file is the same as starting in the background process mode).

?

The difference between the two ways of. / bin/redis-server. / redis.conf is nothing more than the difference between signed and unsigned. Redis-server is followed by a configuration file that aims to start the redis service based on the configuration of the configuration file. Redis.conf configuration files allow you to customize multiple configuration files by specifying which one to read at startup.

The redis.conf configuration file has a redis.conf configuration file in the directory / usr/local/redis. The above startup mode is run by executing the configuration of the configuration file. We can read the file through the built-in read commands of cat, vim, less and other Linux.

You can also read all configuration items through CONFIG GET * after entering the redis console through the redis-cli command. As follows:

Redis- cli`CONFIG GET *

All configuration items will be read after enter confirmation, as shown in the following figure

Here are the more important configuration items

The configuration item name configuration item value range indicates that daemonizeyes and noyes means that the daemon is enabled. The default is no, that is, it does not run as a daemon. Running port with daemon enabled is not supported under Windows system.

Specifies the Redis listening port. The default port is 6379bind

The bound host address. If you need to set remote access, you can directly comment on this attribute or change it to bind *. This attribute and the following protected-mode control whether it can be accessed remotely. Protected-modeyes and no protection mode, which controls whether the external network can connect to the redis service. The default is yes, so by default, our public network is inaccessible. If you need to connect to the rendis service through the public network, you need to change this attribute to no. Timeout300 closes the connection when the client has been idle for how long. If 0 is specified, the log level of logleveldebug, verbose, notice and warning is disabled. The default is the number of databases set by noticedatabases16. The default database is 0. The whole rdbcompressionyes can be seen through the client tool, and no specifies whether to compress the data when it is stored in the local database. The default is that yes,Redis uses LZF compression. If you want to save CPU time, you can turn off this option, but it will cause the database file to become huge. Dbfilenamedump.rdb specifies the local database file name, and the default value is dump.rdbdir

Specify the local database storage directory requirepass

Set the Redis connection password. If the connection password is configured, the client needs to provide a password through the AUTH command when connecting to the Redis. By default, turn off maxclients0 to set the maximum number of client connections at the same time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that can be opened by the Redis process. If maxclients0 is set, there is no limit. When the number of client connections reaches the limit, Redis closes the new connection and returns a max number of clients reached error message to the client. MaxmemoryXXX specifies the maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the expired or expiring Key. When this method is processed, the maximum memory setting is still reached, and no more write operations can be performed, but read operations can still be performed. Redis's new vm mechanism stores Key in memory and Value in the swap area. XXX is a value in the range of configuration item values. Show details

Here I'm going to change daemonize to yes, otherwise I will have to add a symbol after the redis-server command every time I start, otherwise the redis service will automatically shut down as soon as I return to the Linux console, and I will also comment bind and set protected-mode to no. In this way, I can access it on the external network after starting it.

Change method:

Vim / usr/local/redis/redis.conf finds the attribute through / daemonize. The default is no, and you can change it to yes. (if multiple results appear through the / keyword search, you can use the n character to switch to the next one. Enter: noh returns to normal mode after finding the result.)

As shown below:

The other two properties can be found and edited in the same way.

Check whether Redis is running. 1. View the process.

Ps-aux | the grep redis result is shown below:

2. Take port monitoring and viewing mode.

Netstat-lanp | grep 6379 results as shown below:

Redis-cliredis-cli is a command to connect to the local redis service, which allows you to anger redis's scripting console. The figure below is as follows

Enter exit to exit the redis script console

Close the running Redis service enter redis-cli to enter the console and enter the command shutdown to shut down the running Redis service. As shown below:

There is no problem with remote connection as shown in the figure below. The ip of Redis service is not 127.0.0.1. Theoretically, the remote client should be able to connect, and the port number of the CVM is also open in the security group.

Later, it is found that there is a problem with the startup command, because I am relatively lazy, I directly enter the command redis-server or redis-server& to start the redis, both of which directly read the default configuration file to start, but the former shows that the latter is launched as a background application. I am actually very puzzled, because I changed the default configuration file, I did not regenerate the new configuration file, but it is true that I type the command redis-server / usr/local/redis/etc/redis.conf is successful, and I enter the command redis-server& / usr/local/redis/etc/redis.conf is also a remote login failure. With regard to the problem that it is not possible to enter redis-server directly, I also wonder if it is the Linux cache problem, so I will try to restart the server. The result is still the same. Ah, let's not worry about it before we find out the reason.

The above is all the contents of the article "how to install Redis under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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