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
[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
[root@localhost local]# cd redis-5.0.3 [root@localhost redis-5.0.3]# make
[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis
[root@localhost redis-5.0.3]# cd /usr/local/redis/bin/ [root@localhost bin]# ./redis-server
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
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!