1、下載Redis3.2.5安裝包
cd /opt
wget http://download.redis.io/releases/redis-3.2.5.tar.gz
2、解壓、編譯、安裝redis-3.2.5

tar -zxvf redis-3.2.5.tar.gz -C /usr/src/ cd /usr/src/redis-3.2.5/ make && make install
3、創建redis相關目錄

mkdir -p /home/redis/bin mkdir -p /home/redis/log mkdir -p /home/redis/pid mkdir -p /home/redis/db
4、將可執行文件復制到自己的安裝目錄:/home/redis/
ln -s /usr/local/bin/redis-* /home/redis/bin/
5、復制配置文件到自己的安裝目錄:/home/redis/
cp redis.conf /home/redis/
6、進入自己的安裝目錄,編輯redis.conf配置文件

cd /home/redis/
vim /home/redis/redis.conf

根據實際需要修改配置文件,以下僅供參考 daemonize yes pidfile /home/redis/pid/redis.pid logfile /home/redis/log/redis.log dir /home/redis/db
7、創建redis服務腳本,並賦予權限
vim /etc/init.d/redis

#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. PATH=/home/redis/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/home/redis/bin/redis-server CLIEXEC=/home/redis/bin/redis-cli PIDFILE=/home/redis/pid/redis.pid CONF="/home/redis/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
8、添加redis服務開機啟動
chmod a+x /etc/init.d/redis
9、啟動redis服務

service redis start ps -ef | grep redis netstat -anptu | grep 6379
10、測試OK

redis-cli set key1 hello get key1 quit

(防火牆啟用6379端口:iptables -A INPUT -p tcp --dport 6379 -j ACCEPT)