Home> Database> Redis> body text

How to quickly install Redis and set up self-starting

WBOY
Release: 2023-05-29 10:43:06
forward
1319 people have browsed it

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
Copy after login

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 "==========安装完成=========="
Copy after login

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
Copy after login

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

Then switch to the installation directory:

cd /usr/local/redis/bin
Copy after login

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
Copy after login

Service self-start

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

vi /etc/systemd/system/redis.service
Copy after login

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
Copy after login

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

Then reload the local service:

systemctl daemon-reload
Copy after login

Start the service just handwritten:

systemctl start redis.service
Copy after login

Set the startup:

systemctl enable redis.service
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!