wget http://download.redis.io/releases/redis-2.8.6.tar.gz
tar xzf redis-2.8.6.tar.gz
cd redis-2.8.6
make
有是make会报错
gcc类的错误 则需安装 gcc
如:
yum install -y gcc g++ gcc-c++ make
此类错误
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory zmalloc.h:55:2: error: #error "Newer version of jemalloc required" make[1]: *** [adlist.o] Error 1 make[1]: Leaving directory `/data0/src/redis-2.6.2/src' make: *** [all] Error 2
解决办法是:
make MALLOC=libc
zmalloc.o: In function `zmalloc_used_memory':
/usr/local/src/redis-2.8.3/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld 返回 1
make[1]: *** [redis-server] 错误 1
make[1]: Leaving directory `/usr/local/src/redis-2.8.3/src'
make: *** [all] 错误 2
make后面加一个参数
make CFLAGS="-march=i686"
2、编译完成后,在./Src目录下,有三个可执行文件redis-server、redis-benchmark、redis-cli和./redis.conf然后拷贝到一个目录下。
mkdir /usr/redis
cp redis-server /usr/redis
cp redis-benchmark /usr/redis
cp redis-cli /usr/redis
cp redis.conf /usr/redis
cd /usr/redis
3、启动Redis服务。
redis-server redis.conf
4、然后用客户端测试一下是否启动成功。
redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
---------------------------------------------------------------------------------------------------------
然后自己动手制作一个redis启动脚本方便管理
1、vim /etc/rc.d/init.d/redisd
#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
PROGDIR=/usr/redis #安装路径
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/usr/redis.conf
PIDFILE=/var/run/redis.pid
DESC="redis daemon"
SCRIPTNAME=/etc/rc.d/init.d/redisd
start()
{
if test -x $DAEMON
then
echo -e "Starting $DESC: $PROGNAME"
if $DAEMON $CONFIG
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "Couldn't find Redis Server ($DAEMON)"
fi
}
stop()
{
if test -e $PIDFILE
then
echo -e "Stopping $DESC: $PROGNAME"
if kill `cat $PIDFILE`
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "No Redis Server ($DAEMON) running"
fi
}
restart()
{
echo -e "Restarting $DESC: $PROGNAME"
stop
start
}
list()
{
ps aux | grep $PROGNAME
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
list)
list
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
exit 1
;;
esac
exit 0
2、增加服务并开机启动
cp ./redisd /etc/rc.d/init.d/redisd
chmod +x /etc/rc.d/init.d/redisd
chkconfig --add redisd
chkconfig --level 345 redisd on
chkconfig --list redisd
执行该脚本后,就可以开始start|stop|restart|list你的服务了。
提示:
默认的redis.conf文件参数是前台启动的,修改daemonize no为daemonize yes则为后台启动。
补充:这是最开始安装所使用的方法,后来发现有人用的方法更好更简单,另起一篇转载 点击打开链接