Welcome 微信登录

首页 / 数据库 / MySQL / CentOS 7环境下安装Redis

正如我们所知的那样,Redis是一个开源的、基于BSD许可证的,基于内存的、键值存储NoSQL数据库。Redis经常被视为一个数据结构服务器,因为Redis支持字符串strings、哈希hashes、列表lists、集合sets、有序集sorted sets等数据结构。Redis还支持像事务Transitions、发布和订阅这样的数据类型。有鉴于此,Redis经常被认为是更强大的Memcache。本文主要讲述Redis在CentOS 7环境下的安装有什么不同。假定CentOS 7 Server已经就绪。

1、启用EPEL仓库

## 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要验证EPEL仓库是否建立成功,可以执行:# yum repolist

2、通过Yum安装Redis

# yum -y update# yum install redis php-pecl-redis把Redis添加到开机启动服务中:# systemctl start redis-server.service# systemctl enable redis-server.service检查Redis是否运行:# systemctl is-active redis-server.service

3、安装Redis的Web管理客户端

phpRedisAdmin是一个免费开源的RedisWeb管理客户端,它提供了一个简单的界面来实现对Redis数据库的管理。# git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git# cd phpRedisAdmin/includes# cp config.sample.inc.php config.inc.php要确保配置正确:# nano config.inc.php再把RedisAdmin配置文件添加到Apache服务器,文件的内容如下:### nano /etc/httpd/conf.d/redisadmin.conf### Now add the following #####Web Interface for RedisAdmin# <Directory "/downloads/phpRedisAdmin/">Order Deny,AllowDeny from allAllow from 127.0.0.1Allow from <your ipaddress></Directory>Alias /redisAdmin /downloads/phpRedisAdminAlias /redisadmin /downloads/phpRedisAdmin创建一个Bash脚本来确保Redis的正常运行,内容如下:### nano /scripts/redis-check.sh#!/bin/bashPS=$(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确保脚本是可执行的:# chmod +x /scripts/redis-check.sh通过定时器cron来保证脚本的执行,每3分钟运行一次:### nano /var/spool/cron/root*/3 * * * * /bin/bash /script/redis-check.sh >> /var/log/redis-check.logOK,至此完工。本文永久更新链接地址