Home  >  Article  >  Database  >  How to install redis on centos7

How to install redis on centos7

WBOY
WBOYforward
2023-06-02 17:20:581796browse

1. Install gcc dependencies

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

 [root@localhost local]# yum install -y gcc

2. Download and decompress the installation package

[root@localhost local]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz

[root@localhost local]# tar -zxvf redis-5.0.3.tar.gz

3. cd to the redis decompression directory and execute compilation

[root@localhost local]# cd redis-5.0.3

[root@localhost redis-5.0.3]# make

4. Install and specify the installation directory

[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis

5. Start the service

5.1 Foreground startup

[root@localhost redis-5.0.3]# cd /usr/local/redis/bin/

[root@localhost bin]# ./redis-server

5.2 Background startup

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

[root@localhost bin]# cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/

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

[root@localhost bin]# vi redis.conf

Background startup

[root@localhost bin]# ./redis-server redis.conf

6. Set boot startup

Add boot startup service

[root@localhost bin]# vi /etc/systemd/system/redis.service

Copy and paste 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 is configured to its own path

Set up for startup

[root@localhost bin]# systemctl daemon-reload

[root@localhost bin]# systemctl start redis.service

[root@localhost bin]# systemctl enable redis.service

Create a redis command soft link

[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

Test redis

Service operation command

systemctl start redis.service   #启动redis服务

systemctl stop redis.service   #停止redis服务

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

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

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

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

The above is the detailed content of How to install redis on centos7. 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