Home  >  Article  >  Database  >  A brief discussion on how to install Redis on Centos 7

A brief discussion on how to install Redis on Centos 7

青灯夜游
青灯夜游forward
2021-04-15 11:30:461579browse

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

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

3. cd to the redis decompression directory and execute compilation

$ cd redis-5.0.7 && make

4. Install and specify the installation directory

$ make install PREFIX=/usr/local/redis

[Related recommendations: Redis video tutorial]

5. Start the service

5.1 Foreground startup

$ cd /usr/local/redis/bin/

$ ./redis-server

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/

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

Background startup

$ ./redis-server redis.conf

6. Set up boot startup

Add startup service

$ vim /etc/systemd/system/redis.service

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

Note: ExecStart Configure to your own path

Set startup

$ systemctl daemon-reload

$ systemctl start redis.service

$ systemctl enable redis.service

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>

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

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!

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