官网参考:
#环境搭建
#设置下载路径
cd /usr/local/src
#下载
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
#解压
tar xzf redis-3.2.0.tar.gz
#编译到指定目录
cd redis-3.2.0
cd src
make PREFIX=/usr/local/redis install
#启动Server
cd /usr/local/redis
bin/redis-server
#启动client
cd /usr/local/redis
bin/redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo"bar"
127.0.0.1:6379> quit
#环境变量配置参考:http://blog.csdn.net/langzi7758521/article/details/51446931
#开机启动:
#服务器配置文件
cp /usr/local/src/redis-3.2.0/redis.conf /usr/local/redis/bin
cd /usr/local/redis/bin
vi redis.conf
#修改ip
bind 192.168.186.130
#修改pidfile
pidfile /usr/local/redis/bin/redis_6379.pid
#存放数据和log
mkdir data
mkdir log
chmod 755 data
chmod 755 log
#启动配置文件配置
cp /usr/local/src/redis-3.2.0/utils/redis_init_script /etc/init.d/redis
chmod 755 /etc/init.d/redis
vi /etc/init.d/redis
#修改服务快捷启动命令配置
#参考如下:
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/usr/local/redis/bin/redis_${REDISPORT}.pid
CONF="/usr/local/redis/bin/${REDISPORT}.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
;;
status)
if [ -f $PIDFILE ]
then
echo "SUCCESS! Redis is Running(Port:${REDISPORT} PID:$(cat $PIDFILE))"
else
echo "ERROR! Redis is not Running"
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -h 192.168.199.132 -p $REDISPORT SHUTDOWN
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
${0} stop
${0} start
;;
*)
echo "Please use start or stop as first argument"
;;
esac
#配置文件中$EXEC $CONF $比原文件多&,意为在后台运行
#授权
chmod +x /etc/init.d/redis
#设置开机启动
chkconfig redis on
#配置完成,测试
service redis start