Home  >  Article  >  Database  >  How to quickly install Redis and set up self-starting

How to quickly install Redis and set up self-starting

WBOY
WBOYforward
2023-05-29 10:43:061356browse

Analysis

There are two relatively practical solutions:

One is to install redis through docker and hook the configuration file to the local file through the data volume.

The second is to use shell scripts to help us complete these mechanized operations.

The first type is very unfriendly to novices. You need to check more information and try more mistakes. If you are eager to complete the task, it will cause you more trouble. In order to really help everyone, this article will talk about the second type and go directly to the topic.

Write a script

First, enter any directory on the server and execute the following command:

vi redis-install.sh

Enter the vi editor, click i to open the editing mode, and paste the following code in (version , change the installation directory according to your needs):

#!/bin/bash

version="6.2.2"echo "==========检查并安装gcc=========="yum install -y gcc

echo "==========切换目录=========="cd ~echo "==========下载压缩包=========="wget https://download.redis.io/releases/redis-${version}.tar.gzecho "==========解压到当前目录=========="tar xzf redis-${version}.tar.gz

echo "==========删除无用文件=========="rm redis-${version}.tar.gz

echo "==========切换目录=========="cd redis-${version}

echo "==========开始编译=========="make

echo "==========开始安装=========="make install PREFIX=/usr/local/redis

echo "==========配置文件=========="cp ~/redis-6.2.2/redis.conf /usr/local/redis/bin/echo "==========安装完成=========="

Then: press esc - enter colon - enter wq - enter

Installation and configuration

shell script It has been written and executed through the sh command:

sh redis-install.sh

When the execution is completed, the installation operation is completed.

Then switch to the installation directory:

cd /usr/local/redis/bin

There is a redis.conf file in this directory. Open and modify the following items (according to your needs):

//是否允许后台启动daemonize no 改为 yes//设置密码requirepass your password//允许的最大物理存储空间(示例为1gb)maxmemory 1073741824//淘汰规则,规定空间不够用时如何淘汰已有键maxmemory-policy volatile-ttl

Service self-start

Switch to any directory and execute the following command to create a new service:

vi /etc/systemd/system/redis.service

Same as vi just now, press i to enter edit mode, and then copy the following code:

[Unit]
Description=redisAfter=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true[Install]
WantedBy=multi-user.target

Press esc - enter colon - enter wq - click Enter.

Then reload the local service:

systemctl daemon-reload

Start the service just handwritten:

systemctl start redis.service

Set the startup:

systemctl enable redis.service

If there is no feedback, it means startup Successfully, you can use the client software to link and test.

The above is the detailed content of How to quickly install Redis and set up self-starting. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete