Install the Redis database in the CentOS 7 environment

  • 2020-05-17 06:52:47
  • OfStack

As we know, Redis is an open source, BSD license-based, in-memory, key-value store NoSQL database. Redis is often considered a data structure server because Redis supports data structures such as string strings, hash hashes, list lists, collection sets, ordered set sorted sets, and so on. Redis also supports data types such as transaction Transitions, publish, and subscribe. For this reason, Redis is often considered the more powerful Memcache.

This article focuses on the differences in the installation of Redis in the CentOS 7 environment. Assume that CentOS 7 Server is ready.

1. Enable EPEL warehouse


## RHEL/CentOS 7 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# rpm -ivh epel-release-7-5.noarch.rpm

To verify that the EPEL warehouse was set up successfully, execute:


# yum repolist

2. Install Redis via Yum


# yum -y update
# yum install redis php-pecl-redis

Add Redis to startup service:


# systemctl start redis-server.service
# systemctl enable redis-server.service

Check whether Redis is running:


# systemctl is-active redis-server.service

3. Install Web management client of Redis

phpRedisAdmin is a free and open source RedisWeb management client that provides a simple interface to manage the Redis database.


# git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
# cd phpRedisAdmin/includes
# cp config.sample.inc.php config.inc.php

Make sure the configuration is correct:


# nano config.inc.php

Then add the RedisAdmin configuration file to the Apache server. The content of the file is as follows:


### nano /etc/httpd/conf.d/redisadmin.conf
### Now add the following ###
#
# Web Interface for RedisAdmin
# 

<Directory "/downloads/phpRedisAdmin/">
 Order Deny,Allow
 Deny from all
 Allow from 127.0.0.1
 Allow from <your ipaddress>
</Directory>

Alias /redisAdmin /downloads/phpRedisAdmin
Alias /redisadmin /downloads/phpRedisAdmin

Create an Bash script to ensure that Redis is running properly, as follows:


### nano /scripts/redis-check.sh
#!/bin/bash
PS=$(which ps)
GREP=$(which grep)
WHEN=$(date +"%Y-%m-%d-%H:%M:%S")
  if ! $PS aux | $GREP "redis.conf" | $GREP -v grep 2>&1 > /dev/null; then
    /etc/init.d/redis restart
    echo 'Restarted Redis @' $WHEN
  fi
#Check Second instance
  if ! $PS aux | $GREP "redis2.conf" | $GREP -v grep 2>&1 > /dev/null; then
    /etc/init.d/redis2 restart
    echo 'Restarted Redis2 @' $WHEN
  fi

Make sure the script is executable:


# chmod +x /scripts/redis-check.sh

Ensure the execution of the script through the timer cron, running once every 3 minutes:


# yum repolist
0

OK, that's it.

The original link: http: / / blog csdn. net/chszs/article/details / 51925378


Related articles: