当前位置: 移动技术网 > IT编程>数据库>Redis > 在CentOS 7环境下安装Redis数据库详解

在CentOS 7环境下安装Redis数据库详解

2017年12月08日  | 移动技术网IT编程  | 我要评论

正如我们所知的那样,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://blog.csdn.net/chszs/article/details/51925378

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网