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

Vue plugin error: Vue.js is detected on this page. Problem solved

Vue plugin reports an error: Vue.js is detected o...

The correct way to migrate MySQL data to Oracle

There is a table student in the mysql database, i...

Steps to introduce PWA into Vue project

Table of contents 1. Install dependencies 2. Conf...

An article to help you understand the basics of VUE

Table of contents What is VUE Core plugins in Vue...

Steps of an excellent registration process

For a website, it is the most basic function. So l...

Solution to leaving gaps between BootStrap grids

Table of contents [See an example]: [The original...

js to achieve the effect of dragging the slider

This article shares the specific code of how to d...

MySQL paging query optimization techniques

In applications with paging queries, queries that...

Some tips for writing high-performance HTML applications

How can you improve web page performance? Most de...

Detailed explanation of the difference between tinyint and int in MySQL

Question: What is the difference between int(1) a...

mysql 8.0.15 winx64 decompression version graphic installation tutorial

Every time after installing the system, I have to...

Detailed steps to install MySQL 8.0.27 in Linux 7.6 binary

Table of contents 1. Environmental Preparation 1....

MySQL learning record: bloody incident caused by KEY partition

Demand background Part of the data in the busines...

How to modify the root password of mysql under Linux

Preface The service has been deployed on MySQL fo...

Complete steps for Nginx to configure anti-hotlinking

need: Usually, sites want to prevent videos and p...