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 and configure public network accessibility for CentOS7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "CentOS7 how to install redis and configure external network accessibility", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "CentOS7 how to install redis and configure public network accessibility" article.

1. Install the gcc editor

The installation of redis depends on the gcc environment, execute the following command to install:

Yum install-y gcc

If the machine does not have a network, you can refer to this article:

CentOS offline installation gcc environment (with installation package + illustrated)

2. Download the redis installation package

Redis official website: https://redis.io/download

Download and upload to CentOS, such as / usr/local/

3. Decompress and compile and install redis

The instruction commands are as follows:

1. Enter the installation package directory cd / usr/local/2, extract the installation package tar-zxvf redis-6.2.1.tar.gz3, enter the extracted redis directory and compile cd redis-6.2.1make

4. Install to the specified directory

Install redis to the specified directory and modify the path, as shown below: / usr/local/redis:

Make install prefix=/usr/local/redis

4. Start redis

There are two ways to start redis, one is the foreground interface, as long as the interface is closed, and the other is the background startup.

4.1. The foreground interface starts

Go to the bin directory of the redis installation directory:

Cd / usr/local/redis/bin

At this point, you can start simply by executing the following command:

. / redis-server

The screenshot of launch is as follows:

The problem at this time is that we don't know where the startup configuration file is.

In fact, we can check it out directly through the find command:

Find /-name 'redis.conf'

The results are as follows:

The foreground startup mode is not very common, as long as the interface is closed, the redis will stop.

4.2. Start the backend service.

We copy a redis.conf file from the previously unzipped installation package to the redis installation directory.

Cp / usr/local/redis-6.2.1/redis.conf / usr/local/redis/bin/

Then modify the thread mode parameters of the redis.conf configuration file:

Vi / usr/local/redis/bin/redis.conf

PS:vi shortcut key, press /, and then enter [keyword] to query the parameters.

Mainly modify the corresponding value of daemonize to yes

1. Daemonize no 2 before modification, daemonize yes after modification

The explanation of the value of this parameter:

Yes:redis adopts the mode of single-process and multi-threading. When the option daemonize in redis.conf is set to yes, daemon mode is enabled. In this mode, redis runs in the background and writes the process pid number to the file set by the redis.conf option pidfile, and redis runs all the time unless you manually kill the process.

No: when the daemonize option is set to no, the current interface will enter the command line interface of redis. Forcing exit to exit or closing the connection tool (putty,xshell, etc.) will cause the redis process to exit.

After modification, save and exit.

Start redis again by executing the following command:

. / redis-server redis.conf

At this point, redis is started in the background.

5. Set access to the public network

The default configuration file does not support public network access. Next, modify the parameters of public network access.

Or modify the configuration file:

Vi / usr/local/redis/bin/redis.conf

Find the following three parameters:

Bind 127.0.0.1 (bind the ip allowed to be accessed)

Protected-mode yes (protected mode on)

# requirepass yourpassword (password for requesting access)

One or two items are combined items, which are particularly important, and the third item is to set a password to protect the service area to a certain extent.

Modify it as follows:

# bind 127.0.0.1

Protected-mode no

Requirepass, your password.

After modification, save and exit.

6. Register for redis service

It is very troublesome to start and close redis every time, so it is better to register as a service directly.

Execute the following command to create the redis service:

Vi / etc/systemd/system/redis.service

Add the following command:

[Unit] Description=redis-serverAfter=network.target [Service] Type=forkingExecStart=/usr/local/redis/bin/redis-server / usr/local/redis/bin/redis.confPrivateTmp= true[Install] WantedBy=multi-user.target

The redis-server in the installation Redis directory corresponding to the ExecStart parameter is the same as the configuration file above.

Set up boot boot:

Systemctl daemon-reloadsystemctl start redis.servicesystemctl enable redis.service7, commonly used service commands start redis service systemctl start redis.service stop redis service systemctl stop redis.service restart service systemctl restart redis.service view service current status systemctl status redis.service setting boot self-start systemctl enable redis.service stop boot self-start systemctl disable redis.service above is about "CentOS7 how to install redis and configure public network access" this article, I believe we all have a certain understanding I hope the content shared by the editor will be helpful to all of you. If you want to know more about the relevant knowledge, please 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