共计 1783 个字符,预计需要花费 5 分钟才能阅读完成。
正如我们所知的那样,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,Allow | |
Deny from all | |
Allow from 127.0.0.1 | |
Allow from <your ipaddress> | |
</Directory> | |
Alias /redisAdmin /downloads/phpRedisAdmin | |
Alias /redisadmin /downloads/phpRedisAdmin |
创建一个 Bash 脚本来确保 Redis 的正常运行,内容如下:
### 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 |
确保脚本是可执行的:
# chmod +x /scripts/redis-check.sh
通过定时器 cron 来保证脚本的执行,每 3 分钟运行一次:
### nano /var/spool/cron/root | |
*/3 * * * * /bin/bash /script/redis-check.sh >> /var/log/redis-check.log |
OK,至此完工。
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-10/136402.htm
正文完
星哥玩云-微信公众号
