Installation and daemon configuration of Redis on Windows and Linux

Installation and daemon configuration of Redis on Windows and Linux

# Installation daemon configuration for Redis on Windows and Linux

Introduction to Redis

Redis is one of the most commonly used non-relational databases (NOSql) and is often stored in the form of Key-Value. Redis's read and write speeds are much higher than relational databases (MySQL, Oracle). So it is often used as a project hot data cache

Installation and Configuration on Windows

1) Download from GitHub https://github.com/microsoftarchive/redis/releases

2) Unzip and install the redis service to support daemon (background startup)

After decompression, there are two configuration files and two executable programs in the directory

You can keep only one of the two configuration files and delete it.

redis-server.exe is the redis service

redis-cli.exe is the redis operation window

Before using redis, you must start the redis service, that is, double-click redis-server.exe. Although it can be started, you don't know which configuration file it uses, so you usually use cmd to specify the configuration file to use and start the service. like:

使用cmd進入到redis解壓出來的目錄在redis目錄下執行redis-server.exe redis.windows.conf

In this way, the redis service is started normally, and the configuration file used is redis.windows.conf, this window cannot be closed

Then double-click redis-cli.exe to open the redis command window, enter ping, and press Enter to display PONG, indicating a successful connection:

However, when using it, we will not keep a window open and then use it, so we need to register the redis service as a system service and run it in the background

Register for the reids service

使用cmd進入redis目錄運行redis-server --service-install redis.windows.conf --service-name redis

As shown in the figure, we have installed the redis service:

Start the redis service (set to start automatically)

win + R 然后輸入services.msc回車。打開服務找到redis服務啟動redis并把啟動類型修改為自動(如果不是自動的話)

Now the redis service is OK. Double-click redis-cli.exe to start the redis client to operate.

Install and configure Redis on Linux

1) Go to the redis official website https://redis.io/download and download the redis installation package

Find the address to download the latest stable version. When I installed it, it was 5.0.5: http://download.redis.io/releases/redis-5.0.5.tar.gz

Then use the wget command to download the installation package

wget http://download.redis.io/releases/redis-5.0.5.tar.gz

2) Unzip and install redis

解壓:tar -zxf redis-5.0.5.tar.gz進入redis目錄:cd redis-5.0.5編譯:make

After compilation, redis-service, redis-cli and several other executable files are generated in src

3) Start redis

在src下執行./redis-service ../redis.conf

You can see that the operation is successful


But this is started in the foreground, so we can start it as a daemon by modifying the configuration file

Edit the redis.conf configuration file under redis-5.0.5

Change daemonize to yes

Save and exit

Restart

./redis-service ../redis.conf

Already started as a daemon process

./redis-cli

It indicates that it can be used, but redis does not require a password at this time, which is absolutely not advisable on the server. And the redis password strength must be set higher

I personally experienced that the redis password was too weak and was used to implant a mining virus. I don't remember which version this bug was in, but there is absolutely no problem with a stronger password.

4) Start and stop scripts

When restarting here, I wrote two scripts to start and stop for convenience.

redis-start

#/bin/bash
/usr/local/redis/redis-server /usr/local/redis/redis.conf

The front and back are the absolute paths of redis-server and configuration file respectively. You can modify them according to your installation location.

redis-stop

#!/bin/bash
echo "redis-server will stop"
redis_pid=$(ps -ef |grep -v 'grep' | egrep /usr/local/redis/redis-server | awk '{printf $2 " "}');
if [ "$redis_pid" != "" ]; then
 kill -9 "$redis_pid"
 echo "redis-server stop"
 else
 echo "can not find redis-server"
fi
 exit 1

This also modifies /usr/local/redis/redis-server according to the location of your redis-server

After writing, just give them executable permissions.

chmod u+x redis-st*

Note: If you want to make it easier, put these two scripts in the environment variables, and then you can use these two scripts to start and stop anywhere, which is also very good.

5) Set the Redis password

Modify requirepass in redis.conf

Remove the comments and change foobared to your desired password. For demonstration purposes, I will set my password to 123456.


After modification, restart the redis service

We reconnect using redis-cli and then enter ping, it will tell you that you do not have permission

Using auth That is, for example:


Summarize

The above is the installation daemon configuration of Redis on Windows and Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Install redis database on Windows system
  • Detailed explanation of the process of installing Redis under Windows
  • Redis installation and configuration process in Windows and remote access function
  • Installation process of Redis database under Linux system
  • Detailed steps to install redis under Linux
  • Installation process and configuration method of redis5.0.5 under Linux
  • Redis installation graphic tutorial (Windows and Linux) detailed diagram

<<:  MySQL date functions and date conversion and formatting functions

>>:  Usage and difference of Js module packaging exports require import

Recommend

Vue3 draggable left and right panel split component implementation

Table of contents Breaking down components Left P...

Summary of experience in using div box model

Calculation of the box model <br />Margin + ...

Programs to query port usage and clear port usage in Windows operating system

In Windows operating system, the program to query...

MySql Sql optimization tips sharing

One day I found that the execution speed of a SQL...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...

Specific use of node.js global variables

Global Object All modules can be called global: r...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

Linux automatic login example explanation

There are many scripts on the Internet that use e...

How to implement the webpage anti-copying function (with cracking method)

By right-clicking the source file, the following c...

How to upgrade all Python libraries in Ubuntu 18.04 at once

What is pip pip is a Python package management to...

A Deep Understanding of Angle Brackets in Bash (For Beginners)

Preface Bash has many important built-in commands...

CSS3 transition to implement notification message carousel

Vue version, copy it to the file and use it <t...

MySQL Optimization Summary - Total Number of Query Entries

1. COUNT(*) and COUNT(COL) COUNT(*) usually perfo...