Install Redis on Windows (configuration to start automatically at boot + configure password)

background

Redis is very popular for its excellent performance. It has always been a software that developers cannot live without. I believe that those who are willing to click on this article have recently needed to
build various project running environments on Windows servers , including Redis because You may instruct others to install it in the future, so simply record the tutorial document in the form of a blog.

Install

This article only introduces the installation of Redis under Windows. For other methods and introduction to the use of Redis, please click the blue link to view: For
installation under Linux, see: Chapter 2 of Redis Technology.
For installation under Docker, see: Chapter 7 of Docker Technology.

  1. Download address: github
    requires a VPN. If you don’t have a VPN, you can download the resource attachments bound to this blog.
    Insert image description here

  2. After installing the
    downloaded .msiimage installation file, double-click to install. As shown below, just click nextps
    Insert image description here
    : If the installation location is not set manually, the default location is in C:\Program Files\Redisthe directory (will be used below).
    Add it to the system environment variable, so that it can be used in cmd Connect through the local shell under the command
    Insert image description here

  3. To access redis-cli,
    you can double-click to open it C:\Program Files\Redisin the directory redis-cli.exe
    , or you can cmdopen the command line and enter redis-cli -h 127.0.0.1to access ( you need to check the box above and add it to the system environment variable )
    Insert image description here

Configuration

Start automatically at boot

In Windows, all running programs run as services,
so we only need to hand over the service to the system for hosting and the system will automatically restart.

  1. For service management,
    Win+Rpress the key combination to enter the running window, enter services.mscto enter the service management page, find Redis, and check whether the startup type
    of the Redis service is automatic . Automatic means that it is handed over to the system for hosting. When the system restarts or starts, it will automatically start something like Spring. Inject the bean into Spring. The container automatically manages the bean life cycle (creation and destruction, etc.). ps: If the startup type is manual, double-click the service and reselect the startup type to automatic .

    Insert image description here

    Insert image description here

Supplement: Configure jar to start automatically in Windows

For some reasons, the jar package cannot be registered with the service after startup, so we cannot configure auto-start in the above way. Therefore, using the
Windows Scheduler to automatically execute Windows scripts to start the project has become the first choice. The steps are as follows

  1. Prerequisite: To run the jar package, you need to install jdk and configure environment variables
    Insert image description here

  2. Writing Windows startup scripts .bat
    chcp 65001can avoid garbled content in the window display.

    chcp  65001
    
    @title 运行时左上角的shell窗格名称
    java  -jar  jar名称
    pause
    
  3. Find computer management
    Insert image description here

  4. Create basic tasks
    Insert image description here

  5. Set task name and description
    Insert image description here

  6. Set task trigger conditions
    Insert image description here

  7. Set task action
    Insert image description here

  8. Specify task startup script/batch program
    Insert image description here

set password

Please choose temporary configuration or permanent configuration according to the actual situation such as whether your Redis service will be restarted.

temporary

The advantage of setting the password through redis-cli is that it takes effect without restarting, but the disadvantage is that it becomes invalid after restarting. I configured it like this before I needed to reconfigure it,
but because Windows restarts irregularly, I need to manually configure the password again after restarting. There are still some problems. Troublesome

  1. In redis-cliManual Settings
    open redis-cli.exe, enterCONFIG SET requirepass "密码"

  2. Enter auth 密码to verify whether the password is successful
    Insert image description here

Permanent (recommended)

Setting the password under redis-cli has the opposite advantages and disadvantages than the temporary effective method. It
will also take effect after a restart. The disadvantage is that it must be restarted after configuration.

  1. Check which configuration file is used when the Redis service starts.
    When configuring the above configuration to start automatically, we can check in the service details which configuration file is used when the Redis service starts.
    win+R->cmd->services.msc->Redis We can see that the configuration file in the Redis installation directory is used redis.windows-service.conf
    . We need to redis.windows-service.confmodify this file
    Insert image description here
    ps: If there is no configuration file address here, then we can manually close it and open a shell in the Redis installation directory
    ./redis-server.exe --service-install redis.windows-service.conf

  2. After finding the file, perform a global search and search requirepassto find the following area
    Insert image description here

  3. After configuration, while still on the service page, restart the service and be
    careful not to click on the wrong service, which will give you the illusion that the configuration file is configured but invalid!!!
    Insert image description here

  4. rediis-cliVerify whether it takes effect
    Insert image description here


Reference blog
https://blog.csdn.net/Itmastergo/article/details/131569908
https://blog.csdn.net/gmm313/article/details/129835401
https://blog.51cto.com/ios9/5374277

Guess you like

Origin blog.csdn.net/qq_43371556/article/details/131847600