Home > Database > Redis > body text

A brief discussion on how to install Redis on Centos 7

青灯夜游
Release: 2021-04-15 11:30:46
forward
1592 people have browsed it

This article will show you how to install Redis on Centos 7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on how to install Redis on Centos 7

Without further ado, let’s get started.

1. Install gcc dependencies

redis is developed in C language. Before installation, you must first confirm whether the gcc environment is installed (gcc -v) , if it is not installed, execute the following command to install it.

$ yum install -y gcc
Copy after login

2. Download and decompress the installation package

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

$ tar -zxvf redis-5.0.7.tar.gz
Copy after login

3. cd to the redis decompression directory and execute compilation

$ cd redis-5.0.7 && make
Copy after login

4. Install and specify the installation directory

$ make install PREFIX=/usr/local/redis
Copy after login

[Related recommendations: Redis video tutorial]

5. Start the service

5.1 Foreground startup

$ cd /usr/local/redis/bin/

$ ./redis-server
Copy after login

5.2 Background startup

Copy redis.conf from the redis source code directory to The installation directory of redis

$ cp /usr/local/redis-5.0.7/redis.conf /usr/local/redis/bin/
Copy after login

Modify the redis.conf file and change daemonize no to daemonize yes

$ vim redis.conf

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
Copy after login

Background startup

$ ./redis-server redis.conf
Copy after login

6. Set up boot startup

Add startup service

$ vim /etc/systemd/system/redis.service
Copy after login

Add the following content

[Unit]
Description=redis-server
After=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

Note: ExecStart Configure to your own path

Set startup

$ systemctl daemon-reload

$ systemctl start redis.service

$ systemctl enable redis.service
Copy after login

Create redis command soft link

$ ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

# 测试
$ redis

127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
Copy after login

Finally, post some common commands~

# 启动redis服务
systemctl start redis.service

# 停止redis服务
systemctl stop redis.service

# 重新启动服务
systemctl restart redis.service

# 查看服务当前状态
systemctl status redis.service

# 设置开机自启动
systemctl enable redis.service

# 停止开机自启动
systemctl disable redis.service
Copy after login

OK~It’s done~

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of A brief discussion on how to install Redis on Centos 7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template