For those of you who didn’t know, Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis also supports datatypes such as Transitions, Publish and Subscribe. ‘Redis ’ is considered more powerful than ‘Memcache’ . It would be smart to bring ‘Redis’ into practice and put ‘Memcache’ down for a while.
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Redis on a CentOS 7 server.
Step 1. First, you need to enable EPEL repository on your system.
1 2 3 | ## 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 |
Step 2. Install Redis with Yum.
1 2 | yum-yupdate yuminstallredisphp-pecl-redis |
Enable Redis service to start on boot:
1 2 | systemctlstartredis-server.service systemctlenableredis-server.service |
Check if Redis is Running:
1 | systemctlis-activeredis-server.service |
Step 3. Install web interface for Redis.
phpRedisAdmin is a simple web interface to manage Redis databases:
1 2 3 | gitclonehttps://github.com/ErikDubbelboer/phpRedisAdmin.git cdphpRedisAdmin/includes cpconfig.sample.inc.phpconfig.inc.php |
Make sure the setting are correct:
1 | nanoconfig.inc.php |
Lets add the RedisAdmin configuration file to Apache:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ### nano /etc/httpd/conf.d/redisadmin.conf ### Now add the following ### # # Web Interface for RedisAdmin # <Directory"/downloads/phpRedisAdmin/"> OrderDeny,Allow Denyfromall Allowfrom127.0.0.1 Allowfrom<youripaddress> </Directory> Alias/redisAdmin/downloads/phpRedisAdmin Alias/redisadmin/downloads/phpRedisAdmin |
Create a Bash Script to make sure Redis is running:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ### nano /scripts/redis-check.sh #!/bin/bash PS=$(whichps) GREP=$(whichgrep) WHEN=$(date+"%Y-%m-%d-%H:%M:%S") if !$PSaux|$GREP"redis.conf"|$GREP-vgrep2>&1>/dev/null;then /etc/init.d/redisrestart echo'Restarted Redis @'$WHEN fi #Check Second instance if !$PSaux|$GREP"redis2.conf"|$GREP-vgrep2>&1>/dev/null;then /etc/init.d/redis2restart echo'Restarted Redis2 @'$WHEN fi |
Make the Script executable:
1 | chmod+x/scripts/redis-check.sh |
Add your script to your cron to run every 3 minutes or so:
1 2 | ### nano /var/spool/cron/root */3****/bin/bash/script/redis-check.sh>>/var/log/redis-check.log |
Congratulation’s! You have successfully installed Redis. Thanks for using this tutorial for installing Redis server on CentOS 7 system. For additional help or useful information, we recommend you to check the official Redis web site.